Exemple #1
0
        public async ValueTask DisposeAsync()
        {
            _heartbeat?.Dispose();
            await Writer.DisposeAsync().ConfigureAwait(false);

            await Reader.DisposeAsync().ConfigureAwait(false);

            //_ctx.Abort();
            _cts.Cancel();
            await _ctx.DisposeAsync().ConfigureAwait(false);

            _listener.Stop();
            CancelTcs();
            if (!_connectionCloseOkSrc.Task.IsCompleted && !_connectionCloseOkSrc.Task.IsCanceled)
            {
                _connectionCloseOkSrc.SetCanceled();
            }
            if (!_connectionOpenOk.Task.IsCompleted && !_connectionOpenOk.Task.IsCanceled)
            {
                _connectionOpenOk.SetCanceled();
            }
            if (!ConnectionClosedSrc.Task.IsCompleted && !ConnectionClosedSrc.Task.IsCanceled)
            {
                ConnectionClosedSrc.SetCanceled();
            }
        }
Exemple #2
0
        public async ValueTask DisposeAsync()
        {
            if (_connection == null)
            {
                return;
            }

            await _writer.DisposeAsync().ConfigureAwait(false);

            _reader.Connection.Transport.Input.CancelPendingRead();

            await _readingTask.ConfigureAwait(false);

            await _reader.DisposeAsync().ConfigureAwait(false);

            foreach (var operation in _operations)
            {
                _operations.TryRemove(operation.Key, out _);

                // Cancel all pending operations
                operation.Value.TrySetCanceled();
            }

            await _connection.DisposeAsync().ConfigureAwait(false);
        }
Exemple #3
0
        public override async Task OnConnectedAsync(ConnectionContext connection)
        {
            var tcpClient = new TcpClientAdapter(connection);

            if (!_portEndPoints.TryGetValue(((IPEndPoint)connection.LocalEndPoint).Port, out var transportEndPoint))
            {
                // This should never occur, but handling anyway.
                await connection.DisposeAsync();

                return;
            }

            using var transport = new TcpTransport(tcpClient, _envelopeSerializer, transportEndPoint.ServerCertificate);
            await transport.OpenAsync(null, default);

            try
            {
                await _listener.ListenAsync(transport, connection.ConnectionClosed);
            }
            finally
            {
                if (transport.IsConnected)
                {
                    using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
                    await transport.CloseAsync(cts.Token);
                }
            }
        }
Exemple #4
0
    public ValueTask DisposeAsync()
    {
        _muxer?.Dispose();
        _stream?.Dispose();
        _socket?.Dispose();

        return(_connection == null ? default : _connection.DisposeAsync());
    }
        private async Task OnConnection(ConnectionContext connection)
        {
            // Handle the connection
            await _connectionDispatcher(connection.Transport.Input, connection.Transport.Output, connection);

            // Wait for the transport to close
            await CancellationTokenAsTask(connection.ConnectionClosed);

            await connection.DisposeAsync();
        }
Exemple #6
0
 public async ValueTask DisposeAsync()
 {
     _muxer?.Dispose();
     if (_stream != null)
     {
         await _stream.DisposeAsync().ConfigureAwait(false);
     }
     if (_socket != null)
     {
         await _socket.DisposeAsync().ConfigureAwait(false);
     }
     if (_connection != null)
     {
         await _connection.DisposeAsync().ConfigureAwait(false);
     }
 }
Exemple #7
0
        private static void Release(ConnectionContext connection)
        {
            try
            {
                connection.Abort(new ConnectionAbortedException("Failed socket verification."));
            }
            catch (Exception ex)
            {
                NetState.TraceException(ex);
            }

            try
            {
                // TODO: Is this needed?
                connection.DisposeAsync();
            }
            catch (Exception ex)
            {
                NetState.TraceException(ex);
            }
        }
Exemple #8
0
        private async Task Accept(ConnectionContext connection)
        {
            try
            {
                IRSocketTransport rsocketTransport = new ConnectionListenerTransport(connection);

                RSocketServer rsocketServer = new EchoServer(rsocketTransport);
                await rsocketServer.ConnectAsync();

                _logger.LogInformation("Connection {ConnectionId} connected", connection.ConnectionId);

                await connection.ConnectionClosed.WaitAsync();
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Connection {ConnectionId} threw an exception", connection.ConnectionId);
            }
            finally
            {
                await connection.DisposeAsync();

                _logger.LogInformation("Connection {ConnectionId} disconnected", connection.ConnectionId);
            }
        }
 public Task DisposeAsync(ConnectionContext connection)
 {
     return(connection.DisposeAsync().AsTask());
 }