Exemplo n.º 1
0
 public SocketReceiver(LinuxSocket recipient, ChannelWriter<ConnectionContext> acceptQueue, EndPoint endPoint, MemoryPool<byte> memoryPool, IoUringOptions options, TransportThreadScheduler scheduler)
 {
     _recipient = recipient;
     AcceptQueue = acceptQueue;
     _endPoint = endPoint;
     _memoryPool = memoryPool;
     _options = options;
     _scheduler = scheduler;
 }
Exemplo n.º 2
0
        private AcceptSocket(LinuxSocket socket, EndPoint endPoint, ChannelWriter <ConnectionContext> acceptQueue, MemoryPool <byte> memoryPool, IoUringOptions options, TransportThreadScheduler scheduler)
        {
            Socket      = socket;
            EndPoint    = endPoint;
            AcceptQueue = acceptQueue;
            _memoryPool = memoryPool;
            _options    = options;
            _scheduler  = scheduler;

            _unbindCompletion = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
            if (endPoint is IPEndPoint) // _addr is null by intention for the remaining EndPoint types
            {
                _addr    = GC.AllocateUninitializedArray <byte>(SizeOf.sockaddr_storage, pinned: true);
                _addrLen = GC.AllocateUninitializedArray <byte>(SizeOf.socklen_t, pinned: true);
            }
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
 public InboundConnection(LinuxSocket socket, EndPoint local, EndPoint remote, MemoryPool <byte> memoryPool, IoUringOptions options, TransportThreadScheduler scheduler)
     : base(socket, local, remote, memoryPool, options, scheduler)
 {
 }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
        private OutboundConnection(LinuxSocket socket, EndPoint remote, MemoryPool <byte> memoryPool, IoUringOptions options, TransportThreadScheduler scheduler, TaskCompletionSource <ConnectionContext> connectCompletion)
            : base(socket, null, remote, memoryPool, options, scheduler)
        {
            unsafe
            {
                switch (remote)
                {
                case IPEndPoint ipEndPoint:
                {
                    ipEndPoint.ToSockAddr((sockaddr_storage *)Addr, out var addrLength);
                    AddrLen = addrLength;
                    break;
                }

                case UnixDomainSocketEndPoint unixDomainSocketEndPoint:
                {
                    unixDomainSocketEndPoint.ToSockAddr((sockaddr_un *)Addr);
                    AddrLen = SizeOf.sockaddr_un;
                    break;
                }
                }
            }

            _connectCompletion = connectCompletion;

            // Add IConnectionInherentKeepAliveFeature to the tcp connection impl since Kestrel doesn't implement
            // the IConnectionHeartbeatFeature
            Features.Set <IConnectionInherentKeepAliveFeature>(this);
        }