void SipUdpServer::printStatus() { SipClient* pServer = NULL; UtlHashMapIterator iterator(mServers); UtlVoidPtr* pServerContainer = NULL; UtlString* pKey = NULL; while (pKey = (UtlString*)iterator()) { pServerContainer = (UtlVoidPtr*) iterator.value(); if (pServerContainer) { pServer = (SipClient*)pServerContainer->getValue(); } if (pServer) { UtlString clientNames; long clientTouchedTime = pServer->getLastTouchedTime(); UtlBoolean clientOk = pServer->isOk(); pServer->getClientNames(clientNames); osPrintf("UDP server %p last used: %ld ok: %d names: \n%s \n", this, clientTouchedTime, clientOk, clientNames.data()); SipProtocolServerBase::printStatus(); } } }
void SipProtocolServerBase::printStatus() { int numClients = mClientList.getCount(); int iteratorHandle = mClientList.getIteratorHandle(); OsTime time; OsDateTime::getCurTimeSinceBoot(time); long currentTime = time.seconds(); //long currentTime = OsDateTime::getSecsSinceEpoch(); SipClient* client; UtlString clientNames; long clientTouchedTime; UtlBoolean clientOk; osPrintf("%s %d clients in list at: %ld\n", mProtocolString.data(), numClients, currentTime); while ((client = (SipClient*)mClientList.next(iteratorHandle))) { // Remove this or any other bad client clientTouchedTime = client->getLastTouchedTime(); clientOk = client->isOk(); client->getClientNames(clientNames); osPrintf("%s client %p last used: %ld ok: %d names:\n%s\n", mProtocolString.data(), this, clientTouchedTime, clientOk, clientNames.data()); } mClientList.releaseIteratorHandle(iteratorHandle); }
SipClient* SipProtocolServerBase::getClient(const char* hostAddress, int hostPort, const char* localIp) { UtlBoolean isSameHost = FALSE; UtlString hostAddressString(hostAddress ? hostAddress : ""); int iteratorHandle = mClientList.getIteratorHandle(); SipClient* client = NULL; # if TEST_CLIENT_CREATION OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipProtocolServerBase::getClient( %s, %d )", hostAddress, hostPort); # endif while ((client = (SipClient*)mClientList.next(iteratorHandle))) { // Are these the same host? isSameHost = client->isConnectedTo(hostAddressString, hostPort); if(isSameHost && client->isOk() && 0 == strcmp(client->getLocalIp(), localIp)) { break; } else if(isSameHost) { if(!client->isOk()) { OsSysLog::add(FAC_SIP, PRI_DEBUG, "%s Client matches but is not OK", mProtocolString.data()); } } } mClientList.releaseIteratorHandle(iteratorHandle); # ifdef TEST_CLIENT_CREATION if (!client) { OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipProtocolServerBase::getClient( %s, %d ) NOT FOUND", hostAddress, hostPort); } # endif return(client); }
void SipUdpServer::printStatus() { UtlHashMapIterator iterator(mServers); UtlString* pKey = NULL; while ((pKey = dynamic_cast <UtlString*> (iterator()))) { SipClient* pServer = dynamic_cast <SipClient*> (iterator.value()); UtlString clientNames; long clientTouchedTime = pServer->getLastTouchedTime(); UtlBoolean clientOk = pServer->isOk(); pServer->getClientNames(clientNames); osPrintf("UDP server %p last used: %ld ok: %d names: \n%s \n", this, clientTouchedTime, clientOk, clientNames.data()); SipProtocolServerBase::printStatus(); } }
UtlBoolean SipProtocolServerBase::isOk() { UtlBoolean bRet = true; SipClient* pServer = NULL; UtlHashMapIterator iterator(mServers); UtlVoidPtr* pServerContainer = NULL; UtlString* pKey = NULL; while ((pKey = (UtlString*)iterator())) { pServerContainer = (UtlVoidPtr*)iterator.value(); if (pServerContainer) { pServer = (SipClient*)pServerContainer->getValue(); } if (pServer) { bRet = bRet && pServer->isOk(); } } return bRet; }
void SipProtocolServerBase::removeOldClients(long oldTime) { mClientLock.acquireWrite(); // Find the old clients in the list and shut them down int iteratorHandle = mClientList.getIteratorHandle(); SipClient* client; int numClients = mClientList.getCount(); int numDelete = 0; int numBusy = 0; SipClient** deleteClientArray = NULL; UtlString clientNames; while ((client = (SipClient*)mClientList.next(iteratorHandle))) { if(client->isInUseForWrite()) numBusy++; // Remove any client with a bad socket // With TCP clients let them stay around if they are still // good as the may stay open for the session // The clients opened from this side for sending requests // get closed by the server (i.e. other side). The clients // opened as servers for requests from the remote side are // explicitly closed on this side when the final response is // sent. if( ! client->isInUseForWrite() // can't remove it if writing to it... && ( ! client->isOk() // socket is bad || client->getLastTouchedTime() < oldTime // idle for long enough ) ) { client->getClientNames(clientNames); #ifdef TEST_PRINT osPrintf("Removing %s client names:\n%s\r\n", mProtocolString.data(), clientNames.data()); #endif OsSysLog::add(FAC_SIP, PRI_DEBUG, "Sip%sServer::Removing old client %p:\n%s\r", mProtocolString.data(), client, clientNames.data()); mClientList.remove(iteratorHandle); // Delete the clients after releasing the lock if(!deleteClientArray) deleteClientArray = new SipClient*[numClients]; deleteClientArray[numDelete] = client; numDelete++; client = NULL; } else { # ifdef TEST_PRINT UtlString names; client->getClientNames(names); OsSysLog::add(FAC_SIP, PRI_DEBUG, "Sip%sServer::removeOldClients leaving client:\n%s", mProtocolString.data(), names.data()); # endif } } mClientList.releaseIteratorHandle(iteratorHandle); mClientLock.releaseWrite(); if ( numDelete || numBusy ) // get rid of lots of 'doing nothing when nothing to do' messages in the log { OsSysLog::add(FAC_SIP, PRI_DEBUG, "Sip%sServer::removeOldClients deleting %d of %d SipClients (%d busy)", mProtocolString.data(), numDelete, numClients, numBusy); } // These have been removed from the list so delete them // after releasing the locks for(int clientIndex = 0; clientIndex < numDelete; clientIndex++) { delete deleteClientArray[clientIndex]; } if(deleteClientArray) { delete[] deleteClientArray; deleteClientArray = NULL; } }