/// <inheritdoc /> public async Task StartAsync(CancellationToken cancellationToken) { var rawStream = new SimplePipeStream( _socketPipe.Input, _socketPipe.Output); var sslStream = await _sslStreamWrapperFactory.WrapStreamAsync(rawStream, false, _certificate, cancellationToken) .ConfigureAwait(false); var receiverLogger = _loggerFactory ?.CreateLogger(typeof(SslStreamConnectionAdapter).FullName + ".Receiver"); var receiverService = new NonClosingNetworkStreamReader( sslStream, _connectionPipe.Output, _socketPipe.Input, _connectionClosed, receiverLogger); var transmitterLogger = _loggerFactory ?.CreateLogger(typeof(SslStreamConnectionAdapter).FullName + ".Transmitter"); var transmitterService = new NonClosingNetworkStreamWriter( sslStream, _connectionPipe.Input, _connectionClosed, transmitterLogger); var info = new SslCommunicationInfo(transmitterService, receiverService, sslStream); _info = info; await info.TransmitterService.StartAsync(cancellationToken) .ConfigureAwait(false); await info.ReceiverService.StartAsync(cancellationToken) .ConfigureAwait(false); }
/// <inheritdoc /> public async Task StopAsync(CancellationToken cancellationToken) { if (_info == null) { // Service wasn't started yet! return; } var info = _info; var receiverStopTask = info.ReceiverService.StopAsync(cancellationToken); var transmitterStopTask = info.TransmitterService.StopAsync(cancellationToken); await Task.WhenAll(receiverStopTask, transmitterStopTask) .ConfigureAwait(false); await _sslStreamWrapperFactory.CloseStreamAsync(info.SslStream, cancellationToken) .ConfigureAwait(false); _info = null; }