Advertisement
Guest User

Untitled

a guest
Jan 18th, 2014
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 KB | None | 0 0
  1.         static void Main(string[] args)
  2.         {
  3.             IntPtr loop = uv.uv_default_loop();
  4.  
  5.             IntPtr address = alloc(4);
  6.  
  7.             uv.uv_ip4_addr("0.0.0.0", 5000, address);
  8.  
  9.             IntPtr server = alloc(uv.uv_handle_size(uv.handle_type.UV_TCP));
  10.  
  11.             uv.uv_tcp_init(loop, server);
  12.  
  13.             uv.uv_tcp_bind(server, address);
  14.  
  15.             var r = uv.uv_listen(server, 128, (val, status) =>
  16.             {
  17.                 Console.WriteLine("got connection");
  18.  
  19.                 var client = alloc(uv.uv_handle_size(uv.handle_type.UV_TCP));
  20.  
  21.                 uv.uv_tcp_init(loop, client);
  22.  
  23.                 uv.uv_accept(server, client);
  24.  
  25.                 uv.uv_read_start(client, (handle, suggested_size, buf) =>
  26.                 {
  27.                     Console.WriteLine("alloc_callback");
  28.                    
  29.                     Console.WriteLine("handle: {0}", handle);
  30.  
  31.                     Console.WriteLine("suggested_size: {0}", suggested_size);
  32.  
  33.                     var _buf   = (uv.uv_buf_t)Marshal.PtrToStructure(buf, typeof(uv.uv_buf_t));
  34.  
  35.                     _buf.@base = alloc(suggested_size);
  36.  
  37.                     _buf.len   = suggested_size;
  38.  
  39.                 }, (stream, nread, buf) =>
  40.                 {
  41.                     Console.WriteLine("read_callback");
  42.                    
  43.                     Console.WriteLine("stream: {0}", stream);
  44.  
  45.                     Console.WriteLine("nread: {0}", nread);
  46.  
  47.                     var _buf = (uv.uv_buf_t)Marshal.PtrToStructure(buf, typeof(uv.uv_buf_t));
  48.  
  49.                     Console.WriteLine("buf: {0}", _buf.len);                    
  50.                 });
  51.  
  52.                 //uv.uv_close(client, (handle) =>
  53.                 //{
  54.                 //    Console.WriteLine(handle);
  55.                 //});
  56.             });
  57.            
  58.             uv.uv_run(loop, uv.uv_run_mode.UV_RUN_DEFAULT);
  59.  
  60.             Console.ReadLine();
  61.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement