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();
} /* _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
CookieRef::SocketForHost( HostID dest )
{
@ -590,9 +606,9 @@ CookieRef::handleEvents()
/* break; */
case XWA_SEND_RERSP:
increasePlayerCounts( &evt, true );
sendResponse( &evt, false );
sendAnyStored( &evt );
increasePlayerCounts( &evt, true );
postCheckAllHere();
break;
@ -994,7 +1010,7 @@ CookieRef::send_msg( int socket, HostID id, XWRelayMsg msg, XWREASON why,
void
CookieRef::RecordSent( int nBytes, int socket ) {
m_totalSent += nBytes;
DBMgr::Get()->RecordSent( ConnName(), nBytes );
DBMgr::Get()->RecordSent( ConnName(), HostForSocket(socket), nBytes );
}
void

View file

@ -93,6 +93,7 @@ class CookieRef {
int GetHeartbeat() { return m_heatbeat; }
int SocketForHost( HostID dest );
HostID HostForSocket( int sock );
/* connect case */
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 );
const char* fmt = "UPDATE " GAMES_TABLE " SET nPerDevice[%d] = %d,"
" seeds[%d] = %d, mtime='now'"
" seeds[%d] = %d, mtimes[%d]='now'"
" WHERE connName = '%s'";
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 );
execSql( query );
@ -223,9 +223,9 @@ bool
DBMgr::RmDevice( const char* connName, HostID hid )
{
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];
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 );
return execSql( query );
@ -249,8 +249,8 @@ DBMgr::HaveDevice( const char* connName, HostID hid, int seed )
void
DBMgr::AddCID( const char* const connName, CookieID cid )
{
const char* fmt = "UPDATE " GAMES_TABLE " SET cid = %d, "
" mtime='now' WHERE connName = '%s'";
const char* fmt = "UPDATE " GAMES_TABLE " SET cid = %d "
" WHERE connName = '%s'";
char query[256];
snprintf( query, sizeof(query), fmt, cid, connName );
logf( XW_LOGINFO, "%s: query: %s", __func__, query );
@ -271,16 +271,17 @@ DBMgr::ClearCID( const char* connName )
}
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"
" nsent = nsent + %d, mtime = 'now'"
" WHERE connName = '%s'";
char query[256];
snprintf( query, sizeof(query), fmt, nBytes, connName );
logf( XW_LOGINFO, "%s: query: %s", __func__, query );
assert( hid >= 0 && hid <= 4 );
const char* fmt = "UPDATE " GAMES_TABLE " SET"
" nsent = nsent + %d, mtimes[%d] = 'now'"
" WHERE connName = '%s'";
char query[256];
snprintf( query, sizeof(query), fmt, nBytes, hid, connName );
logf( XW_LOGINFO, "%s: query: %s", __func__, query );
execSql( query );
execSql( query );
}
void

View file

@ -52,9 +52,9 @@ class DBMgr {
int nToAdd, unsigned short seed );
bool RmDevice( const char* const connName, HostID id );
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 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,
int* nHere );