diff --git a/relay/cref.cpp b/relay/cref.cpp index 98b80169d..6fe5b1e01 100644 --- a/relay/cref.cpp +++ b/relay/cref.cpp @@ -780,8 +780,8 @@ CookieRef::noteHeartbeat( const CRefEvent* evt ) assert( iter->second.m_socket == socket ); logf( XW_LOGVERBOSE1, "upping m_lastHeartbeat from %d to %d", - iter->second.m_lastHeartbeat, now() ); - iter->second.m_lastHeartbeat = now(); + iter->second.m_lastHeartbeat, uptime() ); + iter->second.m_lastHeartbeat = uptime(); } } /* noteHeartbeat */ @@ -856,7 +856,7 @@ CookieRef::_PrintCookieInfo( string& out ) /* open since when */ snprintf( buf, sizeof(buf), "Hosts connected=%d; cur time = %ld\n", - m_sockets.size(), now() ); + m_sockets.size(), uptime() ); out += buf; map::iterator iter = m_sockets.begin(); while ( iter != m_sockets.end() ) { diff --git a/relay/cref.h b/relay/cref.h index 1828df29f..a466ec4ac 100644 --- a/relay/cref.h +++ b/relay/cref.h @@ -41,7 +41,7 @@ class HostRec { : m_socket(socket) , m_nPlayersH(nPlayersH) , m_nPlayersT(nPlayersT) - , m_lastHeartbeat(now()) + , m_lastHeartbeat(uptime()) {} ~HostRec() {} int m_socket; diff --git a/relay/crefmgr.cpp b/relay/crefmgr.cpp index 72f18bca2..1daebcd45 100644 --- a/relay/crefmgr.cpp +++ b/relay/crefmgr.cpp @@ -413,7 +413,7 @@ CRefMgr::UnlockCref( CookieRef* cref ) CRefMgr::heartbeatProc( void* closure ) { CRefMgr* self = (CRefMgr*)closure; - self->checkHeartbeats( now() ); + self->checkHeartbeats( uptime() ); } /* heartbeatProc */ #endif diff --git a/relay/ctrl.cpp b/relay/ctrl.cpp index 0de23be46..31f598b2e 100644 --- a/relay/ctrl.cpp +++ b/relay/ctrl.cpp @@ -348,7 +348,7 @@ cmd_rev( int socket, const char** args ) void format_uptime( char* buf, int len ) { - time_t seconds = now(); + time_t seconds = uptime(); int days = seconds / (24*60*60); seconds %= (24*60*60); diff --git a/relay/permid.cpp b/relay/permid.cpp index 5bf9647d2..77da4a96a 100644 --- a/relay/permid.cpp +++ b/relay/permid.cpp @@ -29,38 +29,18 @@ using namespace std; pthread_mutex_t PermID::s_guard = PTHREAD_MUTEX_INITIALIZER; string PermID::s_serverName; -string PermID::s_idFileName; +int PermID::s_nextId = 0; +string PermID::s_startTime; string PermID::GetNextUniqueID() { - const char* fileName = s_idFileName.c_str(); MutexLock ml( &s_guard ); - string s = s_serverName; - assert( s.length() > 0 ); - s += ":"; - - char buf[32]; /* should last for a while :-) */ - - FILE* f = fopen( fileName, "r+" ); - if ( f ) { - fscanf( f, "%s\n", buf ); - rewind( f ); - } else { - f = fopen( fileName, "w" ); - assert ( f != NULL ); - buf[0] = '0'; - buf[1] = '\0'; - } - - int n = atoi(buf) + 1; - sprintf( buf, "%d", n ); - - fprintf( f, "%s\n", buf ); - fclose( f ); - - s += buf; + char buf[64]; + snprintf( buf, sizeof(buf), "%s:%s:%d", s_serverName.c_str(), + s_startTime.c_str(), ++s_nextId ); + string s(buf); return s; } @@ -72,7 +52,10 @@ PermID::SetServerName( const char* name ) } /* static */ void -PermID::SetIDFileName( const char* name ) +PermID::SetStartTime( time_t startTime ) { - s_idFileName = name; + char buf[16]; + snprintf( buf, sizeof(buf), "%ld", startTime ); + s_startTime = buf; + logf( XW_LOGINFO, "assigned startTime: %s", s_startTime.c_str() ); } diff --git a/relay/permid.h b/relay/permid.h index 0136c4ad0..43f73a572 100644 --- a/relay/permid.h +++ b/relay/permid.h @@ -34,7 +34,7 @@ class PermID { public: static void SetServerName( const char* name ); - static void SetIDFileName( const char* name ); + static void SetStartTime( time_t startTime ); static std::string GetNextUniqueID(); private: @@ -44,7 +44,8 @@ class PermID { this, which is supposed to be unique to this relay instance. */ - static std::string s_idFileName; /* The incremented part of the - name is stored where? */ -}; + static int s_nextId; /* numeric part of ID */ + static std::string s_startTime; /* allows multiple servers per + host to have uniquie names */ +}; #endif diff --git a/relay/timermgr.cpp b/relay/timermgr.cpp index 69e55f88d..1e7de2c15 100644 --- a/relay/timermgr.cpp +++ b/relay/timermgr.cpp @@ -47,11 +47,11 @@ void TimerMgr::SetTimer( time_t inMillis, TimerProc proc, void* closure, int interval ) { - logf( XW_LOGINFO, "setTimer: now = %d", now() ); + logf( XW_LOGINFO, "setTimer: uptime = %ld", uptime() ); TimerInfo ti; ti.proc = proc; ti.closure = closure; - ti.when = now() + inMillis; + ti.when = uptime() + inMillis; ti.interval = interval; MutexLock ml( &m_timersMutex ); @@ -75,7 +75,7 @@ TimerMgr::GetPollTimeout() if ( tout == 0 ) { tout = -1; } else { - tout -= now(); + tout -= uptime(); if ( tout < 0 ) { tout = 0; } @@ -103,7 +103,7 @@ TimerMgr::figureNextFire() { /* Don't call this unless have the lock!!! */ time_t t = 0x7FFFFFFF; - time_t cur = now(); + time_t cur = uptime(); list::iterator iter = m_timers.begin(); @@ -141,7 +141,7 @@ TimerMgr::FireElapsedTimers() { pthread_mutex_lock( &m_timersMutex ); - time_t curTime = now(); + time_t curTime = uptime(); vector procs; vector closures; diff --git a/relay/xwrelay.conf b/relay/xwrelay.conf index c6b5d94ea..4690a8fad 100644 --- a/relay/xwrelay.conf +++ b/relay/xwrelay.conf @@ -12,7 +12,7 @@ HEARTBEAT=60 ALLCONN=300 # How many worker threads in the thread pool? Default is five. -NTHREADS=5 +NTHREADS=1 # What port do we listen on for incomming connections? PORTS=10997,10998,10999 @@ -32,10 +32,6 @@ WWW_REFRESH_SECS=30 # create game ids guaranteed to be unique SERVERNAME=eehouse.org -# Where will the file live that stores the last ID used for a new -# connName. -IDFILE=./xwrelay_id.txt - # Initial level of logging. See xwrelay_priv.h for values. Currently # 0 means errors only, 1 info, 2 verbose and 3 very verbose. LOGLEVEL=2 diff --git a/relay/xwrelay.cpp b/relay/xwrelay.cpp index ed4c7bcad..189d9ca64 100644 --- a/relay/xwrelay.cpp +++ b/relay/xwrelay.cpp @@ -360,7 +360,7 @@ killSocket( int socket, const char* why ) } time_t -now( void ) +uptime( void ) { static time_t startTime = time(NULL); return time(NULL) - startTime; @@ -563,7 +563,7 @@ main( int argc, char** argv ) bool doDaemon = true; bool doFork = true; - (void)now(); /* force capture of start time */ + (void)uptime(); /* force capture of start time */ /* Verify sizes here... */ assert( sizeof(CookieID) == 2 ); @@ -651,15 +651,8 @@ main( int argc, char** argv ) } } - char idFileNameBuf[128]; - if ( idFileName == NULL ) { - if ( cfg->GetValueFor( "IDFILE", idFileNameBuf, sizeof(idFileName) ) ) { - idFileName = idFileNameBuf; - } - } - PermID::SetServerName( serverName ); - PermID::SetIDFileName( idFileName ); + PermID::SetStartTime( time(NULL) ); /* add signal handling here */ diff --git a/relay/xwrelay_priv.h b/relay/xwrelay_priv.h index 4d4f30990..7dbbf7ba8 100644 --- a/relay/xwrelay_priv.h +++ b/relay/xwrelay_priv.h @@ -21,7 +21,7 @@ void killSocket( int socket, const char* why ); bool send_with_length_unsafe( int socket, unsigned char* buf, int bufLen ); -time_t now(void); +time_t uptime(void); int make_socket( unsigned long addr, unsigned short port );