From e2e66f8057a2b419ef8cf565bd2aedffbbd408dc Mon Sep 17 00:00:00 2001 From: ehouse Date: Wed, 19 Oct 2005 03:44:55 +0000 Subject: [PATCH] Set a disconn timer when somebody leaves to make it parallel with case where somebody never shows up; print more info about cref state to ctrl port. --- xwords4/relay/cref.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/xwords4/relay/cref.cpp b/xwords4/relay/cref.cpp index 894e79a33..8b03c75f6 100644 --- a/xwords4/relay/cref.cpp +++ b/xwords4/relay/cref.cpp @@ -422,14 +422,18 @@ CookieRef::handleEvents() case XWA_TIMERDISCONN: disconnectSockets( 0, XWRELAY_ERROR_TIMEOUT ); break; + case XWA_HEARTDISCONN: notifyOthers( evt.u.heart.socket, XWRELAY_DISCONNECT_OTHER, XWRELAY_ERROR_HEART_OTHER ); + setAllConnectedTimer(); + reducePlayerCounts( evt.u.discon.socket ); disconnectSockets( evt.u.heart.socket, XWRELAY_ERROR_HEART_YOU ); break; case XWA_DISCONNECT: + setAllConnectedTimer(); reducePlayerCounts( evt.u.discon.socket ); removeSocket( evt.u.discon.socket ); /* Don't notify. This is a normal part of a game ending. */ @@ -444,6 +448,7 @@ CookieRef::handleEvents() break; case XWA_REMOVESOCKET: + setAllConnectedTimer(); reducePlayerCounts( evt.u.rmsock.socket ); notifyOthers( evt.u.rmsock.socket, XWRELAY_DISCONNECT_OTHER, XWRELAY_ERROR_LOST_OTHER ); @@ -800,9 +805,25 @@ CookieRef::_PrintCookieInfo( string& out ) snprintf( buf, sizeof(buf), "Players here=%d\n", m_nPlayersHere ); out += buf; + snprintf( buf, sizeof(buf), "State=%s\n", stateString( m_curState ) ); + out += buf; + + /* Timer state: how long since last heartbeat; how long til disconn timer + fires. */ + /* n messages */ - /* n bytes */ /* open since when */ - /* sockets */ + + snprintf( buf, sizeof(buf), "Hosts connected=%d; cur time = %ld\n", + m_sockets.size(), now() ); + out += buf; + map::iterator iter = m_sockets.begin(); + while ( iter != m_sockets.end() ) { + snprintf( buf, sizeof(buf), " HostID=%d; socket=%d;last hbeat=%ld\n", + iter->first, iter->second.m_socket, + iter->second.m_lastHeartbeat ); + out += buf; + ++iter; + } } /* PrintCookieInfo */