mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-11 08:48:06 +01:00
rename now() as uptime(); drop NTHREADS to 1 for now; include time of
server boot in connName and keep counter in memory rather than a file.
This commit is contained in:
parent
f9e6c5631d
commit
fbe95478ba
10 changed files with 32 additions and 59 deletions
|
@ -780,8 +780,8 @@ CookieRef::noteHeartbeat( const CRefEvent* evt )
|
||||||
assert( iter->second.m_socket == socket );
|
assert( iter->second.m_socket == socket );
|
||||||
|
|
||||||
logf( XW_LOGVERBOSE1, "upping m_lastHeartbeat from %d to %d",
|
logf( XW_LOGVERBOSE1, "upping m_lastHeartbeat from %d to %d",
|
||||||
iter->second.m_lastHeartbeat, now() );
|
iter->second.m_lastHeartbeat, uptime() );
|
||||||
iter->second.m_lastHeartbeat = now();
|
iter->second.m_lastHeartbeat = uptime();
|
||||||
}
|
}
|
||||||
} /* noteHeartbeat */
|
} /* noteHeartbeat */
|
||||||
|
|
||||||
|
@ -856,7 +856,7 @@ CookieRef::_PrintCookieInfo( string& out )
|
||||||
/* open since when */
|
/* open since when */
|
||||||
|
|
||||||
snprintf( buf, sizeof(buf), "Hosts connected=%d; cur time = %ld\n",
|
snprintf( buf, sizeof(buf), "Hosts connected=%d; cur time = %ld\n",
|
||||||
m_sockets.size(), now() );
|
m_sockets.size(), uptime() );
|
||||||
out += buf;
|
out += buf;
|
||||||
map<HostID,HostRec>::iterator iter = m_sockets.begin();
|
map<HostID,HostRec>::iterator iter = m_sockets.begin();
|
||||||
while ( iter != m_sockets.end() ) {
|
while ( iter != m_sockets.end() ) {
|
||||||
|
|
|
@ -41,7 +41,7 @@ class HostRec {
|
||||||
: m_socket(socket)
|
: m_socket(socket)
|
||||||
, m_nPlayersH(nPlayersH)
|
, m_nPlayersH(nPlayersH)
|
||||||
, m_nPlayersT(nPlayersT)
|
, m_nPlayersT(nPlayersT)
|
||||||
, m_lastHeartbeat(now())
|
, m_lastHeartbeat(uptime())
|
||||||
{}
|
{}
|
||||||
~HostRec() {}
|
~HostRec() {}
|
||||||
int m_socket;
|
int m_socket;
|
||||||
|
|
|
@ -413,7 +413,7 @@ CRefMgr::UnlockCref( CookieRef* cref )
|
||||||
CRefMgr::heartbeatProc( void* closure )
|
CRefMgr::heartbeatProc( void* closure )
|
||||||
{
|
{
|
||||||
CRefMgr* self = (CRefMgr*)closure;
|
CRefMgr* self = (CRefMgr*)closure;
|
||||||
self->checkHeartbeats( now() );
|
self->checkHeartbeats( uptime() );
|
||||||
} /* heartbeatProc */
|
} /* heartbeatProc */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -348,7 +348,7 @@ cmd_rev( int socket, const char** args )
|
||||||
void
|
void
|
||||||
format_uptime( char* buf, int len )
|
format_uptime( char* buf, int len )
|
||||||
{
|
{
|
||||||
time_t seconds = now();
|
time_t seconds = uptime();
|
||||||
|
|
||||||
int days = seconds / (24*60*60);
|
int days = seconds / (24*60*60);
|
||||||
seconds %= (24*60*60);
|
seconds %= (24*60*60);
|
||||||
|
|
|
@ -29,38 +29,18 @@ using namespace std;
|
||||||
|
|
||||||
pthread_mutex_t PermID::s_guard = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t PermID::s_guard = PTHREAD_MUTEX_INITIALIZER;
|
||||||
string PermID::s_serverName;
|
string PermID::s_serverName;
|
||||||
string PermID::s_idFileName;
|
int PermID::s_nextId = 0;
|
||||||
|
string PermID::s_startTime;
|
||||||
|
|
||||||
string
|
string
|
||||||
PermID::GetNextUniqueID()
|
PermID::GetNextUniqueID()
|
||||||
{
|
{
|
||||||
const char* fileName = s_idFileName.c_str();
|
|
||||||
MutexLock ml( &s_guard );
|
MutexLock ml( &s_guard );
|
||||||
|
|
||||||
string s = s_serverName;
|
char buf[64];
|
||||||
assert( s.length() > 0 );
|
snprintf( buf, sizeof(buf), "%s:%s:%d", s_serverName.c_str(),
|
||||||
s += ":";
|
s_startTime.c_str(), ++s_nextId );
|
||||||
|
string s(buf);
|
||||||
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;
|
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
@ -72,7 +52,10 @@ PermID::SetServerName( const char* name )
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ void
|
/* 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() );
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
class PermID {
|
class PermID {
|
||||||
public:
|
public:
|
||||||
static void SetServerName( const char* name );
|
static void SetServerName( const char* name );
|
||||||
static void SetIDFileName( const char* name );
|
static void SetStartTime( time_t startTime );
|
||||||
static std::string GetNextUniqueID();
|
static std::string GetNextUniqueID();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -44,7 +44,8 @@ class PermID {
|
||||||
this, which is supposed to be
|
this, which is supposed to be
|
||||||
unique to this relay
|
unique to this relay
|
||||||
instance. */
|
instance. */
|
||||||
static std::string s_idFileName; /* The incremented part of the
|
static int s_nextId; /* numeric part of ID */
|
||||||
name is stored where? */
|
static std::string s_startTime; /* allows multiple servers per
|
||||||
|
host to have uniquie names */
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -47,11 +47,11 @@ void
|
||||||
TimerMgr::SetTimer( time_t inMillis, TimerProc proc, void* closure,
|
TimerMgr::SetTimer( time_t inMillis, TimerProc proc, void* closure,
|
||||||
int interval )
|
int interval )
|
||||||
{
|
{
|
||||||
logf( XW_LOGINFO, "setTimer: now = %d", now() );
|
logf( XW_LOGINFO, "setTimer: uptime = %ld", uptime() );
|
||||||
TimerInfo ti;
|
TimerInfo ti;
|
||||||
ti.proc = proc;
|
ti.proc = proc;
|
||||||
ti.closure = closure;
|
ti.closure = closure;
|
||||||
ti.when = now() + inMillis;
|
ti.when = uptime() + inMillis;
|
||||||
ti.interval = interval;
|
ti.interval = interval;
|
||||||
|
|
||||||
MutexLock ml( &m_timersMutex );
|
MutexLock ml( &m_timersMutex );
|
||||||
|
@ -75,7 +75,7 @@ TimerMgr::GetPollTimeout()
|
||||||
if ( tout == 0 ) {
|
if ( tout == 0 ) {
|
||||||
tout = -1;
|
tout = -1;
|
||||||
} else {
|
} else {
|
||||||
tout -= now();
|
tout -= uptime();
|
||||||
if ( tout < 0 ) {
|
if ( tout < 0 ) {
|
||||||
tout = 0;
|
tout = 0;
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ TimerMgr::figureNextFire()
|
||||||
{
|
{
|
||||||
/* Don't call this unless have the lock!!! */
|
/* Don't call this unless have the lock!!! */
|
||||||
time_t t = 0x7FFFFFFF;
|
time_t t = 0x7FFFFFFF;
|
||||||
time_t cur = now();
|
time_t cur = uptime();
|
||||||
|
|
||||||
list<TimerInfo>::iterator iter = m_timers.begin();
|
list<TimerInfo>::iterator iter = m_timers.begin();
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ TimerMgr::FireElapsedTimers()
|
||||||
{
|
{
|
||||||
pthread_mutex_lock( &m_timersMutex );
|
pthread_mutex_lock( &m_timersMutex );
|
||||||
|
|
||||||
time_t curTime = now();
|
time_t curTime = uptime();
|
||||||
|
|
||||||
vector<TimerProc> procs;
|
vector<TimerProc> procs;
|
||||||
vector<void*> closures;
|
vector<void*> closures;
|
||||||
|
|
|
@ -12,7 +12,7 @@ HEARTBEAT=60
|
||||||
ALLCONN=300
|
ALLCONN=300
|
||||||
|
|
||||||
# How many worker threads in the thread pool? Default is five.
|
# How many worker threads in the thread pool? Default is five.
|
||||||
NTHREADS=5
|
NTHREADS=1
|
||||||
|
|
||||||
# What port do we listen on for incomming connections?
|
# What port do we listen on for incomming connections?
|
||||||
PORTS=10997,10998,10999
|
PORTS=10997,10998,10999
|
||||||
|
@ -32,10 +32,6 @@ WWW_REFRESH_SECS=30
|
||||||
# create game ids guaranteed to be unique
|
# create game ids guaranteed to be unique
|
||||||
SERVERNAME=eehouse.org
|
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
|
# Initial level of logging. See xwrelay_priv.h for values. Currently
|
||||||
# 0 means errors only, 1 info, 2 verbose and 3 very verbose.
|
# 0 means errors only, 1 info, 2 verbose and 3 very verbose.
|
||||||
LOGLEVEL=2
|
LOGLEVEL=2
|
||||||
|
|
|
@ -360,7 +360,7 @@ killSocket( int socket, const char* why )
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t
|
time_t
|
||||||
now( void )
|
uptime( void )
|
||||||
{
|
{
|
||||||
static time_t startTime = time(NULL);
|
static time_t startTime = time(NULL);
|
||||||
return time(NULL) - startTime;
|
return time(NULL) - startTime;
|
||||||
|
@ -563,7 +563,7 @@ main( int argc, char** argv )
|
||||||
bool doDaemon = true;
|
bool doDaemon = true;
|
||||||
bool doFork = true;
|
bool doFork = true;
|
||||||
|
|
||||||
(void)now(); /* force capture of start time */
|
(void)uptime(); /* force capture of start time */
|
||||||
|
|
||||||
/* Verify sizes here... */
|
/* Verify sizes here... */
|
||||||
assert( sizeof(CookieID) == 2 );
|
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::SetServerName( serverName );
|
||||||
PermID::SetIDFileName( idFileName );
|
PermID::SetStartTime( time(NULL) );
|
||||||
|
|
||||||
/* add signal handling here */
|
/* add signal handling here */
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ void killSocket( int socket, const char* why );
|
||||||
|
|
||||||
bool send_with_length_unsafe( int socket, unsigned char* buf, int bufLen );
|
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 );
|
int make_socket( unsigned long addr, unsigned short port );
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue