コード例 #1
0
        protected IoUringConnection(LinuxSocket socket, EndPoint local, EndPoint remote, MemoryPool <byte> memoryPool, IoUringOptions options, TransportThreadScheduler scheduler)
        {
            Socket = socket;

            LocalEndPoint  = local;
            RemoteEndPoint = remote;

            MemoryPool = memoryPool;
            Debug.Assert(MaxBufferSize == MemoryPool.MaxBufferSize);

            _scheduler = scheduler;

            _connectionClosedTokenSource = new CancellationTokenSource();
            ConnectionClosed             = _connectionClosedTokenSource.Token;
            _waitForConnectionClosedTcs  = new TaskCompletionSource <object>(TaskCreationOptions.RunContinuationsAsynchronously);

            var appScheduler  = options.ApplicationSchedulingMode;
            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 = () => HandleFlushedToApp();
            _onReadFromApp    = () => HandleReadFromApp();

            _ioVecBytes = GC.AllocateUninitializedArray <byte>(SizeOf.iovec * (ReadIOVecCount + WriteIOVecCount), pinned: true);
            unsafe
            {
                _iovec = (iovec *)MemoryHelper.UnsafeGetAddressOfPinnedArrayData(_ioVecBytes);
            }
        }
コード例 #2
0
 public TransportThread(IoUringOptions options, int cpuId)
     : base("IoUring Transport Thread", options, cpuId)
 {
     _memoryPool = new SlabMemoryPool();
     _scheduler  = new TransportThreadScheduler(_unblockHandle, _asyncOperationQueue, _asyncOperationStates);
 }