// Creates a new MsQuicStream internal MsQuicStream(MsQuicConnection connection, QUIC_STREAM_OPEN_FLAG flags, IntPtr nativeObjPtr, bool inbound) { Debug.Assert(connection != null); _ptr = nativeObjPtr; if (inbound) { _started = StartState.Finished; _canWrite = !flags.HasFlag(QUIC_STREAM_OPEN_FLAG.UNIDIRECTIONAL); _canRead = true; } else { _started = StartState.None; _canWrite = true; _canRead = !flags.HasFlag(QUIC_STREAM_OPEN_FLAG.UNIDIRECTIONAL); } _sendResettableCompletionSource = new ResettableCompletionSource <uint>(); _receiveResettableCompletionSource = new ResettableCompletionSource <uint>(); _shutdownWriteResettableCompletionSource = new ResettableCompletionSource <uint>(); SetCallbackHandler(); }
internal MsQuicStream(MsQuicConnection connection, QUIC_STREAM_OPEN_FLAG flags, IntPtr nativeObjPtr, bool inbound) { Debug.Assert(connection != null, "Connection null"); _ptr = nativeObjPtr; _sendResettableCompletionSource = new ResettableCompletionSource <uint>(); _receiveResettableCompletionSource = new ResettableCompletionSource <uint>(); SetCallbackHandler(); bool isBidirectional = !flags.HasFlag(QUIC_STREAM_OPEN_FLAG.UNIDIRECTIONAL); if (inbound) { _canRead = true; _canWrite = isBidirectional; _started = true; } else { _canRead = isBidirectional; _canWrite = true; StartLocalStream(); } }
public MsQuicStream(MsQuicApi api, MsQuicConnection connection, MsQuicTransportContext context, QUIC_STREAM_OPEN_FLAG flags, IntPtr nativeObjPtr) { Debug.Assert(connection != null); Api = api; _nativeObjPtr = nativeObjPtr; _connection = connection; MemoryPool = context.Options.MemoryPoolFactory(); _log = context.Log; ConnectionClosed = _streamClosedTokenSource.Token; var maxReadBufferSize = context.Options.MaxReadBufferSize.Value; var maxWriteBufferSize = context.Options.MaxWriteBufferSize.Value; _resettableCompletion = new ResettableCompletionSource(this); // TODO should we allow these PipeScheduler to be configurable here? var inputOptions = new PipeOptions(MemoryPool, PipeScheduler.ThreadPool, PipeScheduler.Inline, maxReadBufferSize, maxReadBufferSize / 2, useSynchronizationContext: false); var outputOptions = new PipeOptions(MemoryPool, PipeScheduler.Inline, PipeScheduler.ThreadPool, maxWriteBufferSize, maxWriteBufferSize / 2, useSynchronizationContext: false); var pair = DuplexPipe.CreateConnectionPair(inputOptions, outputOptions); // TODO when stream is unidirectional, don't create an output pipe. if (flags.HasFlag(QUIC_STREAM_OPEN_FLAG.UNIDIRECTIONAL)) { Features.Set <IUnidirectionalStreamFeature>(this); } // TODO populate the ITlsConnectionFeature (requires client certs). var feature = new FakeTlsConnectionFeature(); Features.Set <ITlsConnectionFeature>(feature); Transport = pair.Transport; Application = pair.Application; SetCallbackHandler(); _processingTask = ProcessSends(); // Concatenate stream id with ConnectionId. _log.NewStream(ConnectionId); }