mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
Include number of games played in html output; don't report closed
sockets found while reporting closed sockets (to avoid deadlock); remove sockets from crefmgr's map when closing them so new connections using same (re-used) socket aren't treated as belonging to open games.
This commit is contained in:
parent
a680a6e5fe
commit
2ef16d44ca
5 changed files with 57 additions and 21 deletions
|
@ -225,13 +225,13 @@ CookieRef::notifyDisconn( const CRefEvent* evt )
|
||||||
evt->u.disnote.why
|
evt->u.disnote.why
|
||||||
};
|
};
|
||||||
|
|
||||||
send_with_length( socket, buf, sizeof(buf) );
|
send_with_length( socket, buf, sizeof(buf), true );
|
||||||
} /* notifyDisconn */
|
} /* notifyDisconn */
|
||||||
|
|
||||||
void
|
void
|
||||||
CookieRef::removeSocket( int socket )
|
CookieRef::removeSocket( int socket )
|
||||||
{
|
{
|
||||||
logf( XW_LOGINFO, "%s(%d)", __func__, socket );
|
logf( XW_LOGINFO, "%s(socket=%d)", __func__, socket );
|
||||||
int count;
|
int count;
|
||||||
{
|
{
|
||||||
/* RWWriteLock rwl( &m_sockets_rwlock ); */
|
/* RWWriteLock rwl( &m_sockets_rwlock ); */
|
||||||
|
@ -501,18 +501,29 @@ CookieRef::handleEvents()
|
||||||
} /* handleEvents */
|
} /* handleEvents */
|
||||||
|
|
||||||
void
|
void
|
||||||
CookieRef::send_with_length( int socket, unsigned char* buf, int bufLen )
|
CookieRef::send_with_length( int socket, unsigned char* buf, int bufLen,
|
||||||
|
bool cascade )
|
||||||
{
|
{
|
||||||
SocketWriteLock slock( socket );
|
bool failed = false;
|
||||||
if ( slock.socketFound() ) {
|
{
|
||||||
|
SocketWriteLock slock( socket );
|
||||||
if ( send_with_length_unsafe( socket, buf, bufLen ) ) {
|
if ( slock.socketFound() ) {
|
||||||
RecordSent( bufLen, socket );
|
if ( send_with_length_unsafe( socket, buf, bufLen ) ) {
|
||||||
} else {
|
RecordSent( bufLen, socket );
|
||||||
/* ok that the slock above is still in scope */
|
} else {
|
||||||
killSocket( socket, "couldn't send" );
|
failed = true;
|
||||||
|
/* ok that the slock above is still in scope */
|
||||||
|
/* Can't call killSocket. It will deadlock (try to lock a mutex
|
||||||
|
we already hold) if what we're sending about is that we're
|
||||||
|
killing a socket */
|
||||||
|
/* killSocket( socket, "couldn't send" ); */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ( failed && cascade ) {
|
||||||
|
_Remove( socket );
|
||||||
|
XWThreadPool::GetTPool()->CloseSocket( socket );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -652,7 +663,7 @@ CookieRef::sendResponse( const CRefEvent* evt, bool initial )
|
||||||
logf( XW_LOGVERBOSE0, "writing hostID of %d into msg", id );
|
logf( XW_LOGVERBOSE0, "writing hostID of %d into msg", id );
|
||||||
*bufp++ = (char)id;
|
*bufp++ = (char)id;
|
||||||
|
|
||||||
send_with_length( socket, buf, bufp - buf );
|
send_with_length( socket, buf, bufp - buf, true );
|
||||||
logf( XW_LOGVERBOSE0, "sent XWRELAY_CONNECTRESP" );
|
logf( XW_LOGVERBOSE0, "sent XWRELAY_CONNECTRESP" );
|
||||||
} /* sendResponse */
|
} /* sendResponse */
|
||||||
|
|
||||||
|
@ -668,7 +679,7 @@ CookieRef::forward( const CRefEvent* evt )
|
||||||
if ( destSocket != -1 ) {
|
if ( destSocket != -1 ) {
|
||||||
/* This is an ugly hack!!!! */
|
/* This is an ugly hack!!!! */
|
||||||
*buf = XWRELAY_MSG_FROMRELAY;
|
*buf = XWRELAY_MSG_FROMRELAY;
|
||||||
send_with_length( destSocket, buf, buflen );
|
send_with_length( destSocket, buf, buflen, true );
|
||||||
|
|
||||||
/* also note that we've heard from src recently */
|
/* also note that we've heard from src recently */
|
||||||
#ifdef RELAY_HEARTBEAT
|
#ifdef RELAY_HEARTBEAT
|
||||||
|
@ -681,11 +692,12 @@ CookieRef::forward( const CRefEvent* evt )
|
||||||
} /* forward */
|
} /* forward */
|
||||||
|
|
||||||
void
|
void
|
||||||
CookieRef::send_msg( int socket, HostID id, XWRelayMsg msg, XWREASON why )
|
CookieRef::send_msg( int socket, HostID id, XWRelayMsg msg, XWREASON why,
|
||||||
|
bool cascade )
|
||||||
{
|
{
|
||||||
unsigned char buf[10];
|
unsigned char buf[10];
|
||||||
short tmp;
|
short tmp;
|
||||||
int len = 0;
|
unsigned int len = 0;
|
||||||
buf[len++] = msg;
|
buf[len++] = msg;
|
||||||
|
|
||||||
switch ( msg ) {
|
switch ( msg ) {
|
||||||
|
@ -701,7 +713,7 @@ CookieRef::send_msg( int socket, HostID id, XWRelayMsg msg, XWREASON why )
|
||||||
}
|
}
|
||||||
|
|
||||||
assert( len <= sizeof(buf) );
|
assert( len <= sizeof(buf) );
|
||||||
send_with_length( socket, buf, len );
|
send_with_length( socket, buf, len, cascade );
|
||||||
} /* send_msg */
|
} /* send_msg */
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -715,7 +727,7 @@ CookieRef::notifyOthers( int socket, XWRelayMsg msg, XWREASON why )
|
||||||
while ( iter != m_sockets.end() ) {
|
while ( iter != m_sockets.end() ) {
|
||||||
int other = iter->second.m_socket;
|
int other = iter->second.m_socket;
|
||||||
if ( other != socket ) {
|
if ( other != socket ) {
|
||||||
send_msg( other, iter->first, msg, why );
|
send_msg( other, iter->first, msg, why, false );
|
||||||
}
|
}
|
||||||
++iter;
|
++iter;
|
||||||
}
|
}
|
||||||
|
@ -741,7 +753,8 @@ CookieRef::sendAllHere( bool includeName )
|
||||||
|
|
||||||
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() ) {
|
||||||
send_with_length( iter->second.m_socket, buf, bufp-buf );
|
send_with_length( iter->second.m_socket, buf, bufp-buf,
|
||||||
|
true );
|
||||||
++iter;
|
++iter;
|
||||||
}
|
}
|
||||||
} /* sendAllHere */
|
} /* sendAllHere */
|
||||||
|
|
|
@ -144,8 +144,10 @@ class CookieRef {
|
||||||
} u;
|
} u;
|
||||||
} CRefEvent;
|
} CRefEvent;
|
||||||
|
|
||||||
void send_with_length( int socket, unsigned char* buf, int bufLen );
|
void send_with_length( int socket, unsigned char* buf, int bufLen,
|
||||||
void send_msg( int socket, HostID id, XWRelayMsg msg, XWREASON why );
|
bool cascade );
|
||||||
|
void send_msg( int socket, HostID id, XWRelayMsg msg, XWREASON why,
|
||||||
|
bool cascade );
|
||||||
|
|
||||||
void RecordSent( int nBytes, int socket ) {
|
void RecordSent( int nBytes, int socket ) {
|
||||||
m_totalSent += nBytes;
|
m_totalSent += nBytes;
|
||||||
|
|
|
@ -140,6 +140,12 @@ CRefMgr::nextCID( const char* connName )
|
||||||
return ++m_nextCID;
|
return ++m_nextCID;
|
||||||
} /* nextCID */
|
} /* nextCID */
|
||||||
|
|
||||||
|
int
|
||||||
|
CRefMgr::GetNumGamesSeen( void )
|
||||||
|
{
|
||||||
|
return m_nextCID;
|
||||||
|
}
|
||||||
|
|
||||||
CookieID
|
CookieID
|
||||||
CRefMgr::cookieIDForConnName( const char* connName )
|
CRefMgr::cookieIDForConnName( const char* connName )
|
||||||
{
|
{
|
||||||
|
@ -244,7 +250,7 @@ CRefMgr::Disassociate( int socket, CookieRef* cref )
|
||||||
logf( XW_LOGERROR, "can't find cref/threadID pair for socket %d", socket );
|
logf( XW_LOGERROR, "can't find cref/threadID pair for socket %d", socket );
|
||||||
} else {
|
} else {
|
||||||
SocketStuff* stuff = iter->second;
|
SocketStuff* stuff = iter->second;
|
||||||
assert( stuff->m_cref == cref );
|
assert( cref == NULL || stuff->m_cref == cref );
|
||||||
delete stuff;
|
delete stuff;
|
||||||
m_SocketStuff.erase( iter );
|
m_SocketStuff.erase( iter );
|
||||||
}
|
}
|
||||||
|
@ -268,6 +274,8 @@ CRefMgr::RemoveSocketRefs( int socket )
|
||||||
{
|
{
|
||||||
SafeCref scr( socket );
|
SafeCref scr( socket );
|
||||||
scr.Remove( socket );
|
scr.Remove( socket );
|
||||||
|
|
||||||
|
Disassociate( socket, NULL );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -76,6 +76,8 @@ class CRefMgr {
|
||||||
void PrintSocketInfo( int socket, string& out );
|
void PrintSocketInfo( int socket, string& out );
|
||||||
SocketsIterator MakeSocketsIterator();
|
SocketsIterator MakeSocketsIterator();
|
||||||
|
|
||||||
|
int GetNumGamesSeen( void );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class SafeCref;
|
friend class SafeCref;
|
||||||
CookieRef* getMakeCookieRef_locked( const char* cORn, bool isCookie,
|
CookieRef* getMakeCookieRef_locked( const char* cORn, bool isCookie,
|
||||||
|
|
|
@ -157,6 +157,15 @@ printCrefs( FILE* fil )
|
||||||
fprintf( fil, "</table>\n" );
|
fprintf( fil, "</table>\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
printNumGames( FILE* fil )
|
||||||
|
{
|
||||||
|
CRefMgr* cmgr = CRefMgr::Get();
|
||||||
|
int nGames = cmgr->GetNumGamesSeen();
|
||||||
|
fprintf( fil, "<div class=\"header\">Games played</div>" );
|
||||||
|
fprintf( fil, "<p>%d</p>\n", nGames );
|
||||||
|
}
|
||||||
|
|
||||||
static void*
|
static void*
|
||||||
http_thread_main( void* arg )
|
http_thread_main( void* arg )
|
||||||
{
|
{
|
||||||
|
@ -183,6 +192,8 @@ http_thread_main( void* arg )
|
||||||
send_meta( fil );
|
send_meta( fil );
|
||||||
fprintf( fil, "<body><div class=\"main\">" );
|
fprintf( fil, "<body><div class=\"main\">" );
|
||||||
|
|
||||||
|
printNumGames( fil );
|
||||||
|
|
||||||
printCrefs( fil );
|
printCrefs( fil );
|
||||||
|
|
||||||
printUptime( fil );
|
printUptime( fil );
|
||||||
|
|
Loading…
Reference in a new issue