Пример #1
0
        async Task ListenAsync(SmtpSessionContext sessionContext, IEndpointListener endpointListener, CancellationToken cancellationToken)
        {
            // The listener can be stopped either by the caller cancelling the CancellationToken used when starting the server, or when calling
            // the shutdown method. The Shutdown method will stop the listeners and allow any active sessions to finish gracefully.
            var cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(_shutdownTokenSource.Token, cancellationToken);

            // wait for a client connection
            var stream = await endpointListener.GetStreamAsync(sessionContext, cancellationTokenSource.Token).ConfigureAwait(false);

            cancellationTokenSource.Token.ThrowIfCancellationRequested();

            sessionContext.NetworkClient = new NetworkClient(stream, _options.NetworkBufferSize);

            if (sessionContext.EndpointDefinition.IsSecure && _options.ServerCertificate != null)
            {
                await sessionContext.NetworkClient.Stream.UpgradeAsync(_options.ServerCertificate, _options.SupportedSslProtocols, cancellationToken).ConfigureAwait(false);

                cancellationToken.ThrowIfCancellationRequested();
            }

            _sessions.Run(sessionContext, cancellationToken);
        }
Пример #2
0
        async Task <ISecurableDuplexPipe> GetPipeAsync(IEndpointListener endpointListener, SmtpSessionContext sessionContext, CancellationToken cancellationToken)
        {
            var pipe = await endpointListener.GetPipeAsync(sessionContext, cancellationToken).ConfigureAwait(false);

            try
            {
                cancellationToken.ThrowIfCancellationRequested();

                if (sessionContext.EndpointDefinition.IsSecure && _options.ServerCertificate != null)
                {
                    await pipe.UpgradeAsync(_options.ServerCertificate, _options.SupportedSslProtocols, cancellationToken).ConfigureAwait(false);

                    cancellationToken.ThrowIfCancellationRequested();
                }
            }
            catch
            {
                pipe.Dispose();

                throw;
            }

            return(pipe);
        }
Пример #3
0
 public CustomEndpointListener(IEndpointListener endpointListener)
 {
     _endpointListener = endpointListener;
 }