public WriteAsync ( byte buffer, int offset, int count, System cancellationToken ) : System.Threading.Tasks.Task | ||
buffer | byte | |
offset | int | |
count | int | |
cancellationToken | System | |
return | System.Threading.Tasks.Task |
static void WriteBytesAsync(PipeStream pipeStream, byte[] buffer) { Assert.True(pipeStream.IsConnected); Assert.True(buffer.Length > 0); Task writeTask = pipeStream.WriteAsync(buffer, 0, buffer.Length); writeTask.Wait(); }
static Task WriteBytesAsync(PipeStream pipeStream, byte[] buffer) { Assert.True(pipeStream.IsConnected); Assert.True(buffer.Length > 0); return pipeStream.WriteAsync(buffer, 0, buffer.Length); }
public async Task WriteAsync(PipeStream outStream, CancellationToken cancellationToken) { using (var writer = new BinaryWriter(new MemoryStream(), Encoding.Unicode)) { // Format the response CompilerServerLogger.Log("Formatting Response"); writer.Write(this.ReturnCode); BuildProtocolConstants.WriteLengthPrefixedString(writer, this.Output); BuildProtocolConstants.WriteLengthPrefixedString(writer, this.ErrorOutput); writer.Flush(); cancellationToken.ThrowIfCancellationRequested(); // Send the response to the client // Grab the MemoryStream and its internal buffer to prevent // making another copy. var stream = (MemoryStream)writer.BaseStream; // Write the length of the response uint length = (uint)stream.Length; CompilerServerLogger.Log("Writing response length"); // There is no way to know the number of bytes written to // the pipe stream. We just have to assume all of them are written. await outStream.WriteAsync(BitConverter.GetBytes(length), 0, 4, cancellationToken).ConfigureAwait(false); // Write the response CompilerServerLogger.Log("Writing response of size {0}", length); // There is no way to know the number of bytes written to // the pipe stream. We just have to assume all of them are written. await outStream.WriteAsync(stream.GetBuffer(), 0, (int)length, cancellationToken).ConfigureAwait(false); } }
/// <summary> /// Write a Request to the stream. /// </summary> public async Task WriteAsync(PipeStream outStream, CancellationToken cancellationToken) { using (var writer = new BinaryWriter(new MemoryStream(), Encoding.Unicode)) { // Format the request. CompilerServerLogger.Log("Formatting request"); writer.Write(this.Id); writer.Write(this.Arguments.Length); foreach (Argument arg in this.Arguments) { cancellationToken.ThrowIfCancellationRequested(); arg.WriteToBinaryWriter(writer); } writer.Flush(); cancellationToken.ThrowIfCancellationRequested(); // Grab the MemoryStream and its internal buffer // to prevent making another copy. var stream = (MemoryStream)writer.BaseStream; // Write the length of the request int length = (int)stream.Length; // Back out if the request is > 1 MB if (stream.Length > 0x100000) { CompilerServerLogger.Log("Request is over 1MB in length, cancelling write"); throw new ArgumentOutOfRangeException(); } // Send the request to the server CompilerServerLogger.Log("Writing length of request."); await outStream.WriteAsync(BitConverter.GetBytes(length), 0, 4, cancellationToken).ConfigureAwait(false); CompilerServerLogger.Log("Writing request of size {0}", length); // Write the request await outStream.WriteAsync(stream.GetBuffer(), 0, length, cancellationToken).ConfigureAwait(false); } }