public IoUringConnectionContext(LinuxSocket socket, EndPoint server, EndPoint client, MemoryPool <byte> pool,
                                        TransportThreadContext threadContext)
        {
            Socket = socket;

            LocalEndPoint  = server;
            RemoteEndPoint = client;

            MemoryPool     = pool;
            _threadContext = threadContext;

            var appScheduler  = PipeScheduler.ThreadPool; // TODO: configure
            var inputOptions  = new PipeOptions(MemoryPool, appScheduler, PipeScheduler.Inline, PauseInputWriterThreshold, PauseInputWriterThreshold / 2, useSynchronizationContext: false);
            var outputOptions = new PipeOptions(MemoryPool, PipeScheduler.Inline, appScheduler, PauseOutputWriterThreshold, PauseOutputWriterThreshold / 2, useSynchronizationContext: false);

            var pair = DuplexPipe.CreateConnectionPair(inputOptions, outputOptions);

            Transport   = pair.Transport;
            Application = pair.Application;

            _onOnFlushedToApp = FlushedToAppAsynchronously;
            _onReadFromApp    = ReadFromAppAsynchronously;

            iovec[] vecs   = new iovec[ReadIOVecCount + WriteIOVecCount];
            var     handle = GCHandle.Alloc(vecs, GCHandleType.Pinned);

            _iovec       = (iovec *)handle.AddrOfPinnedObject();
            _iovecHandle = handle;
        }
Ejemplo n.º 2
0
        public void Bind()
        {
            var         domain = _endPoint.AddressFamily == AddressFamily.InterNetwork ? AF_INET : AF_INET6;
            LinuxSocket s      = socket(domain, SOCK_STREAM | SOCK_NONBLOCK, IPPROTO_TCP);

            s.SetOption(SOL_SOCKET, SO_REUSEADDR, 1);
            s.SetOption(SOL_SOCKET, SO_REUSEPORT, 1);
            s.Bind(_endPoint);
            s.Listen(ListenBacklog);
            _acceptSocket = s;
        }