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 }
protected override void OnNewConnectionAccepted(UvTcp socket) { var targetPipe = this.GetNextWorkerPipe(); targetPipe.WriteHandle(socket, this.WriteHandleCallback, socket); }
public static extern int uv_tcp_getpeername(UvTcp handle, out SockAddr name, ref int namelen);
public static extern int uv_tcp_connect(UvTcpConnectRequest req, UvTcp handle, ref SockAddr addr, UvConnectCallback cb);
public static extern int uv_tcp_nodelay(UvTcp handle, int enable);
public static extern int uv_tcp_open(UvTcp handle, IntPtr hSocket);
public static extern int uv_tcp_bind(UvTcp handle, ref SockAddr addr, int flags);
public static extern int uv_tcp_init(UvLoop loop, UvTcp handle);