public IAsyncResult BeginSend(byte[] buffer, int offset, int count, AsyncCallback asyncCallback, Object asyncState) { AsyncSendDataResult asyncSendResult = new AsyncSendDataResult(asyncCallback, asyncState); lock (_handshakeLock) { if (!_isAuthenticated) { Exception e = new InvalidOperationException("Trying to send on an unauthenticated session"); asyncSendResult.SetComplete(e); return(asyncSendResult); } if (_isHandshaking) { // Queue requests to send data during renegotiation // TODO: implement this when renegotiation is implemented Exception e = new InvalidOperationException("Sending data during renegotiation not implemented"); asyncSendResult.SetComplete(e); return(asyncSendResult); } } // Copy the bytes to send into own buffer byte[] outputBuffer = new byte[count]; Buffer.BlockCopy(buffer, offset, outputBuffer, 0, count); // Create and encrypt the data output record Record[] records = _handshakePacketizer.ProcessOutputData(_handshakeSession.NegotiatedVersion, RecordType.Data, outputBuffer, _recordStream.MaximumFragmentLength); for (int i = 0; i < records.Length; i++) { _recordHandler.ProcessOutputRecord(records[i]); } // Send the data output record _recordStream.BeginSend(records, new AsyncCallback(SendDataCallback), asyncSendResult); return(asyncSendResult); }