public TransportThread(IoUringOptions options) { int res = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); if (res == -1) { throw new ErrnoException(errno); } _eventfd = res; // Pin buffer for eventfd reads via io_uring byte[] bytes = new byte[8]; _eventfdBytes = GCHandle.Alloc(bytes, GCHandleType.Pinned); // Pin iovec used for eventfd reads via io_uring var eventfdIoVec = new iovec { iov_base = (void *)_eventfdBytes.AddrOfPinnedObject(), iov_len = bytes.Length }; _eventfdIoVecHandle = GCHandle.Alloc(eventfdIoVec, GCHandleType.Pinned); _eventfdIoVec = (iovec *)_eventfdIoVecHandle.AddrOfPinnedObject(); var memoryPool = new SlabMemoryPool(); _threadContext = new TransportThreadContext(options, memoryPool, _eventfd, s => Read(s), s => Write(s)); _maxBufferSize = memoryPool.MaxBufferSize; }
protected IoUringConnectionContext(LinuxSocket socket, EndPoint local, EndPoint remote, TransportThreadContext threadContext) { Socket = socket; LocalEndPoint = local; RemoteEndPoint = remote; MemoryPool = threadContext.MemoryPool; _threadContext = threadContext; var appScheduler = threadContext.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 = FlushedToAppAsynchronously; _onReadFromApp = ReadFromAppAsynchronously; iovec[] vecs = new iovec[ReadIOVecCount + WriteIOVecCount]; var handle = GCHandle.Alloc(vecs, GCHandleType.Pinned); _iovec = (iovec *)handle.AddrOfPinnedObject(); _iovecHandle = handle; }
public TransportThread(IoUringOptions options) { _ring = new Ring(RingSize); SetupEventFd(); _threadContext = new TransportThreadContext(options, _readPollQueue, _writePollQueue, _memoryPool, _eventfd); }