Пример #1
0
        public async Task StartAsync(CancellationToken cancelToken)
        {
            server?.Dispose();
            this.cancelToken = cancelToken;
            server           = new TcpListenerActive(IPAddress.Any, port);
            server.Start(maxConnectionCount);
            cancelToken.Register(Dispose);
            try
            {
                while (server != null && server.Active)
                {
                    try
                    {
                        await ProcessConnection();
                    }
                    catch (ObjectDisposedException)
                    {
                        // happens on shutdown
                    }
                    catch (Exception ex)
                    {
                        MailDemonLog.Error(ex);
                    }
                }
            }
            catch (Exception ex2)
            {
                MailDemonLog.Error(ex2);
            }

            MailDemonLog.Warn("SMTP server is shutdown");
        }
Пример #2
0
 public void Dispose()
 {
     try
     {
         MailDemonLog.Warn("Disposing SMTP server");
         server?.Dispose();
     }
     catch
     {
     }
     server = null;
 }
    public async Task StartAsync(int port, CancellationToken token)
    {
        if (server != null)
        {
            server.Stop();
        }

        server = new TcpListenerActive(IPAddress.Any, port);
        server.Start(maxConnectionCount);
        token.Register(() => server.Stop());
        while (server.Active)
        {
            try
            {
                await ProcessConnection();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
    }
Пример #4
0
        public async Task StartAsync(CancellationToken cancelToken)
        {
            server?.Dispose();
            this.cancelToken = cancelToken;
            server           = new TcpListenerActive(IPAddress.Any, port);
            server.Start(maxConnectionCount);
            cancelToken.Register(Dispose);
            try
            {
                while (server != null && server.Active)
                {
                    TcpClient tcpClient = null;
                    try
                    {
                        // handle connection in background
                        tcpClient = await server.AcceptTcpClientAsync();
                    }
                    catch (ObjectDisposedException)
                    {
                        // ignore, happens on shutdown
                    }
                    catch (Exception ex)
                    {
                        MailDemonLog.Error("Error connecting incoming socket", ex);
                        continue;
                    }

                    // process connection in background
                    ProcessConnection(tcpClient).GetAwaiter();
                }
            }
            catch (Exception ex2)
            {
                MailDemonLog.Error(ex2);
            }

            MailDemonLog.Warn("SMTP server is shutdown");
        }