private async Task AcceptAsync(ITransmissionConnection c) { try { await _buffer.WriteAsync(_connectionFactory.Create(c), CancellationToken).ConfigureAwait(false); Log.Debug("New connection accepted"); } catch { await c.DisconnectAsync().IgnoreExceptions().ConfigureAwait(false); throw; } }
public async ValueTask <ITransportConnection> ConnectAsync(CancellationToken cancellationToken) { var transmissionConnection = await _transmissionClient.ConnectAsync(cancellationToken).ConfigureAwait(false); try { return(_connectionFactory.Create(transmissionConnection)); } catch (OperationCanceledException) when(cancellationToken.IsCancellationRequested) { Log.Trace("Connection canceled"); transmissionConnection.Dispose(); throw; } catch (Exception ex) { Log.Trace("Connection failed: {0}", ex.FormatTypeAndMessage()); transmissionConnection.Dispose(); throw; } }