Пример #1
0
 /// <summary>
 /// TCP服务端轮询
 /// </summary>
 /// <param name="clientId">TCP服务端标识</param>
 /// <param name="onLog">TCP服务注册通知委托</param>
 internal void GetLog(ref ClientId clientId, Func <TcpServer.ReturnValue <Log>, bool> onLog)
 {
     if (clientId.Tick == ticks)
     {
         object arrayLock = clientPool.ArrayLock;
         Monitor.Enter(arrayLock);
         if (clientPool.Array[clientId.Index].Set(clientId.Identity, onLog))
         {
             try
             {
                 foreach (ServerSet serverSet in serverSets.Values)
                 {
                     serverSet.OnLog(onLog);
                 }
                 onLog(Log.RegisterLoaded);
             }
             finally { Monitor.Exit(arrayLock); }
             return;
         }
         Monitor.Exit(arrayLock);
     }
     onLog(Log.ClientError);
 }
Пример #2
0
 private void getLog(ClientId clientId, AutoCSer.Net.TcpServer.ServerCallback <Log> onLog)
 {
     if (clientId.Tick == ticks)
     {
         object arrayLock = clientPool.ArrayLock;
         Monitor.Enter(arrayLock);
         if (clientPool.Array[clientId.Index].Set(clientId.Identity, onLog))
         {
             try
             {
                 foreach (ServerSet serverSet in serverSets.Values)
                 {
                     serverSet.OnLog(onLog);
                 }
                 onLog.Callback(Log.RegisterLoaded);
             }
             finally { Monitor.Exit(arrayLock); }
             return;
         }
         Monitor.Exit(arrayLock);
     }
     onLog.Callback(Log.ClientError);
 }
Пример #3
0
        /// <summary>
        /// TCP 客户端套接字初始化处理
        /// </summary>
        /// <param name="parameter"></param>
        private void onNewSocket(TcpServer.ClientSocketEventParameter parameter)
        {
#if NoAutoCSer
            throw new Exception();
#else
            if (parameter.Type == TcpServer.ClientSocketEventParameter.EventType.SetSocket)
            {
                isClientErrorLog = false;
                do
                {
                    try
                    {
                        if (isClientErrorLog)
                        {
                            isClientErrorLog = false;
                            clientId.Tick    = 0;
                        }
                        if (clientId.Tick == 0)
                        {
                            clientId = registerClient.register();
                            if (clientId.Tick != 0)
                            {
                                createWait.Set();
                            }
                        }
                        if (clientId.Tick != 0)
                        {
                            if (logKeep != null)
                            {
                                logKeep.Dispose();
                                logKeep = null;
                            }
                            if (serverSets.Count != 0)
                            {
                                Monitor.Enter(serverSetLock);
                                try
                                {
                                    LeftArray <HashString> removeKeys = new LeftArray <HashString>(serverSets.Count);
                                    foreach (KeyValuePair <HashString, ClientServerSet> serverSet in serverSets)
                                    {
                                        if (serverSet.Value.Clear())
                                        {
                                            removeKeys.Add(serverSet.Key);
                                        }
                                    }
                                    foreach (HashString name in removeKeys)
                                    {
                                        serverSets.Remove(name);
                                    }
                                }
                                finally { Monitor.Exit(serverSetLock); }
                            }
                            isRegisterLoaded = false;
                            if ((logKeep = registerClient.getLog(clientId, logHandle)) != null)
                            {
                                byte isError = 0;
                                foreach (IServer server in servers)
                                {
                                    Monitor.Enter(registerLock);
                                    try
                                    {
                                        ServerInfo serverInfo = server.TcpRegisterInfo;
                                        long       clientTick = clientId.Tick;
                                        if (serverInfo != null && serverInfo.RegisterTick != clientTick)
                                        {
                                            serverInfo.ClientIndex    = clientId.Index;
                                            serverInfo.ClientIdentity = clientId.Identity;
                                            if (registerClient.checkRegister(clientTick, serverInfo).Value)
                                            {
                                                serverInfo.RegisterTick = clientTick;
                                            }
                                            else if (isError == 0)
                                            {
                                                isError = 1;
                                                if (registerClient.checkRegister(clientTick, serverInfo).Value)
                                                {
                                                    serverInfo.RegisterTick = clientTick;
                                                }
                                            }
                                        }
                                    }
                                    catch (Exception error)
                                    {
                                        isError = 1;
                                        server.AddLog(error);
                                    }
                                    finally { Monitor.Exit(registerLock); }
                                }
                                return;
                            }
                        }
                    }
                    catch (Exception error)
                    {
                        registerClient._TcpClient_.Log.Add(AutoCSer.Log.LogType.Debug, error, null, true);
                    }
                    Thread.Sleep(registerClient._TcpClient_.TryCreateSleep);
                }while (registerClient._TcpClient_.IsDisposed == 0);
            }
#endif
        }
Пример #4
0
 private void getLog(ClientId clientId, Func <TcpServer.ReturnValue <Log>, bool> onLog)
 {
     Server.GetLog(ref clientId, onLog);
 }