protected override async Task <IDuplexPipe> ConnectPipelineAsync(int sendMaxMessageSize, int receiveMaxMessageSize, CancellationToken cancellationToken)
        {
            // TODO: The URL should be parsed in RpConnectionInfo constructor .
            // If invalid an ArgumentException should be thrown there.

            if (this.ConnectionInfo.HostUrl is Uri url)
            {
#pragma warning disable CA2000 // Dispose objects before losing scope
                string pipeName = PipeUri.LookupPipeName(url);
                if (string.IsNullOrEmpty(pipeName))
                {
                    throw new RpcCommunicationException(RpcCommunicationStatus.Unavailable, $"Failed to connect to named pipe at '{url}'");
                }

                NamedPipeClientStream?pipeClientStream = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut, System.IO.Pipes.PipeOptions.Asynchronous);

                try
                {
                    await pipeClientStream.ConnectAsync(cancellationToken).ContextFree();

                    var sendOptions = new System.IO.Pipelines.PipeOptions(
                        pauseWriterThreshold: sendMaxMessageSize * 2, resumeWriterThreshold: sendMaxMessageSize,
                        readerScheduler: System.IO.Pipelines.PipeScheduler.Inline,
                        useSynchronizationContext: false);
                    var receiveOptions = new System.IO.Pipelines.PipeOptions(
                        pauseWriterThreshold: receiveMaxMessageSize * 2, resumeWriterThreshold: receiveMaxMessageSize,
                        readerScheduler: System.IO.Pipelines.PipeScheduler.Inline,
                        useSynchronizationContext: false);

                    var connection = new StreamDuplexPipe(pipeClientStream); //, sendOptions, receiveOptions);

                    pipeClientStream = null;                                 // Prevent disposal

                    return(connection);
                }
                finally
                {
                    pipeClientStream?.Dispose();
                }
#pragma warning restore CA2000 // Dispose objects before losing scope
            }
            else
            {
                throw new InvalidOperationException("Missing connection URL.");
            }
        }
Ejemplo n.º 2
0
        public PipeTransport(PipeStream pipeStream, ILogger <PipeTransport> logger)
        {
            ConnectionClosed = _connectionClosedTokenSource.Token;

            _stream = pipeStream;
            _logger = logger;

            var pipeOptions = new System.IO.Pipelines.PipeOptions(
                readerScheduler: PipeScheduler.ThreadPool,
                writerScheduler: PipeScheduler.ThreadPool,
                useSynchronizationContext: false
                );

            //  these pipes operate as pairs
            //  Transport is the pipes Kestrel will use to send and receive data
            //  Application is how this class will read data to send and buffer data that's read from the remote
            var pipes = DuplexPipe.CreateConnectionPair(pipeOptions, pipeOptions);

            Transport    = pipes.Transport;
            _application = pipes.Application;
        }
Ejemplo n.º 3
0
        public static (IDuplexPipe Transport, IDuplexPipe Application) CreateConnectionPair(PipeOptions inputOptions, PipeOptions outputOptions)
        {
            var input  = new Pipe(inputOptions);
            var output = new Pipe(outputOptions);

            var transportToApplication = new PipeConnection(output.Reader, input.Writer);
            var applicationToTransport = new PipeConnection(input.Reader, output.Writer);

            return(applicationToTransport, transportToApplication);
        }
Ejemplo n.º 4
0
 public StreamPipeline(PipeOptions options)
 {
     this.pipe   = new Pipe(options);
     this.reader = new StreamPipelineReader(this.pipe.Reader);
     this.writer = new StreamPipelineWriter(this.pipe.Writer);
 }
Ejemplo n.º 5
0
 public IPipe Create(PipeOptions options)
 {
     return(new Pipe(_pool, options));
 }
Ejemplo n.º 6
0
 public StreamPipeConnection(PipeOptions options, Stream stream)
 {
     Input  = CreateReader(options, stream);
     Output = CreateWriter(options, stream);
 }