public static AcceptSocket Bind(IPEndPoint ipEndPoint, ChannelWriter <ConnectionContext> acceptQueue, MemoryPool <byte> memoryPool, IoUringOptions options, TransportThreadScheduler scheduler) { var domain = ipEndPoint.AddressFamily == AddressFamily.InterNetwork ? AF_INET : AF_INET6; LinuxSocket s = new LinuxSocket(domain, SOCK_STREAM, IPPROTO_TCP, blocking: false); s.SetOption(SOL_SOCKET, SO_REUSEADDR, 1); s.SetOption(SOL_SOCKET, SO_REUSEPORT, 1); s.Bind(ipEndPoint); s.Listen(options.ListenBacklog); return(new AcceptSocket(s, s.GetLocalAddress(), acceptQueue, memoryPool, options, scheduler)); }
public static OutboundConnection Create(EndPoint endpoint, TaskCompletionSource <ConnectionContext> connectCompletion, MemoryPool <byte> memoryPool, IoUringOptions options, TransportThreadScheduler scheduler) { LinuxSocket s = default; switch (endpoint) { case IPEndPoint _: var domain = endpoint.AddressFamily == AddressFamily.InterNetwork ? AF_INET : AF_INET6; s = new LinuxSocket(domain, SOCK_STREAM, IPPROTO_TCP, blocking: false); if (options.TcpNoDelay) { s.SetOption(SOL_TCP, TCP_NODELAY, 1); } break; case UnixDomainSocketEndPoint _: s = new LinuxSocket(AF_UNIX, SOCK_STREAM, 0, blocking: false); break; case FileHandleEndPoint fileHandleEndPoint: s = (int)fileHandleEndPoint.FileHandle; break; default: ThrowHelper.ThrowNewNotSupportedException_EndPointNotSupported(); break; } return(new OutboundConnection(s, endpoint, memoryPool, options, scheduler, connectCompletion)); }