public override async ValueTask <Connection?> AcceptConnectionAsync(IConnectionProperties?options = null, CancellationToken cancellationToken = default)
            {
                Connection?baseConnection = await BaseListener.AcceptConnectionAsync(options, cancellationToken).ConfigureAwait(false);

                if (baseConnection == null)
                {
                    return(null);
                }

                SslStream?stream = null;

                try
                {
                    stream = new SslStream(baseConnection.Stream, leaveInnerStreamOpen: false);
                    await stream.AuthenticateAsServerAsync(_sslOptions, cancellationToken).ConfigureAwait(false);

                    return(new SslConnection(baseConnection, stream));
                }
                catch
                {
                    if (stream != null)
                    {
                        await stream.DisposeAsync().ConfigureAwait(false);
                    }
                    await baseConnection.DisposeAsync(cancellationToken).ConfigureAwait(false);

                    throw;
                }
            }
Пример #2
0
            public override async ValueTask <Connection?> AcceptConnectionAsync(IConnectionProperties?options = null, CancellationToken cancellationToken = default)
            {
                Connection?con = await BaseListener.AcceptConnectionAsync(options, cancellationToken).ConfigureAwait(false);

                if (con == null)
                {
                    return(con);
                }

                return(new FilteringConnection(con, new WriteBufferingStream(con.Stream)));
            }