// // This method assumes that InnerStream type == typeof(NetwokrStream) // It will produce a set of buffers for one MultipleWrite call // private void StartWriting(SplitWritesState splitWrite, SplitWriteAsyncProtocolRequest asyncRequest) { while (!splitWrite.IsDone) { // request a write IO slot if (_SslState.CheckEnqueueWrite(asyncRequest)) { // operation is async and has been queued, return. return; } byte[] lastHandshakePayload = null; if (_SslState.LastPayload != null) { // // !!! LastPayload Only used in TlsStream for HTTP and it needs re-work for a general case !!! // lastHandshakePayload = _SslState.LastPayload; _SslState.LastPayloadConsumed(); } BufferOffsetSize[] buffers = splitWrite.GetNextBuffers(); buffers = EncryptBuffers(buffers, lastHandshakePayload); if (asyncRequest != null) { // prepare for the next request IAsyncResult ar = ((NetworkStream)(_SslState.InnerStream)).BeginMultipleWrite(buffers, _MulitpleWriteCallback, asyncRequest); if (!ar.CompletedSynchronously) { return; } ((NetworkStream)(_SslState.InnerStream)).EndMultipleWrite(ar); } else { ((NetworkStream)(_SslState.InnerStream)).MultipleWrite(buffers); } // release write IO slot _SslState.FinishWrite(); } if (asyncRequest != null) { asyncRequest.CompleteUser(); } }
private void StartWriting(SplitWritesState splitWrite, SplitWriteAsyncProtocolRequest asyncRequest) { while (!splitWrite.IsDone) { if (this._SslState.CheckEnqueueWrite(asyncRequest)) { return; } byte[] lastHandshakePayload = null; if (this._SslState.LastPayload != null) { lastHandshakePayload = this._SslState.LastPayload; this._SslState.LastPayloadConsumed(); } BufferOffsetSize[] nextBuffers = splitWrite.GetNextBuffers(); nextBuffers = this.EncryptBuffers(nextBuffers, lastHandshakePayload); if (asyncRequest != null) { IAsyncResult asyncResult = ((NetworkStream)this._SslState.InnerStream).BeginMultipleWrite(nextBuffers, _MulitpleWriteCallback, asyncRequest); if (!asyncResult.CompletedSynchronously) { return; } ((NetworkStream)this._SslState.InnerStream).EndMultipleWrite(asyncResult); } else { ((NetworkStream)this._SslState.InnerStream).MultipleWrite(nextBuffers); } this._SslState.FinishWrite(); } if (asyncRequest != null) { asyncRequest.CompleteUser(); } }
// // This method assumes that InnerStream type == typeof(NetwokrStream) // It will produce a set of buffers for one MultipleWrite call // private void StartWriting(SplitWritesState splitWrite, SplitWriteAsyncProtocolRequest asyncRequest) { while (!splitWrite.IsDone) { // request a write IO slot if (_SslState.CheckEnqueueWrite(asyncRequest)) { // operation is async and has been queued, return. return; } byte[] lastHandshakePayload = null; if (_SslState.LastPayload != null) { // // !!! LastPayload Only used in TlsStream for HTTP and it needs re-work for a general case !!! // lastHandshakePayload = _SslState.LastPayload; _SslState.LastPayloadConsumed(); } BufferOffsetSize[] buffers = splitWrite.GetNextBuffers(); buffers = EncryptBuffers(buffers, lastHandshakePayload); if (asyncRequest != null) { // prepare for the next request IAsyncResult ar = ((NetworkStream)(_SslState.InnerStream)).BeginMultipleWrite(buffers, _MulitpleWriteCallback, asyncRequest); if (!ar.CompletedSynchronously) return; ((NetworkStream)(_SslState.InnerStream)).EndMultipleWrite(ar); } else { ((NetworkStream)(_SslState.InnerStream)).MultipleWrite(buffers); } // release write IO slot _SslState.FinishWrite(); } if (asyncRequest != null) asyncRequest.CompleteUser(); }
private void StartWriting(SplitWritesState splitWrite, SplitWriteAsyncProtocolRequest asyncRequest) { while (!splitWrite.IsDone) { if (this._SslState.CheckEnqueueWrite(asyncRequest)) { return; } byte[] lastHandshakePayload = null; if (this._SslState.LastPayload != null) { lastHandshakePayload = this._SslState.LastPayload; this._SslState.LastPayloadConsumed(); } BufferOffsetSize[] nextBuffers = splitWrite.GetNextBuffers(); nextBuffers = this.EncryptBuffers(nextBuffers, lastHandshakePayload); if (asyncRequest != null) { IAsyncResult asyncResult = ((NetworkStream) this._SslState.InnerStream).BeginMultipleWrite(nextBuffers, _MulitpleWriteCallback, asyncRequest); if (!asyncResult.CompletedSynchronously) { return; } ((NetworkStream) this._SslState.InnerStream).EndMultipleWrite(asyncResult); } else { ((NetworkStream) this._SslState.InnerStream).MultipleWrite(nextBuffers); } this._SslState.FinishWrite(); } if (asyncRequest != null) { asyncRequest.CompleteUser(); } }