private void CompleteAccept(AcceptSocketContext acceptContext, int result) { if (result < 0) { var err = -result; if (err == EAGAIN || err == EINTR || err == EMFILE) { Debug.WriteLine($"accept completed with EAGAIN on {(int)acceptContext.Socket}"); Accept(acceptContext); return; } throw new ErrnoException(err); } LinuxSocket socket = result; Debug.WriteLine($"Accepted {(int)socket} from {(int)acceptContext.Socket}"); if (_threadContext.Options.TcpNoDelay) { socket.SetOption(SOL_TCP, TCP_NODELAY, 1); } var remoteEndpoint = IPEndPointFormatter.AddrToIpEndPoint(acceptContext.Addr); var context = new InboundConnectionContext(socket, acceptContext.EndPoint, remoteEndpoint, _threadContext); _connections[socket] = context; acceptContext.AcceptQueue.TryWrite(context); Accept(acceptContext); Read(context); ReadFromApp(context); }
private void CompleteAcceptPoll(AcceptSocketContext context) { LinuxSocket socket; while ((socket = context.Socket.Accept(out var clientEndpoint)) != -1) { if (_threadContext.Options.TcpNoDelay) { socket.SetOption(SOL_TCP, TCP_NODELAY, 1); } Debug.WriteLine($"Accepted {(int)socket}"); var connectionContext = new InboundConnectionContext(socket, context.EndPoint, clientEndpoint, _threadContext); _connections[socket] = connectionContext; context.AcceptQueue.TryWrite(connectionContext); PollRead(connectionContext); ReadFromApp(connectionContext); } PollAccept(context); }