/// <summary>
 /// 获取一个TCP调用客户端
 /// </summary>
 /// <returns>TCP调用服务器信息</returns>
 protected clientIdentity _getClient_()
 {
     if (isDisposed == 0)
     {
         Monitor.Enter(clientLock);
         int count = currentCount - freeIndexs.length;
         if (count != 0)
         {
             int callCount = this.callCount / count + 1, index = currentIndex;
             do
             {
                 if (clients[currentIndex].TryCount(callCount))
                 {
                     ++this.callCount;
                     clientIdentity value = clients[currentIndex].Client;
                     Monitor.Exit(clientLock);
                     return(value);
                 }
             }while (++currentIndex != currentCount);
             for (currentIndex = 0; currentIndex != index; ++currentIndex)
             {
                 if (clients[currentIndex].TryCount(callCount))
                 {
                     ++this.callCount;
                     clientIdentity value = clients[currentIndex].Client;
                     Monitor.Exit(clientLock);
                     return(value);
                 }
             }
         }
         Monitor.Exit(clientLock);
     }
     return(default(clientIdentity));
 }
        /// <summary>
        /// TCP调用客户端调用结束
        /// </summary>
        /// <param name="client">TCP调用服务器信息</param>
        /// <param name="returnType">是否回调成功</param>
        protected void _end_(ref clientIdentity client, fastCSharp.net.returnValue.type returnType)
        {
            if (isDisposed == 0)
            {
                if (returnType == fastCSharp.net.returnValue.type.Success)
                {
                    Monitor.Enter(clientLock);
                    callCount -= clients[client.Index].End(client.Identity);
                    Monitor.Exit(clientLock);
                }
                else
                {
                    Monitor.Enter(clientLock);
                    keyValue <clientType, keyValue <host, int> > errorClient = clients[client.Index].Error(client.Identity);
                    if (errorClient.Key == null)
                    {
                        Monitor.Exit(clientLock);
                    }
                    else
                    {
                        callCount -= errorClient.Value.Value;
                        try
                        {
                            freeIndexs.Add(client.Index);
                        }
                        finally
                        {
                            Monitor.Exit(clientLock);
                            pub.Dispose(ref errorClient.Key);

                            host host     = errorClient.Value.Key;
                            bool isCreate = newServer(ref host);
                            if (isCreate)
                            {
                                tryCheck();
                                log.Default.Add("恢复TCP调用服务端[调用错误] " + host.Host + ":" + host.Port.toString(), new System.Diagnostics.StackFrame(), false);
                            }
                            else
                            {
                                log.Default.Add("移除TCP调用服务端[调用错误] " + host.Host + ":" + host.Port.toString(), new System.Diagnostics.StackFrame(), false);
                            }
                        }
                    }
                }
            }
            client.Identity = int.MinValue;
            client.Client   = null;
        }