Ejemplo n.º 1
0
        public override async ValueTask <ConnectionContext?> AcceptAsync(CancellationToken cancellationToken = default)
        {
            try
            {
                var stream = await _connection.AcceptStreamAsync(cancellationToken);

                var context = new QuicStreamContext(stream, this, _context);
                context.Start();

                _log.AcceptedStream(context);

                return(context);
            }
            catch (QuicConnectionAbortedException ex)
            {
                // Shutdown initiated by peer, abortive.
                _log.ConnectionAborted(this, ex);

                ThreadPool.UnsafeQueueUserWorkItem(state =>
                {
                    state.CancelConnectionClosedToken();
                },
                                                   this,
                                                   preferLocal: false);
            }
            catch (QuicOperationAbortedException)
            {
                // Shutdown initiated by us

                // Allow for graceful closure.
            }

            return(null);
        }
Ejemplo n.º 2
0
        public override ValueTask <ConnectionContext> ConnectAsync(IFeatureCollection?features = null, CancellationToken cancellationToken = default)
        {
            QuicStream quicStream;

            var streamDirectionFeature = features?.Get <IStreamDirectionFeature>();

            if (streamDirectionFeature != null)
            {
                if (streamDirectionFeature.CanRead)
                {
                    quicStream = _connection.OpenBidirectionalStream();
                }
                else
                {
                    quicStream = _connection.OpenUnidirectionalStream();
                }
            }
            else
            {
                quicStream = _connection.OpenBidirectionalStream();
            }

            var context = new QuicStreamContext(quicStream, this, _context);

            context.Start();

            _log.ConnectedStream(context);

            return(new ValueTask <ConnectionContext>(context));
        }
Ejemplo n.º 3
0
        public override async ValueTask <ConnectionContext?> AcceptAsync(CancellationToken cancellationToken = default)
        {
            try
            {
                var stream = await _connection.AcceptStreamAsync(cancellationToken);

                var context = new QuicStreamContext(stream, this, _context);
                context.Start();
                return(context);
            }
            catch (QuicConnectionAbortedException ex)
            {
                // Shutdown initiated by peer, abortive.
                // TODO cancel CTS here?
                _log.LogDebug($"Accept loop ended with exception: {ex.Message}");
            }
            catch (QuicOperationAbortedException)
            {
                // Shutdown initiated by us

                // Allow for graceful closure.
            }

            return(null);
        }
Ejemplo n.º 4
0
        public override ValueTask <ConnectionContext> ConnectAsync(IFeatureCollection?features = null, CancellationToken cancellationToken = default)
        {
            QuicStream quicStream;

            var streamDirectionFeature = features?.Get <IStreamDirectionFeature>();

            if (streamDirectionFeature != null)
            {
                if (streamDirectionFeature.CanRead)
                {
                    quicStream = _connection.OpenBidirectionalStream();
                }
                else
                {
                    quicStream = _connection.OpenUnidirectionalStream();
                }
            }
            else
            {
                quicStream = _connection.OpenBidirectionalStream();
            }

            // Only a handful of control streams are created by the server and they last for the
            // lifetime of the connection. No value in pooling them.
            QuicStreamContext?context = new QuicStreamContext(this, _context);

            context.Initialize(quicStream);
            context.Start();

            QuicLog.ConnectedStream(_log, context);

            return(new ValueTask <ConnectionContext>(context));
        }
Ejemplo n.º 5
0
        public ValueTask <ConnectionContext> StartBidirectionalStreamAsync()
        {
            var stream  = _connection.OpenBidirectionalStream();
            var context = new QuicStreamContext(stream, this, _context);

            context.Start();
            return(new ValueTask <ConnectionContext>(context));
        }