From 8bb2fb9b092db713ad62717b273521e143303f17 Mon Sep 17 00:00:00 2001 From: eehouse Date: Fri, 28 May 2010 02:31:27 +0000 Subject: [PATCH] track and display in web view the number of games actually joined rather than the number attempted. --- xwords4/relay/cref.cpp | 1 + xwords4/relay/crefmgr.cpp | 17 ++++++++++++----- xwords4/relay/crefmgr.h | 9 +++++++-- xwords4/relay/http.cpp | 8 ++++---- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/xwords4/relay/cref.cpp b/xwords4/relay/cref.cpp index 5e2414983..da0821f61 100644 --- a/xwords4/relay/cref.cpp +++ b/xwords4/relay/cref.cpp @@ -617,6 +617,7 @@ CookieRef::handleEvents() break; case XWA_SENDALLHERE: + CRefMgr::Get()->IncrementFullCount(); cancelAllConnectedTimer(); assignHostIds(); assignConnName(); diff --git a/xwords4/relay/crefmgr.cpp b/xwords4/relay/crefmgr.cpp index 0f49a93a9..766d50d73 100644 --- a/xwords4/relay/crefmgr.cpp +++ b/xwords4/relay/crefmgr.cpp @@ -61,6 +61,7 @@ CRefMgr::CRefMgr() /* should be using pthread_once() here */ pthread_mutex_init( &m_SocketStuffMutex, NULL ); pthread_mutex_init( &m_nextCIDMutex, NULL ); + pthread_mutex_init( &m_roomsFilledMutex, NULL ); pthread_mutex_init( &m_freeList_mutex, NULL ); pthread_rwlock_init( &m_cookieMapRWLock, NULL ); } @@ -210,13 +211,19 @@ CRefMgr::nextCID( const char* connName ) return ++m_nextCID; } /* nextCID */ -int -CRefMgr::GetNumGamesSeen( void ) +void +CRefMgr::IncrementFullCount( void ) { - MutexLock ml(&m_nextCIDMutex); - return m_nextCID; + MutexLock ml( &m_roomsFilledMutex ); + ++m_nRoomsFilled; } +int +CRefMgr::GetNumRoomsFilled( void ) +{ + MutexLock ml(&m_roomsFilledMutex); + return m_nRoomsFilled; +} int CRefMgr::GetSize( void ) @@ -227,7 +234,7 @@ CRefMgr::GetSize( void ) void CRefMgr::GetStats( CrefMgrInfo& mgrInfo ) { - mgrInfo.m_nCrefsAll = GetNumGamesSeen(); + mgrInfo.m_nRoomsFilled = GetNumRoomsFilled(); mgrInfo.m_startTimeSpawn = m_startTime; if ( 0 == m_ports.length() ) { diff --git a/xwords4/relay/crefmgr.h b/xwords4/relay/crefmgr.h index 907adc874..ba0ebfdd1 100644 --- a/xwords4/relay/crefmgr.h +++ b/xwords4/relay/crefmgr.h @@ -63,7 +63,7 @@ class CrefInfo { class CrefMgrInfo { public: const char* m_ports; - int m_nCrefsAll; + int m_nRoomsFilled; int m_nCrefsCurrent; time_t m_startTimeSpawn; vector m_crefInfo; @@ -108,7 +108,9 @@ class CRefMgr { void PrintSocketInfo( int socket, string& out ); SocketsIterator MakeSocketsIterator(); - int GetNumGamesSeen( void ); + void IncrementFullCount( void ); + int GetNumRoomsFilled( void ); + int GetSize( void ); time_t uptime(); @@ -153,6 +155,9 @@ class CRefMgr { pthread_mutex_t m_nextCIDMutex; CookieID m_nextCID; + pthread_mutex_t m_roomsFilledMutex; + int m_nRoomsFilled; + pthread_rwlock_t m_cookieMapRWLock; CookieMap m_cookieMap; diff --git a/xwords4/relay/http.cpp b/xwords4/relay/http.cpp index 2eebab2ae..9e7c08c4f 100644 --- a/xwords4/relay/http.cpp +++ b/xwords4/relay/http.cpp @@ -98,7 +98,7 @@ send_meta( FILE* fil, const CrefMgrInfo* info ) } } - fprintf( fil, "relay: %d/%d\n", info->m_nCrefsAll, + fprintf( fil, "relay: %d/%d\n", info->m_nRoomsFilled, info->m_nCrefsCurrent ); fprintf( fil, "" ); } @@ -189,11 +189,11 @@ printStats( FILE* fil, const CrefMgrInfo* info, bool isLocal ) fprintf( fil, "" ); fprintf( fil, "" "" - "" ); + "" ); fprintf( fil, "" "\n", - info->m_ports, uptime1, GetNSpawns(), uptime2, info->m_nCrefsAll, - info->m_nCrefsCurrent ); + info->m_ports, uptime1, GetNSpawns(), uptime2, + info->m_nRoomsFilled, info->m_nCrefsCurrent ); fprintf( fil, "
PortsUptimeSpawnsSpawn UtimeGames playedGames in play
Rooms filledGames in play
%s%s%d%s%d%d
" ); }