示例#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;
        }
 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.BeginReadLines(onReadLines, result);
     if (result3.CompletedSynchronously)
     {
         LineInfo[] infoArray = conn.Reader.CurrentReader.EndReadLines(result3);
         if (!(result.Result is Exception))
         {
             result.Result = infoArray;
         }
         result.Leave();
     }
     result.CompleteSequence();
     return result;
 }
示例#3
0
 protected void Flush(MultiAsyncResult multiResult)
 {
     if (this.bufferBuilder.Length > 0)
     {
         if (multiResult != null)
         {
             multiResult.Enter();
             IAsyncResult result = this.stream.BeginWrite(
                 this.bufferBuilder.GetBuffer(),
                 0,
                 this.bufferBuilder.Length,
                 onWrite,
                 multiResult);
             if (result.CompletedSynchronously)
             {
                 this.stream.EndWrite(result);
                 multiResult.Leave();
             }
         }
         else
         {
             this.stream.Write(this.bufferBuilder.GetBuffer(), 0, this.bufferBuilder.Length);
         }
         this.bufferBuilder.Reset();
     }
 }
示例#4
0
 protected static void OnWrite(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         MultiAsyncResult multiResult = (MultiAsyncResult)result.AsyncState;
         BaseWriter       thisPtr     = (BaseWriter)multiResult.Context;
         try
         {
             thisPtr._stream.EndWrite(result);
             multiResult.Leave();
         }
         catch (Exception e)
         {
             multiResult.Leave(e);
         }
     }
 }
示例#5
0
 private static void OnWrite(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         MultiAsyncResult asyncState = (MultiAsyncResult)result.AsyncState;
         MimeWriter       context    = (MimeWriter)asyncState.Context;
         try
         {
             context.stream.EndWrite(result);
             asyncState.Leave();
         }
         catch (Exception exception)
         {
             asyncState.Leave(exception);
         }
     }
 }
示例#6
0
 protected void Flush(MultiAsyncResult multiResult)
 {
     if (_bufferBuilder.Length > 0)
     {
         if (multiResult != null)
         {
             multiResult.Enter();
             var asyncResult = _stream.BeginWrite(_bufferBuilder.GetBuffer(), 0, _bufferBuilder.Length, _onWrite, multiResult);
             if (asyncResult.CompletedSynchronously)
             {
                 _stream.EndWrite(asyncResult);
                 multiResult.Leave();
             }
         }
         else
             _stream.Write(_bufferBuilder.GetBuffer(), 0, _bufferBuilder.Length);
         _bufferBuilder.Reset();
     }
 }
 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();
     }
 }
示例#8
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;
 }