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); }
internal Stream EndGetContentStream(IAsyncResult result) { object o = MultiAsyncResult.End(result); if (o is Exception e) { ExceptionDispatchInfoThrower.Throw(e); } return((Stream)o); }
internal IAsyncResult BeginClose(AsyncCallback callback, object state) { MultiAsyncResult multiResult = new MultiAsyncResult(this, callback, state); Close(multiResult); multiResult.CompleteSequence(); return(multiResult); }
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); }
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); } } }
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); }
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(); } }
internal void EndClose(IAsyncResult result) { MultiAsyncResult.End(result); _stream.Close(); }