public SendRequestMessage(WriteAsyncResult completionHandle, List<ArraySegment<byte>> segments) { this.completionHandle = completionHandle; this.segments = segments; }
internal IAsyncResult BeginWrite(int channelId, byte[] buffer, int offset, int count, AsyncCallback callback, object state) { // Framing logic happen here! List<ArraySegment<byte>> data = new List<ArraySegment<byte>>(); int remainingLength = count; int encodingPointer = offset; while (remainingLength > 0) { if (remainingLength >= Constants.FrameSize) { // A full frame can be sent data.Add(new ArraySegment<byte>(new FrameHeader(Constants.FrameSize, channelId).Encode())); data.Add(new ArraySegment<byte>(buffer, encodingPointer, Constants.FrameSize)); encodingPointer += Constants.FrameSize; remainingLength -= Constants.FrameSize; } else { // A partial frame can be sent data.Add(new ArraySegment<byte>(new FrameHeader(remainingLength, channelId).Encode())); data.Add(new ArraySegment<byte>(buffer, encodingPointer, remainingLength)); encodingPointer += remainingLength; remainingLength -= remainingLength; } } // Handling the close packet if (count == 0) { data.Add(new ArraySegment<byte>(new FrameHeader(0, channelId).Encode())); } WriteAsyncResult asyncResult = new WriteAsyncResult(callback, state, this); this.actorManager.SendMessage(this.senderActor, new SendRequestMessage(asyncResult, data)); return asyncResult; }