private void OnListen() { ModuleProc PROC = new ModuleProc(this.DYN_MODULE_NAME, "OnListen"); try { while (!_executorService.WaitForShutdown(100)) { try { IAsyncResult acceptAsync = _socket.BeginAccept(null, null); int waitIndex = _executorService.WaitAny(acceptAsync.AsyncWaitHandle, -1); if (waitIndex == 0) { break; } Socket clientSocket = _socket.EndAccept(acceptAsync); INetSocketHandler client = new TcpSocketServerClient(clientSocket); int hashcode = client.GetHashCode(); if (_hasThreads) { if (_totalThreads != -1) { int threadIndex = (hashcode % _totalThreads); ClientsInfo ci = null; if (_clients.ContainsKey(threadIndex)) { ci = _clients[threadIndex]; } else { ci = new ClientsInfo(threadIndex); _clients.Add(threadIndex, ci); _pool.QueueWorkerItem(ci); } Log.InfoV(PROC, "Client [{0}] was connected at Thread {1:D}", client.ToString(), threadIndex); ci.AddClient(client); } else { } } this.OnClientConnected(client); } catch (Exception ex) { Log.Exception(PROC, ex); } } } catch (Exception ex) { Log.Exception(PROC, ex); } }
private void OnListen() { ModuleProc PROC = new ModuleProc(this.DYN_MODULE_NAME, "OnListen"); try { while (!_executorService.WaitForShutdown(100)) { try { IAsyncResult acceptAsync = _socket.BeginAccept(null, null); int waitIndex = _executorService.WaitAny(acceptAsync.AsyncWaitHandle, -1); if (waitIndex == 0) break; Socket clientSocket = _socket.EndAccept(acceptAsync); INetSocketHandler client = new TcpSocketServerClient(clientSocket); int hashcode = client.GetHashCode(); if (_hasThreads) { if (_totalThreads != -1) { int threadIndex = (hashcode % _totalThreads); ClientsInfo ci = null; if (_clients.ContainsKey(threadIndex)) { ci = _clients[threadIndex]; } else { ci = new ClientsInfo(threadIndex); _clients.Add(threadIndex, ci); _pool.QueueWorkerItem(ci); } Log.InfoV(PROC, "Client [{0}] was connected at Thread {1:D}", client.ToString(), threadIndex); ci.AddClient(client); } else { } } this.OnClientConnected(client); } catch (Exception ex) { Log.Exception(PROC, ex); } } } catch (Exception ex) { Log.Exception(PROC, ex); } }