public StreamPair(PipeWriteWrapper outgoingRequestStream, PipeReadWrapper incomingResponseStream, Action disposeUnderlyingPipe) { this.OutgoingRequestStream = outgoingRequestStream; this.IncomingResponseStream = incomingResponseStream; this._disposeUnderlyingPipe = disposeUnderlyingPipe; }
private static async Task <ConnectionHandlerResult> ConnectionHandler(TaskCompletionSource <bool> tcs, StreamHandlerFunc messageHandler, int maxConcurrentConnections, string pipeNamePrefix) { using (var incomingRequestPipe = new NamedPipeServerStream( pipeNamePrefix + "ParentToChild", PipeDirection.InOut, maxConcurrentConnections)) { incomingRequestPipe.WaitForConnection(); tcs.SetResult(true); //Use the TaskCompletionSource to signal back that the pipe received a connection. var readWrapper = new PipeReadWrapper(incomingRequestPipe); if (readWrapper.CheckRemainingByteChunkSize() == Constants.ShutdownId) { return(ConnectionHandlerResult.Shutdown); } using (var writeWrapper = new PipeWriteWrapper(incomingRequestPipe)) { await messageHandler(readWrapper, writeWrapper); } } return(ConnectionHandlerResult.Normal); }