Example #1
0
        public LibuvConnection(UvTcp socket, IProtocol protocol, IPacketRouter router, IBufferPool bufferPool)
            : base(router, protocol)
        {
            this.BaseSocket     = socket ?? throw new ArgumentNullException(nameof(socket));
            this.RemoteEndPoint = socket.GetPeerEndPoint();

            this.BufferPool = bufferPool;

            this.SilentSend = true;
        }
        private void ReadCallback(UvStream stream, int nread, Exception error, object stateObject)
        {
            UvTcp client = null;

            try
            {
                if (error != null)
                {
                    throw error;
                }

                // When receiving a TCP handle over an IPC pipe the accept logic is slightly different:
                // First we receive some data over the pipe (usually some dummy message)
                // and then we check if we got some handle as well by ckecking the UvPipe.PendingCount.
                // If we do, we can simply accept the pending handle as usual.
                var pipe = (UvPipe)stream;
                if (pipe.PendingCount() > 0)
                {
                    client = new UvTcp(this.Worker.Loop);
                    pipe.Accept(client);

                    this.OnNewConnectionAccepted(client);
                }
            }
            catch (Exception exception)
            {
                lock (this.SyncRoot)
                {
                    this.CloseBaseSocket();
                }

                client?.Close();

                if (exception is UvErrorException errorException && errorException.ErrorCode == UvErrorCode.EOF)
                {
                    // Ignore EOF errors
                }
Example #3
0
        protected override void OnNewConnectionAccepted(UvTcp socket)
        {
            var targetPipe = this.GetNextWorkerPipe();

            targetPipe.WriteHandle(socket, this.WriteHandleCallback, socket);
        }
Example #4
0
 public static extern int uv_tcp_getpeername(UvTcp handle, out SockAddr name, ref int namelen);
Example #5
0
 public static extern int uv_tcp_connect(UvTcpConnectRequest req, UvTcp handle, ref SockAddr addr, UvConnectCallback cb);
Example #6
0
 public static extern int uv_tcp_nodelay(UvTcp handle, int enable);
Example #7
0
 public static extern int uv_tcp_open(UvTcp handle, IntPtr hSocket);
Example #8
0
 public static extern int uv_tcp_bind(UvTcp handle, ref SockAddr addr, int flags);
Example #9
0
 public static extern int uv_tcp_init(UvLoop loop, UvTcp handle);