track mtime per host rather than per game -- make it an array in the db.

This commit is contained in:
Eric House 2010-12-01 21:08:22 -08:00
parent e89feb62d8
commit 4bd5553596
4 changed files with 36 additions and 18 deletions

View file

@ -256,6 +256,22 @@ CookieRef::_Shutdown()
handleEvents(); handleEvents();
} /* _Shutdown */ } /* _Shutdown */
HostID
CookieRef::HostForSocket( int sock )
{
HostID hid = -1;
ASSERT_LOCKED();
vector<HostRec>::const_iterator iter;
for ( iter = m_sockets.begin(); iter != m_sockets.end(); ++iter ) {
if ( iter->m_socket == sock ) {
hid = iter->m_hostID;
logf( XW_LOGINFO, "%s: assigning hid of %d", __func__, hid );
break;
}
}
return hid;
}
int int
CookieRef::SocketForHost( HostID dest ) CookieRef::SocketForHost( HostID dest )
{ {
@ -590,9 +606,9 @@ CookieRef::handleEvents()
/* break; */ /* break; */
case XWA_SEND_RERSP: case XWA_SEND_RERSP:
increasePlayerCounts( &evt, true );
sendResponse( &evt, false ); sendResponse( &evt, false );
sendAnyStored( &evt ); sendAnyStored( &evt );
increasePlayerCounts( &evt, true );
postCheckAllHere(); postCheckAllHere();
break; break;
@ -994,7 +1010,7 @@ CookieRef::send_msg( int socket, HostID id, XWRelayMsg msg, XWREASON why,
void void
CookieRef::RecordSent( int nBytes, int socket ) { CookieRef::RecordSent( int nBytes, int socket ) {
m_totalSent += nBytes; m_totalSent += nBytes;
DBMgr::Get()->RecordSent( ConnName(), nBytes ); DBMgr::Get()->RecordSent( ConnName(), HostForSocket(socket), nBytes );
} }
void void

View file

@ -93,6 +93,7 @@ class CookieRef {
int GetHeartbeat() { return m_heatbeat; } int GetHeartbeat() { return m_heatbeat; }
int SocketForHost( HostID dest ); int SocketForHost( HostID dest );
HostID HostForSocket( int sock );
/* connect case */ /* connect case */
bool AlreadyHere( unsigned short seed, int socket ); bool AlreadyHere( unsigned short seed, int socket );

View file

@ -208,10 +208,10 @@ DBMgr::AddDevice( const char* connName, HostID curID, int nToAdd,
assert( newID <= 4 ); assert( newID <= 4 );
const char* fmt = "UPDATE " GAMES_TABLE " SET nPerDevice[%d] = %d," const char* fmt = "UPDATE " GAMES_TABLE " SET nPerDevice[%d] = %d,"
" seeds[%d] = %d, mtime='now'" " seeds[%d] = %d, mtimes[%d]='now'"
" WHERE connName = '%s'"; " WHERE connName = '%s'";
char query[256]; char query[256];
snprintf( query, sizeof(query), fmt, newID, nToAdd, newID, seed, connName ); snprintf( query, sizeof(query), fmt, newID, nToAdd, newID, seed, newID, connName );
logf( XW_LOGINFO, "%s: query: %s", __func__, query ); logf( XW_LOGINFO, "%s: query: %s", __func__, query );
execSql( query ); execSql( query );
@ -223,9 +223,9 @@ bool
DBMgr::RmDevice( const char* connName, HostID hid ) DBMgr::RmDevice( const char* connName, HostID hid )
{ {
const char* fmt = "UPDATE " GAMES_TABLE " SET nPerDevice[%d] = 0, " const char* fmt = "UPDATE " GAMES_TABLE " SET nPerDevice[%d] = 0, "
"seeds[%d] = 0, mtime='now' WHERE connName = '%s'"; "seeds[%d] = 0, mtimes[%d]='now' WHERE connName = '%s'";
char query[256]; char query[256];
snprintf( query, sizeof(query), fmt, hid, hid, connName ); snprintf( query, sizeof(query), fmt, hid, hid, hid, connName );
logf( XW_LOGINFO, "%s: query: %s", __func__, query ); logf( XW_LOGINFO, "%s: query: %s", __func__, query );
return execSql( query ); return execSql( query );
@ -249,8 +249,8 @@ DBMgr::HaveDevice( const char* connName, HostID hid, int seed )
void void
DBMgr::AddCID( const char* const connName, CookieID cid ) DBMgr::AddCID( const char* const connName, CookieID cid )
{ {
const char* fmt = "UPDATE " GAMES_TABLE " SET cid = %d, " const char* fmt = "UPDATE " GAMES_TABLE " SET cid = %d "
" mtime='now' WHERE connName = '%s'"; " WHERE connName = '%s'";
char query[256]; char query[256];
snprintf( query, sizeof(query), fmt, cid, connName ); snprintf( query, sizeof(query), fmt, cid, connName );
logf( XW_LOGINFO, "%s: query: %s", __func__, query ); logf( XW_LOGINFO, "%s: query: %s", __func__, query );
@ -271,16 +271,17 @@ DBMgr::ClearCID( const char* connName )
} }
void void
DBMgr::RecordSent( const char* const connName, int nBytes ) DBMgr::RecordSent( const char* const connName, HostID hid, int nBytes )
{ {
const char* fmt = "UPDATE " GAMES_TABLE " SET" assert( hid >= 0 && hid <= 4 );
" nsent = nsent + %d, mtime = 'now'" const char* fmt = "UPDATE " GAMES_TABLE " SET"
" WHERE connName = '%s'"; " nsent = nsent + %d, mtimes[%d] = 'now'"
char query[256]; " WHERE connName = '%s'";
snprintf( query, sizeof(query), fmt, nBytes, connName ); char query[256];
logf( XW_LOGINFO, "%s: query: %s", __func__, query ); snprintf( query, sizeof(query), fmt, nBytes, hid, connName );
logf( XW_LOGINFO, "%s: query: %s", __func__, query );
execSql( query ); execSql( query );
} }
void void

View file

@ -52,9 +52,9 @@ class DBMgr {
int nToAdd, unsigned short seed ); int nToAdd, unsigned short seed );
bool RmDevice( const char* const connName, HostID id ); bool RmDevice( const char* const connName, HostID id );
bool HaveDevice( const char* const connName, HostID id, int seed ); bool HaveDevice( const char* const connName, HostID id, int seed );
void AddCID( const char* connName, CookieID cid ); void AddCID( const char* const connName, CookieID cid );
void ClearCID( const char* connName ); void ClearCID( const char* connName );
void RecordSent( const char* const connName, int nBytes ); void RecordSent( const char* const connName, HostID hid, int nBytes );
void GetPlayerCounts( const char* const connName, int* nTotal, void GetPlayerCounts( const char* const connName, int* nTotal,
int* nHere ); int* nHere );