示例#1
0
        public TcpHandle(EventLoop loop) : base()
        {
            _handle    = Libuv.Allocate(uv_handle_type.UV_TCP);
            _eventLoop = loop;

            Libuv.uv_tcp_init(loop.Loop, _handle);

            GCHandle gcHandle = GCHandle.Alloc(this, GCHandleType.Normal);

            ((uv_handle_t *)_handle)->data = GCHandle.ToIntPtr(gcHandle);
        }
示例#2
0
        public void Bind(IPEndPoint ip)
        {
            sockaddr addr = new sockaddr();

            Libuv.GetSocketAddress(ip, out addr);

            int r = Libuv.uv_tcp_init(_eventLoop.Loop, _handle);

            if (r != 0)
            {
                Console.WriteLine($"uv_tcp_init error:{r}");
            }

            r = Libuv.uv_tcp_bind(_handle, ref addr, 0);
            if (r != 0)
            {
                Console.WriteLine($"uv_tcp_bind error:{r}");
            }



            //Libuv.uv_run(_loop, Libuv.uv_run_mode.UV_RUN_DEFAULT);
        }