mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-29 08:34:37 +01:00
fix leak; move heartbeat timer into crefmgr, and only run it when
there are active crefs.
This commit is contained in:
parent
1ad46f9b33
commit
2a0bc3c2de
3 changed files with 28 additions and 13 deletions
|
@ -25,6 +25,8 @@
|
|||
#include "cref.h"
|
||||
#include "mlock.h"
|
||||
#include "permid.h"
|
||||
#include "configs.h"
|
||||
#include "timermgr.h"
|
||||
|
||||
class SocketStuff {
|
||||
public:
|
||||
|
@ -314,6 +316,13 @@ CRefMgr::UnlockCref( CookieRef* cref )
|
|||
pthread_mutex_unlock( cref_mutex );
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
CRefMgr::heartbeatProc( void* closure )
|
||||
{
|
||||
CRefMgr* self = (CRefMgr*)closure;
|
||||
self->checkHeartbeats( now() );
|
||||
} /* heartbeatProc */
|
||||
|
||||
CookieRef*
|
||||
CRefMgr::AddNew( const char* cookie, const char* connName, CookieID id )
|
||||
{
|
||||
|
@ -326,6 +335,14 @@ CRefMgr::AddNew( const char* cookie, const char* connName, CookieID id )
|
|||
m_cookieMap.insert( pair<CookieID, CookieRef*>(ref->GetCookieID(), ref ) );
|
||||
logf( XW_LOGINFO, "paired cookie %s/connName %s with id %d",
|
||||
(cookie?cookie:"NULL"), connName, ref->GetCookieID() );
|
||||
|
||||
if ( m_cookieMap.size() == 1 ) {
|
||||
RelayConfigs* cfg = RelayConfigs::GetConfigs();
|
||||
short heartbeat = cfg->GetHeartbeatInterval();
|
||||
TimerMgr::GetTimerMgr()->SetTimer( heartbeat, heartbeatProc, this,
|
||||
heartbeat );
|
||||
}
|
||||
|
||||
return ref;
|
||||
} /* AddNew */
|
||||
|
||||
|
@ -354,6 +371,12 @@ CRefMgr::Delete( CookieRef* cref )
|
|||
iter2 = m_crefMutexes.find(cref);
|
||||
m_crefMutexes.erase( iter2 );
|
||||
|
||||
delete cref;
|
||||
|
||||
if ( m_cookieMap.size() == 0 ) {
|
||||
TimerMgr::GetTimerMgr()->ClearTimer( heartbeatProc, this );
|
||||
}
|
||||
|
||||
logf( XW_LOGINFO, "CRefMgr::Delete done" );
|
||||
}
|
||||
|
||||
|
@ -392,7 +415,7 @@ CRefMgr::getCookieRef_impl( CookieID cookieID )
|
|||
}
|
||||
|
||||
void
|
||||
CRefMgr::CheckHeartbeats( time_t now )
|
||||
CRefMgr::checkHeartbeats( time_t now )
|
||||
{
|
||||
vector<CookieRef*> crefs;
|
||||
|
||||
|
@ -410,7 +433,7 @@ CRefMgr::CheckHeartbeats( time_t now )
|
|||
SafeCref scr( crefs[i] );
|
||||
scr.CheckHeartbeats( now );
|
||||
}
|
||||
} /* CheckHeartbeats */
|
||||
} /* checkHeartbeats */
|
||||
|
||||
/* static */ CookieMapIterator
|
||||
CRefMgr::GetCookieIterator()
|
||||
|
|
|
@ -57,7 +57,6 @@ class CRefMgr {
|
|||
CookieMapIterator GetCookieIterator();
|
||||
|
||||
/* PENDING. These need to go through SafeCref */
|
||||
void CheckHeartbeats( time_t now );
|
||||
void Delete( CookieID id );
|
||||
void Delete( CookieRef* cref );
|
||||
void Delete( const char* connName );
|
||||
|
@ -91,6 +90,9 @@ class CRefMgr {
|
|||
CookieID cookieIDForConnName( const char* connName );
|
||||
CookieID nextCID( const char* connName );
|
||||
|
||||
static void heartbeatProc( void* closure );
|
||||
void checkHeartbeats( time_t now );
|
||||
|
||||
CookieID m_nextCID;
|
||||
|
||||
int LockCref( CookieRef* cref );
|
||||
|
|
|
@ -387,12 +387,6 @@ make_socket( unsigned long addr, unsigned short port )
|
|||
return sock;
|
||||
} /* make_socket */
|
||||
|
||||
static void
|
||||
HeartbeatProc( void* closure )
|
||||
{
|
||||
CRefMgr::Get()->CheckHeartbeats( now() );
|
||||
} /* HeartbeatProc */
|
||||
|
||||
enum { FLAG_HELP
|
||||
,FLAG_CONFFILE
|
||||
,FLAG_PORT
|
||||
|
@ -534,10 +528,6 @@ int main( int argc, char** argv )
|
|||
XWThreadPool* tPool = XWThreadPool::GetTPool();
|
||||
tPool->Setup( nWorkerThreads, processMessage );
|
||||
|
||||
short heartbeat = cfg->GetHeartbeatInterval();
|
||||
TimerMgr::GetTimerMgr()->SetTimer( heartbeat, HeartbeatProc, NULL,
|
||||
heartbeat );
|
||||
|
||||
/* set up select call */
|
||||
fd_set rfds;
|
||||
for ( ; ; ) {
|
||||
|
|
Loading…
Add table
Reference in a new issue