Ejemplo n.º 1
0
        private void TransportKeepAlive()
        {
            if (_client.IsSocketConnected == false)
            {
                try
                {
                    _client.Close();
                }
                catch
                {
                }
            }

            if (_client.TransportState == TcpTransportState.Closed)
            {
                var oldClient = _client;
                if (oldClient == null)
                {
                    throw new RpcException("FastRpcClient TransportKeepAlive failed,client has been been closed");
                }

                var newClient      = (SimpleRpcClient)SimpleRpcClientPoolRoot.Depool(ServerIP, ServerPort);
                var originalClient = Interlocked.CompareExchange(ref _client, newClient, oldClient);
                if (originalClient != oldClient)
                {
                    SimpleRpcClientPoolRoot.Enpool(newClient);
                    throw new RpcException("FastRpcClient TransportKeepAlive failed,client has been been closed");
                }
            }
        }
Ejemplo n.º 2
0
        public void Close()
        {
            var originalClient = Interlocked.Exchange(ref _client, null);

            if (originalClient == null)
            {
                return;
            }

            if (originalClient.TransportState == TcpTransportState.Closed)
            {
                return;
            }

            var cacheResult = SimpleRpcClientPoolRoot.Enpool(originalClient);

            if (cacheResult == false)
            {
                try
                {
                    originalClient.Dispose();
                }
                catch
                {
                    LogAgent.Warn("SimpleRpcClient Dispose error");
                }
            }
        }
Ejemplo n.º 3
0
        public FastRpcClient(IPAddress ip, int port)
        {
            ServerIP   = ip;
            ServerPort = port;

            _client = (SimpleRpcClient)SimpleRpcClientPoolRoot.Depool(ip, port);
        }
Ejemplo n.º 4
0
        public void Close()
        {
            if (_client == null)
            {
                return;
            }

            var oldValue = Interlocked.Exchange(ref _client, null);

            if (oldValue == null)
            {
                return;
            }

            var cacheResult = SimpleRpcClientPoolRoot.ReturnItem(oldValue);

            if (cacheResult == false)
            {
                try
                {
                    oldValue.Dispose();
                }
                catch
                {
                    LogAgent.Error("SimpleRpcCLient Dispose error");
                }
            }
        }