private void Handshake()
 {
     this.connection.responseReader = new SmtpReplyReaderFactory(this.connection.pooledStream.NetworkStream);
     this.connection.pooledStream.UpdateLifetime();
     if (((SmtpPooledStream)this.connection.pooledStream).previouslyUsed)
     {
         this.connection.isConnected = true;
         base.InvokeCallback();
     }
     else
     {
         SmtpReplyReader nextReplyReader = this.connection.Reader.GetNextReplyReader();
         IAsyncResult    result          = nextReplyReader.BeginReadLine(handshakeCallback, this);
         if (result.CompletedSynchronously)
         {
             LineInfo info = nextReplyReader.EndReadLine(result);
             if (info.StatusCode != SmtpStatusCode.ServiceReady)
             {
                 throw new SmtpException(info.StatusCode, info.Line, true);
             }
             try
             {
                 if (!this.SendEHello())
                 {
                 }
             }
             catch
             {
                 if (!this.SendHello())
                 {
                 }
             }
         }
     }
 }
Exemple #2
0
            private void Handshake()
            {
                _connection._responseReader = new SmtpReplyReaderFactory(_connection._networkStream);

                SmtpReplyReader reader = _connection.Reader.GetNextReplyReader();
                IAsyncResult    result = reader.BeginReadLine(s_handshakeCallback, this);

                if (!result.CompletedSynchronously)
                {
                    return;
                }

                LineInfo info = reader.EndReadLine(result);

                if (info.StatusCode != SmtpStatusCode.ServiceReady)
                {
                    throw new SmtpException(info.StatusCode, info.Line, true);
                }
                try
                {
                    if (!SendEHello())
                    {
                        return;
                    }
                }
                catch
                {
                    if (!SendHello())
                    {
                        return;
                    }
                }
            }
 private static void HandshakeCallback(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         ConnectAndHandshakeAsyncResult thisPtr = (ConnectAndHandshakeAsyncResult)result.AsyncState !;
         try
         {
             try
             {
                 LineInfo info = SmtpReplyReader.EndReadLine(result);
                 if (info.StatusCode != SmtpStatusCode.ServiceReady)
                 {
                     thisPtr.InvokeCallback(new SmtpException(info.StatusCode, info.Line, true));
                     return;
                 }
                 if (!thisPtr.SendEHello())
                 {
                     return;
                 }
             }
             catch (SmtpException)
             {
                 if (!thisPtr.SendHello())
                 {
                     return;
                 }
             }
         }
         catch (Exception e)
         {
             thisPtr.InvokeCallback(e);
         }
     }
 }
Exemple #4
0
        internal static IAsyncResult BeginSend(SmtpConnection conn, AsyncCallback callback, object state)
        {
            MultiAsyncResult multiResult = new MultiAsyncResult(conn, callback, state);

            multiResult.Enter();
            IAsyncResult writeResult = conn.BeginFlush(s_onWrite, multiResult);

            if (writeResult.CompletedSynchronously)
            {
                conn.EndFlush(writeResult);
                multiResult.Leave();
            }
            SmtpReplyReader reader = conn.Reader.GetNextReplyReader();

            multiResult.Enter();

            //this actually does a read on the stream.
            IAsyncResult result = reader.BeginReadLine(s_onReadLine, multiResult);

            if (result.CompletedSynchronously)
            {
                LineInfo info = reader.EndReadLine(result);
                if (!(multiResult.Result is Exception))
                {
                    multiResult.Result = info;
                }
                multiResult.Leave();
            }
            multiResult.CompleteSequence();
            return(multiResult);
        }
Exemple #5
0
        internal static IAsyncResult BeginSend(SmtpConnection conn, AsyncCallback callback, object state)
        {
            MultiAsyncResult result = new MultiAsyncResult(conn, callback, state);

            result.Enter();
            IAsyncResult result2 = conn.BeginFlush(onWrite, result);

            if (result2.CompletedSynchronously)
            {
                conn.EndFlush(result2);
                result.Leave();
            }
            SmtpReplyReader nextReplyReader = conn.Reader.GetNextReplyReader();

            result.Enter();
            IAsyncResult result3 = nextReplyReader.BeginReadLine(onReadLine, result);

            if (result3.CompletedSynchronously)
            {
                LineInfo info = nextReplyReader.EndReadLine(result3);
                if (!(result.Result is Exception))
                {
                    result.Result = info;
                }
                result.Leave();
            }
            result.CompleteSequence();
            return(result);
        }
Exemple #6
0
            void Handshake()
            {
                connection.responseReader = new SmtpReplyReaderFactory(connection.pooledStream.NetworkStream);


                //if we've already used this stream, then we've already done the handshake

                //set connectionlease
                connection.pooledStream.UpdateLifetime();

                if (((SmtpPooledStream)connection.pooledStream).previouslyUsed == true)
                {
                    connection.isConnected = true;
                    InvokeCallback();
                    return;
                }


                SmtpReplyReader reader = connection.Reader.GetNextReplyReader();
                IAsyncResult    result = reader.BeginReadLine(handshakeCallback, this);

                if (!result.CompletedSynchronously)
                {
                    return;
                }

                LineInfo info = reader.EndReadLine(result);

                if (info.StatusCode != SmtpStatusCode.ServiceReady)
                {
                    throw new SmtpException(info.StatusCode, info.Line, true);
                }
                try
                {
                    if (!SendEHello())
                    {
                        return;
                    }
                }
                catch
                {
                    if (!SendHello())
                    {
                        return;
                    }
                }
            }
Exemple #7
0
 private static void OnReadLine(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         MultiAsyncResult multiResult = (MultiAsyncResult)result.AsyncState !;
         try
         {
             SmtpConnection conn = (SmtpConnection)multiResult.Context;
             LineInfo       info = SmtpReplyReader.EndReadLine(result);
             if (!(multiResult.Result is Exception))
             {
                 multiResult.Result = info;
             }
             multiResult.Leave();
         }
         catch (Exception e)
         {
             multiResult.Leave(e);
         }
     }
 }