示例#1
0
 internal void AddClient(commandClient client)
 {
     if (Clients == null)
     {
         Clients = new list <commandClient>(sizeof(int));
     }
     Clients.Add(client);
     client.ChangeTcpRegisterServicesVersion();
 }
            public commandClient(fastCSharp.code.cSharp.tcpServer attribute, fastCSharp.code.cSharp.tcpBase.ITcpClientVerifyMethod <commandClient> verifyMethod)
#endif
            {
                if (attribute == null)
                {
                    log.Error.Throw(log.exceptionType.Null);
                }
                client = new commandClient <commandClient>(attribute, 1024, verifyMethod ?? new verifyMethod(), this);
            }
示例#3
0
            /// <summary>
            /// 删除TCP调用客户端
            /// </summary>
            /// <param name="commandClient">TCP调用客户端</param>
            internal void Remove(commandClient commandClient)
            {
                services services = commandClient.TcpRegisterServices;

                if (services != null)
                {
                    commandClient.TcpRegisterServices = null;
                    Monitor.Enter(servicesLock);
                    services.RemoveClient(commandClient);
                    Monitor.Exit(servicesLock);
                }
            }
示例#4
0
 /// <summary>
 /// 获取TCP服务端口信息
 /// </summary>
 /// <param name="commandClient">TCP调用客户端</param>
 /// <returns>是否更新</returns>
 internal bool GetHost(commandClient commandClient)
 {
     fastCSharp.code.cSharp.tcpServer attribute = commandClient.Attribute;
     if (attribute != null)
     {
         //commandClient.TcpRegisterServicesVersion = Version;
         if (Hosts.Length == 0)
         {
             attribute.Port = 0;
             if (errorServiceName != attribute.ServiceName)
             {
                 fastCSharp.log.Error.Add(attribute.ServiceName + "[" + attribute.TcpRegisterName + "] 未找到注册服务信息", new System.Diagnostics.StackFrame(), false);
             }
             errorServiceName = attribute.ServiceName;
         }
         else
         {
             if (errorServiceName == attribute.ServiceName)
             {
                 errorServiceName = null;
             }
             host host;
             int  index = hostIndex;
             if (index < Hosts.Length)
             {
                 ++hostIndex;
                 host = Hosts[index];
             }
             else
             {
                 hostIndex = 1;
                 host      = Hosts[0];
             }
             if (attribute.IsFixedClientHost)
             {
                 if (attribute.Port != host.Port)
                 {
                     attribute.Port = host.Port;
                 }
             }
             else if (attribute.Host != host.Host || attribute.Port != host.Port)
             {
                 attribute.Host = host.Host;
                 attribute.Port = host.Port;
             }
         }
         return(true);
     }
     return(false);
 }
示例#5
0
            /// <summary>
            /// 获取TCP服务端口信息
            /// </summary>
            /// <param name="commandClient">TCP调用客户端</param>
            /// <returns>TCP服务端口信息是否更新</returns>
            internal bool GetHost(commandClient commandClient)
            {
                services services = commandClient.TcpRegisterServices;

                if (services == null)
                {
                    fastCSharp.code.cSharp.tcpServer attribute = commandClient.Attribute;
                    attribute.Port = 0;
                    return(false);
                }
                Monitor.Enter(servicesLock);
                bool isHost = services.GetHost(commandClient);

                Monitor.Exit(servicesLock);
                return(isHost);
            }
示例#6
0
            /// <summary>
            /// 绑定TCP调用客户端
            /// </summary>
            /// <param name="commandClient">TCP调用客户端</param>
            public void Register(commandClient commandClient)
            {
                hashString name = commandClient.ServiceName;

                Monitor.Enter(servicesLock);
                try
                {
                    if (!this.services.TryGetValue(name, out commandClient.TcpRegisterServices))
                    {
                        services.Add(name, commandClient.TcpRegisterServices = new services {
                            Hosts = nullValue <host> .Array
                        });
                    }
                    commandClient.TcpRegisterServices.AddClient(commandClient);
                }
                finally { Monitor.Exit(servicesLock); }
            }
示例#7
0
 /// <summary>
 /// 删除TCP调用客户端
 /// </summary>
 /// <param name="removeClient">TCP调用客户端</param>
 internal void RemoveClient(commandClient removeClient)
 {
     if (Clients != null && Clients.length != 0)
     {
         int             count       = Clients.length;
         commandClient[] clientArray = Clients.array;
         foreach (commandClient client in clientArray)
         {
             if (client == removeClient)
             {
                 count = Clients.length - count;
                 Clients.UnsafeAddLength(-1);
                 clientArray[count]          = clientArray[Clients.length];
                 clientArray[Clients.length] = null;
                 return;
             }
             if (--count == 0)
             {
                 break;
             }
         }
     }
 }