Example #1
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);
        }
Example #2
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);
        }
Example #3
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();
            IAsyncResult readLinesResult = reader.BeginReadLines(s_onReadLines, multiResult);

            if (readLinesResult.CompletedSynchronously)
            {
                LineInfo[] lines = conn.Reader.CurrentReader.EndReadLines(readLinesResult);
                if (!(multiResult.Result is Exception))
                {
                    multiResult.Result = lines;
                }
                multiResult.Leave();
            }
            multiResult.CompleteSequence();
            return(multiResult);
        }
Example #4
0
 private static void OnWrite(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         MultiAsyncResult asyncState = (MultiAsyncResult)result.AsyncState;
         try
         {
             ((SmtpConnection)asyncState.Context).EndFlush(result);
             asyncState.Leave();
         }
         catch (Exception exception)
         {
             asyncState.Leave(exception);
         }
     }
 }
Example #5
0
 private static void OnWrite(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         MultiAsyncResult multiResult = (MultiAsyncResult)result.AsyncState;
         try
         {
             SmtpConnection conn = (SmtpConnection)multiResult.Context;
             conn.EndFlush(result);
             multiResult.Leave();
         }
         catch (Exception e)
         {
             multiResult.Leave(e);
         }
     }
 }
Example #6
0
 private static void OnWrite(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         MultiAsyncResult asyncState = (MultiAsyncResult)result.AsyncState;
         MailWriter       context    = (MailWriter)asyncState.Context;
         try
         {
             context.stream.EndWrite(result);
             asyncState.Leave();
         }
         catch (Exception exception)
         {
             asyncState.Leave(exception);
         }
     }
 }
Example #7
0
 private static void OnReadLine(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         MultiAsyncResult multiResult = (MultiAsyncResult)result.AsyncState;
         try
         {
             SmtpConnection conn = (SmtpConnection)multiResult.Context;
             LineInfo       info = conn.Reader.CurrentReader.EndReadLine(result);
             if (!(multiResult.Result is Exception))
             {
                 multiResult.Result = info;
             }
             multiResult.Leave();
         }
         catch (Exception e)
         {
             multiResult.Leave(e);
         }
     }
 }
Example #8
0
 private static void OnReadLines(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         MultiAsyncResult multiResult = (MultiAsyncResult)result.AsyncState !;
         try
         {
             SmtpConnection conn  = (SmtpConnection)multiResult.Context;
             LineInfo[]     lines = SmtpReplyReader.EndReadLines(result);
             if (!(multiResult.Result is Exception))
             {
                 multiResult.Result = lines;
             }
             multiResult.Leave();
         }
         catch (Exception e)
         {
             multiResult.Leave(e);
         }
     }
 }
 private static void OnReadLines(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         MultiAsyncResult asyncState = (MultiAsyncResult)result.AsyncState;
         try
         {
             SmtpConnection context   = (SmtpConnection)asyncState.Context;
             LineInfo[]     infoArray = context.Reader.CurrentReader.EndReadLines(result);
             if (!(asyncState.Result is Exception))
             {
                 asyncState.Result = infoArray;
             }
             asyncState.Leave();
         }
         catch (Exception exception)
         {
             asyncState.Leave(exception);
         }
     }
 }
Example #10
0
 private void Flush(MultiAsyncResult multiResult)
 {
     if (this.bufferBuilder.Length > 0)
     {
         if (multiResult != null)
         {
             multiResult.Enter();
             IAsyncResult asyncResult = this.stream.BeginWrite(this.bufferBuilder.GetBuffer(), 0, this.bufferBuilder.Length, onWrite, multiResult);
             if (asyncResult.CompletedSynchronously)
             {
                 this.stream.EndWrite(asyncResult);
                 multiResult.Leave();
             }
         }
         else
         {
             this.stream.Write(this.bufferBuilder.GetBuffer(), 0, this.bufferBuilder.Length);
         }
         this.bufferBuilder.Reset();
     }
 }