Beispiel #1
0
 private void Close(MultiAsyncResult multiResult)
 {
     _bufferBuilder.Append(s_crlf);
     _bufferBuilder.Append(s_DASHDASH);
     _bufferBuilder.Append(_boundaryBytes);
     _bufferBuilder.Append(s_DASHDASH);
     _bufferBuilder.Append(s_crlf);
     Flush(multiResult);
 }
Beispiel #2
0
        internal Stream EndGetContentStream(IAsyncResult result)
        {
            object o = MultiAsyncResult.End(result);

            if (o is Exception e)
            {
                ExceptionDispatchInfoThrower.Throw(e);
            }
            return((Stream)o);
        }
Beispiel #3
0
        internal IAsyncResult BeginClose(AsyncCallback callback, object state)
        {
            MultiAsyncResult multiResult = new MultiAsyncResult(this, callback, state);

            Close(multiResult);

            multiResult.CompleteSequence();

            return(multiResult);
        }
Beispiel #4
0
        internal IAsyncResult BeginGetContentStream(AsyncCallback callback, object state)
        {
            MultiAsyncResult multiResult = new MultiAsyncResult(this, callback, state);

            Stream s = GetContentStream(multiResult);

            if (!(multiResult.Result is Exception))
            {
                multiResult.Result = s;
            }

            multiResult.CompleteSequence();

            return(multiResult);
        }
Beispiel #5
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);
         }
     }
 }
Beispiel #6
0
        private Stream GetContentStream(MultiAsyncResult multiResult)
        {
            if (_isInContent)
            {
                throw new InvalidOperationException(Strings.MailWriterIsInContent);
            }

            _isInContent = true;

            CheckBoundary();

            _bufferBuilder.Append(s_crlf);
            Flush(multiResult);

            ClosableStream cs = new ClosableStream(new EightBitStream(_stream, _shouldEncodeLeadingDots), _onCloseHandler);

            _contentStream = cs;
            return(cs);
        }
Beispiel #7
0
 protected void Flush(MultiAsyncResult multiResult)
 {
     if (_bufferBuilder.Length > 0)
     {
         if (multiResult != null)
         {
             multiResult.Enter();
             IAsyncResult result = _stream.BeginWrite(_bufferBuilder.GetBuffer(), 0,
                                                      _bufferBuilder.Length, s_onWrite, multiResult);
             if (result.CompletedSynchronously)
             {
                 _stream.EndWrite(result);
                 multiResult.Leave();
             }
         }
         else
         {
             _stream.Write(_bufferBuilder.GetBuffer(), 0, _bufferBuilder.Length);
         }
         _bufferBuilder.Reset();
     }
 }
Beispiel #8
0
        internal void EndClose(IAsyncResult result)
        {
            MultiAsyncResult.End(result);

            _stream.Close();
        }