private async Task <NodeGreetingMessage> ReadGreetingAsync(CancellationToken cancellationToken) { var read = await _streamSocket.ReadAsync(_singleByteBuffer, 0, 1, cancellationToken).ConfigureAwait(false); if (read == 0) { throw new RedFoxProtocolException("Error receiving greeting message from remote machine"); } var headerLength = _singleByteBuffer[0]; var header = new byte[headerLength]; var offset = 0; while (headerLength - offset > 0) { read = await _streamSocket.ReadAsync(header, offset, headerLength - offset, cancellationToken); if (read == 0) { throw new RedFoxProtocolException("Error receiving greeting message from remote machine"); } offset += read; } return(NodeGreetingMessage.DeserializeWithoutLength(header)); }
private static async Task<byte[]> ReadHeaderAsync(IStreamSocket socket, CancellationToken cancellationToken) { var header = new byte[6]; var offset = 0; while (offset < header.Length) { var read = await socket.ReadAsync(header, 0, header.Length, cancellationToken); if (read == 0) throw new EndOfStreamException(); offset += read; } return header; }
private static async Task<byte[]> ReadBodyAsync(IStreamSocket socket, int length, CancellationToken cancellationToken) { var rawMessage = new byte[length]; var offset = 0; while (offset < length) { var read = await socket.ReadAsync(rawMessage, offset, rawMessage.Length - offset, cancellationToken); if (read == 0) throw new EndOfStreamException(); offset += read; } return rawMessage; }
private static async Task <byte[]> ReadHeaderAsync(IStreamSocket socket, CancellationToken cancellationToken) { var header = new byte[6]; var offset = 0; while (offset < header.Length) { var read = await socket.ReadAsync(header, 0, header.Length, cancellationToken); if (read == 0) { throw new EndOfStreamException(); } offset += read; } return(header); }
private static async Task <byte[]> ReadBodyAsync(IStreamSocket socket, int length, CancellationToken cancellationToken) { var rawMessage = new byte[length]; var offset = 0; while (offset < length) { var read = await socket.ReadAsync(rawMessage, offset, rawMessage.Length - offset, cancellationToken); if (read == 0) { throw new EndOfStreamException(); } offset += read; } return(rawMessage); }