public MultiplexedPipeConnection(NamedPipeServerStream pipeServer, QueueBufferedStream multiplexedOutputStream) : base(pipeServer.Write) { this.pipeServer = pipeServer; outputPump = new MultiplexConnectionOutputPump(pipeServer.Read, multiplexedOutputStream.Write, Id); outputPump.BeginRunPump(PumpComplete, null); }
void EnsureConnection() { lock (connectLock) { if (dataChannel == null) { multiplexedOutputStream = new ThrottledQueueBufferedStream(10); QueueBufferedStream multiplexedInputStream = new QueueBufferedStream(); dataChannelFactory = new HybridConnectionClient(endpointVia, tokenProvider); dataChannel = dataChannelFactory.CreateConnectionAsync().GetAwaiter().GetResult(); try { var preambleWriter = new BinaryWriter(dataChannel); preambleWriter.Write("np:" + toPipe); rawInputPump = new StreamBufferWritePump(dataChannel, multiplexedInputStream.Write); rawInputPump.BeginRunPump(RawInputPumpCompleted, false); inputPump = new MultiplexConnectionInputPump(multiplexedInputStream.Read, CorrelateConnection, null); inputPump.Run(false); outputPump = new StreamBufferWritePump(multiplexedOutputStream, WriteToDataChannel); outputPump.BeginRunPump(MultiplexPumpCompleted, null); } catch (AuthorizationFailedException af) { Trace.TraceError("Authorization failed: {0}", af.Message); if (dataChannel != null) { DataChannelClose(); dataChannel = null; } throw; } catch (Exception ex) { Trace.TraceError("Unable to establish data channel: {0}", ex.Message); if (dataChannel != null) { DataChannelClose(); dataChannel = null; } throw; } } } }