private ClientConnectionContext CreateConnectionContext <TRequest, TResponse>(
            Method <TRequest, TResponse> method, CallOptions callOptions, TRequest request)
            where TRequest : class where TResponse : class
        {
            var stream = NamedPipeStreamFactory.CreateClient(_serverName, _pipeName, _options);

            try
            {
                bool isServerUnary = method.Type == MethodType.Unary || method.Type == MethodType.ClientStreaming;
                var  ctx           = new ClientConnectionContext(stream, callOptions, isServerUnary, _options.ConnectionTimeout);
                ctx.InitCall(method, request);
                Task.Run(new PipeReader(stream, ctx, ctx.Dispose).ReadLoop);
                return(ctx);
            }
            catch (Exception ex)
            {
                stream.Dispose();

                if (ex is TimeoutException)
                {
                    throw new RpcException(new Status(StatusCode.Unavailable, "failed to connect to all addresses"));
                }
                else
                {
                    throw;
                }
            }
        }
Example #2
0
 public NamedPipeChannel(string serverName, string pipeName, NamedPipeChannelOptions options) :
     this(() => NamedPipeStreamFactory.CreateClient(serverName, pipeName, options), options.ConnectionTimeout)
 {
     this.ConnectionTimeout = options.ConnectionTimeout;
 }
Example #3
0
 private INamedPipeServerStream CreatePipeServer()
 {
     return(NamedPipeStreamFactory.Create(_pipeName, _options));
 }
Example #4
0
 public NamedPipeServer(string pipeName, NamedPipeServerOptions options)
     : this(() => NamedPipeStreamFactory.Create(pipeName, options))
 {
 }