void Network::DeInit() { LOG(LogVerbose, "Network::DeInit: Closing down."); PolledTimer timer; // Kill all connections. while(connections.size() > 0) { MessageConnection *connection = *connections.begin(); CloseConnection(connection); // CloseConnection erases connection from the connections list, so this loop terminates. } // Kill the server, if it's running. StopServer(); // Kill all worker threads. while(workerThreads.size() > 0) CloseWorkerThread(workerThreads.front()); // Erases the item from workerThreads, so this loop terminates. // Clean up any sockets that might be remaining. while(sockets.size() > 0) { sockets.front().Close(); sockets.pop_front(); } // Deinitialize network subsystem. #ifdef WIN32 WSACleanup(); #endif LOG(LogWaits, "Network::DeInit: Deinitialized kNet Network object, took %f msecs.", timer.MSecsElapsed()); }
CNetApp::~CNetApp() { CloseRecvThread(); CloseSendThread(); CloseWorkerThread(); if( m_sSocket != INVALID_SOCKET ) { closesocket(m_sSocket); m_sSocket = INVALID_SOCKET; } WSACleanup(); }
void Network::RemoveServerFromItsWorkerThread(NetworkServer *server) { if (!server) return; NetworkWorkerThread *workerThread = server->WorkerThread(); if (workerThread) { workerThread->RemoveServer(server); server->SetWorkerThread(0); if (workerThread->NumConnections() + workerThread->NumServers() == 0) CloseWorkerThread(workerThread); } }
void Network::RemoveConnectionFromItsWorkerThread(MessageConnection *connection) { if (!connection) return; NetworkWorkerThread *workerThread = connection->WorkerThread(); if (workerThread) { workerThread->RemoveConnection(connection); connection->SetWorkerThread(0); if (workerThread->NumConnections() + workerThread->NumServers() == 0) CloseWorkerThread(workerThread); } }