private MsQuicStream StreamOpen(
            QUIC_STREAM_OPEN_FLAG flags)
        {
            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Enter(this);
            }

            IntPtr streamPtr = IntPtr.Zero;

            QuicExceptionHelpers.ThrowIfFailed(
                MsQuicApi.Api.StreamOpenDelegate(
                    _ptr,
                    (uint)flags,
                    MsQuicStream.NativeCallbackHandler,
                    IntPtr.Zero,
                    out streamPtr),
                "Failed to open stream to peer.");

            MsQuicStream stream = new MsQuicStream(this, flags, streamPtr, inbound: false);

            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Exit(this);
            }
            return(stream);
        }
示例#2
0
        private uint HandleEventNewStream(ref ConnectionEvent connectionEvent)
        {
            MsQuicStream msQuicStream = new MsQuicStream(this, connectionEvent.StreamFlags, connectionEvent.Data.StreamStarted.Stream, inbound: true);

            _acceptQueue.Writer.TryWrite(msQuicStream);
            return(MsQuicStatusCodes.Success);
        }
        private static uint HandleEventNewStream(State state, ref ConnectionEvent connectionEvent)
        {
            var streamHandle = new SafeMsQuicStreamHandle(connectionEvent.Data.PeerStreamStarted.Stream);
            var stream       = new MsQuicStream(streamHandle, connectionEvent.Data.PeerStreamStarted.Flags);

            state.AcceptQueue.Writer.TryWrite(stream);
            return(MsQuicStatusCodes.Success);
        }
示例#4
0
            public bool TryAddStream(MsQuicStream stream)
            {
                lock (this)
                {
                    if (_closing)
                    {
                        return(false);
                    }

                    StreamCount++;
                    return(true);
                }
            }
示例#5
0
            public bool TryQueueNewStream(SafeMsQuicStreamHandle streamHandle, QUIC_STREAM_OPEN_FLAGS flags)
            {
                var stream = new MsQuicStream(this, streamHandle, flags);

                if (AcceptQueue.Writer.TryWrite(stream))
                {
                    return(true);
                }
                else
                {
                    stream.Dispose();
                    return(false);
                }
            }
        private uint HandleEventNewStream(ConnectionEvent connectionEvent)
        {
            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Enter(this);
            }

            MsQuicStream msQuicStream = new MsQuicStream(this, connectionEvent.StreamFlags, connectionEvent.Data.NewStream.Stream, inbound: true);

            _acceptQueue.Writer.TryWrite(msQuicStream);
            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Exit(this);
            }

            return(MsQuicStatusCodes.Success);
        }
示例#7
0
            public void RemoveStream(MsQuicStream stream)
            {
                bool releaseHandles;

                lock (this)
                {
                    StreamCount--;
                    Debug.Assert(StreamCount >= 0);
                    releaseHandles = _closing && StreamCount == 0;
                }

                if (releaseHandles)
                {
                    Handle?.Dispose();
                    StateGCHandle.Free();
                }
            }
示例#8
0
        private async ValueTask <MsQuicStream> OpenStreamAsync(QUIC_STREAM_OPEN_FLAGS flags, CancellationToken cancellationToken)
        {
            ThrowIfDisposed();
            if (!Connected)
            {
                throw new InvalidOperationException(SR.net_quic_not_connected);
            }

            var stream = new MsQuicStream(_state, flags);

            try
            {
                await stream.StartAsync(cancellationToken).ConfigureAwait(false);
            }
            catch
            {
                stream.Dispose();
                throw;
            }

            return(stream);
        }