From 2ecf415618b93fc053eff484fee458312628ea01 Mon Sep 17 00:00:00 2001 From: ehouse Date: Mon, 9 Nov 2009 05:30:42 +0000 Subject: [PATCH] Remove on case where HandleEvents was being called recursively and creating unexpected state transitions; add assert to catch any future recursion. --- xwords4/relay/cref.cpp | 8 +++++++- xwords4/relay/cref.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/xwords4/relay/cref.cpp b/xwords4/relay/cref.cpp index c5d5e9e4a..44dec4230 100644 --- a/xwords4/relay/cref.cpp +++ b/xwords4/relay/cref.cpp @@ -94,6 +94,7 @@ CookieRef::ReInit( const char* cookie, const char* connName, CookieID id ) m_starttime = uptime(); m_gameFull = false; m_nHostMsgs = 0; + m_in_handleEvents = false; RelayConfigs::GetConfigs()->GetValueFor( "HEARTBEAT", &m_heatbeat ); logf( XW_LOGINFO, "initing cref for cookie %s, connName %s", @@ -489,6 +490,9 @@ CookieRef::pushLastSocketGoneEvent() void CookieRef::handleEvents() { + assert( !m_in_handleEvents ); + m_in_handleEvents = true; + /* Assumption: has mutex!!!! */ while ( m_eventQueue.size () > 0 ) { XW_RELAY_STATE nextState; @@ -573,6 +577,7 @@ CookieRef::handleEvents() break; case XWA_NOTE_EMPTY: + cancelAllConnectedTimer(); if ( 0 == count_msgs_stored() ) { CRefEvent evt; evt.type = XWE_NOMOREMSGS; @@ -598,6 +603,7 @@ CookieRef::handleEvents() m_curState = nextState; } } + m_in_handleEvents = false; } /* handleEvents */ bool @@ -612,7 +618,7 @@ CookieRef::send_with_length( int socket, unsigned char* buf, int bufLen, } if ( failed && cascade ) { - _Remove( socket ); + pushRemoveSocketEvent( socket ); XWThreadPool::GetTPool()->CloseSocket( socket ); } return !failed; diff --git a/xwords4/relay/cref.h b/xwords4/relay/cref.h index 70c52dba6..1b6541558 100644 --- a/xwords4/relay/cref.h +++ b/xwords4/relay/cref.h @@ -257,6 +257,7 @@ class CookieRef { pthread_mutex_t m_mutex; pthread_t m_locking_thread; /* for debugging only */ + bool m_in_handleEvents; /* for debugging only */ }; /* CookieRef */ #endif