void ConnectionPool::Execute() { while(!m_stopDesired) { time_t nowTime = time(NULL); if(!m_conf_lua_file.empty() && nowTime >= m_nextLoadTime) { time_t lastModify = JG_F::KFileUtil::GetLastModified(m_conf_lua_file.c_str()); if(lastModify != m_lastModifiedTime) { PoolSettings::ConnectionSettingArray cpy(m_settings.m_settings); if(!m_settings.reload(m_conf_lua_file.c_str())) { Log(LOG_WARN, "warn: fail reload pool setting file '%s', recover", m_conf_lua_file.c_str()); m_settings.m_settings = cpy; } m_lastModifiedTime = lastModify; } m_nextLoadTime = nowTime + 10; } if(nowTime > m_nextCheckIdleTime) { JG_S::KAutoThreadMutex mx(m_mx); ConnectionMap::iterator it = m_cnnMap.begin(), ite = m_cnnMap.end(); for(; it != ite; it++) { ConnectionList tmp; ConnectionList& lst = it->second; PooledConnection* cnn; while(cnn = lst.pop_front()) { if(cnn->isExpire(nowTime)) { Log(LOG_DEBUG, "debug: %s expire, abandon", cnn->toString().c_str()); cnn->destroy(); } else { tmp.push_back(cnn); } } while(cnn = tmp.pop_front()) { lst.push_back(cnn); } } m_nextCheckIdleTime = nowTime + 30; } msleep(100); } }
// Start listening for a specific RHS user function. When it fires we'll call to the client // (over the connection) to implement it. void RhsListener::AddRhsListener(char const* pFunctionName, Connection* pConnection) { RhsMapIter mapIter = m_RhsMap.find(pFunctionName) ; ConnectionList* pList = NULL ; // Either create a new list or retrieve the existing list of listeners if (mapIter == m_RhsMap.end()) { pList = new ConnectionList() ; m_RhsMap[pFunctionName] = pList ; } else { pList = mapIter->second ; } pList->push_back(pConnection) ; }
ConnectionList CNullNetworkManager::GetConnections() { ConnectionList list; list.push_back(CConnectionPtr(new CNullConnection())); return list; }