Пример #1
0
 private Socket GetSocket()
 {
     try
     {
         if (_socket == null || !_socket.Connected)
         {
             var endPoint = new UnixDomainSocketEndPoint(IpcPath);
             _socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
             _socket.Connect(endPoint);
         }
     }
     catch
     {
         //Connection error we want to allow to retry.
         _socket = null;
         throw;
     }
     return(_socket);
 }
Пример #2
0
        protected override async Task <TResponse> SendAsync <TRequest, TResponse>(TRequest request)
        {
            try
            {
                var rpcRequestJson = JsonConvert.SerializeObject(request, JsonSerializerSettings);
                var requestBytes   = Encoding.UTF8.GetBytes(rpcRequestJson);

                var endPoint = new UnixDomainSocketEndPoint(IpcPath);


                using (var client = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified))
                {
                    client.Connect(endPoint);
                    client.SendBufferSize = requestBytes.Length;
#if NET462
                    var val = client.Send(requestBytes, SocketFlags.None);
#else
                    var val = await client.SendAsync(new ArraySegment <byte>(requestBytes, 0, requestBytes.Length), SocketFlags.None).ConfigureAwait(false);
#endif
                    using (var memoryStream = ReceiveFullResponse(client))
                    {
                        memoryStream.Position = 0;
                        using (StreamReader streamReader = new StreamReader(memoryStream))
                            using (JsonTextReader reader = new JsonTextReader(streamReader))
                            {
                                var serializer = JsonSerializer.Create(JsonSerializerSettings);
                                return(serializer.Deserialize <TResponse>(reader));
                            }
                        throw new RpcClientUnknownException(
                                  $"Unable to parse response from the ipc server");
                    }
                }
            }
            catch (Exception ex) when(!(ex is RpcClientException) && !(ex is RpcException))
            {
                throw new RpcClientUnknownException("Error occurred when trying to send ipc requests(s)", ex);
            }
        }
Пример #3
0
 private Socket GetSocket()
 {
     try
     {
         if (_socket == null || !_socket.Connected)
         {
             var endPoint = new UnixDomainSocketEndPoint(IpcPath);
             _socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
             if (!Task.Run(() =>
                           _socket.Connect(endPoint)).Wait(ConnectionTimeout))
             {
                 throw new RpcClientTimeoutException($"Rpc timeout afer {ConnectionTimeout} milliseconds");
             }
         }
     }
     catch
     {
         //Connection error we want to allow to retry.
         _socket = null;
         throw;
     }
     return(_socket);
 }