netDumbster.smtp.SimpleSmtpServer._SocketHandler C# (CSharp) Method

_SocketHandler() private method

Async Socket handler.
private _SocketHandler ( IAsyncResult result ) : void
result IAsyncResult The result.
return void
        private void _SocketHandler(IAsyncResult result)
        {
            if (this.stop)
            {
                return;
            }

            this.log.Debug("Entering Socket Handler.");

            if (this.Configuration.ProcessingDelayInMilliseconds > 0)
            {
                Thread.Sleep(this.Configuration.ProcessingDelayInMilliseconds);
            }

            try
            {
                TcpListener listener = (TcpListener)result.AsyncState;
                listener.BeginAcceptSocket(new AsyncCallback(this._SocketHandler), listener);

                this.log.Debug("Calling EndAcceptSocket.");

                using (Socket socket = listener.EndAcceptSocket(result))
                {
                    this.log.Debug("Socket accepted and ready to be processed.");
                    SmtpProcessor processor = new SmtpProcessor(string.Empty, this.Configuration.UseMessageStore ? this.smtpMessageStore : null);
                    processor.MessageReceived += (sender, args) =>
                    {
                        if (MessageReceived != null)
                        {
                            MessageReceived(this, args);
                        }
                    };
                    processor.ProcessConnection(socket);
                }
            }
            catch (ObjectDisposedException ex)
            {
                this.log.Warn("Object Disposed Exception. THIS IS EXPECTED ONLY IF SERVER WAS STOPPED.", ex);
            }
            catch (SocketException ex)
            {
                this.log.Warn("Socket Exception", ex);
            }
        }