greatly simplify state machine for connections. Now (with DEVACK=20

on conf file) newrelay.sh will complete running 50 4-device gtk games.
Haven't tested reconnect case which I almost certianly broke.
This commit is contained in:
Andy2 2010-09-16 01:53:43 -07:00
parent 0d7165f881
commit b25579b893
2 changed files with 17 additions and 20 deletions

View file

@ -222,8 +222,7 @@ void
CookieRef::_HandleAck( HostID hostID )
{
assert( m_nPendingAcks > 0 && m_nPendingAcks <= 4 );
XW_RELAY_EVENT newEvt = m_nPendingAcks == 1? XWE_GOTLASTACK : XWE_GOTONEACK;
CRefEvent evt( newEvt );
CRefEvent evt( XWE_GOTONEACK );
evt.u.ack.srcID = hostID;
m_eventQueue.push_back( evt );
handleEvents();
@ -572,10 +571,9 @@ CookieRef::handleEvents()
break;
case XWA_NOTEACKCHECK:
postCheckAllHere();
/* FALLTHRU */
case XWA_NOTEACK:
modPending( &evt, true );
postCheckAllHere();
break;
case XWA_DROPDEVICE:
@ -838,16 +836,12 @@ CookieRef::modPending( const CRefEvent* evt, bool keep )
void
CookieRef::postCheckAllHere()
{
XW_RELAY_EVENT newEvt;
if ( m_nPlayersHere == m_nPlayersSought ) { /* complete! */
if ( m_nPendingAcks == 0
&& m_nPlayersHere == m_nPlayersSought ) { /* complete! */
m_gameFull = true;
newEvt = XWE_ALLHERE;
} else {
newEvt = XWE_SOMEMISSING;
CRefEvent evt( XWE_ALLHERE );
m_eventQueue.push_back( evt );
}
CRefEvent evt( newEvt );
m_eventQueue.push_back( evt );
}
void

View file

@ -61,16 +61,15 @@ typedef struct StateTable {
*/
static StateTable g_stateTable[] = {
{ XWS_INITED, XWE_DEVCONNECT, XWA_SEND_CONNRSP, XWS_WAITMORE },
{ XWS_WAITMORE, XWE_DEVCONNECT, XWA_SEND_CONNRSP, XWS_WAITMORE },
{ XWS_WAITMORE, XWE_GOTONEACK, XWA_NOTEACK, XWS_WAITMORE },
{ XWS_WAITMORE, XWE_ACKTIMEOUT, XWA_DROPDEVICE, XWS_WAITMORE },
{ XWS_WAITMORE, XWE_ALLHERE, XWA_SENDALLHERE, XWS_ALLCONND },
{ XWS_INITED, XWE_DEVCONNECT, XWA_SEND_CONNRSP, XWS_WAITING_ACKS },
{ XWS_WAITMORE, XWE_DEVCONNECT, XWA_SEND_CONNRSP, XWS_WAITING_ACKS },
{ XWS_WAITING_ACKS, XWE_DEVCONNECT, XWA_SEND_CONNRSP, XWS_WAITING_ACKS },
{ XWS_WAITING_ACKS, XWE_GOTONEACK, XWA_NOTEACK, XWS_WAITING_ACKS },
{ XWS_WAITING_ACKS, XWE_GOTLASTACK, XWA_NOTEACKCHECK, XWS_CHK_ALLHERE },
{ XWS_WAITING_ACKS, XWE_ACKTIMEOUT, XWA_DROPDEVICE, XWS_WAITMORE },
{ XWS_WAITMORE, XWE_RECONNECT, XWA_SEND_RERSP, XWS_WAITMORE },
{ XWS_ALLCONND, XWE_RECONNECT, XWA_SEND_RERSP, XWS_ALLCONND },
/* { XWS_WAITMORE, XWE_RECONNECT, XWA_SEND_RERSP, XWS_WAITMORE }, */
/* { XWS_ALLCONND, XWE_RECONNECT, XWA_SEND_RERSP, XWS_ALLCONND }, */
/* { XWS_WAITMORE, XWE_GAMEFULL, XWA_SENDALLHERE, XWS_ALLCONND }, */
/* { XWS_WAITMORE, XWE_CHECKFULL, XWA_, XWS_WAITMORE }, */
@ -82,6 +81,8 @@ static StateTable g_stateTable[] = {
/* { XWS_ROOMCHK, XWE_HAVE_ROOM, XWA_SEND_GUEST_RSP, XWS_CHK_ALLHERE }, */
/* { XWS_ROOMCHK, XWE_TOO_MANY, XWA_SEND_TOO_MANY, XWS_WAITGUESTS }, */
{ XWS_CHK_ALLHERE, XWE_ALLHERE, XWA_SENDALLHERE, XWS_ALLCONND },
{ XWS_ALLCONND, XWE_SOMEMISSING, XWA_NONE, XWS_MISSING },
{ XWS_CHK_ALLHERE, XWE_SOMEMISSING, XWA_NONE, XWS_WAITMORE },
@ -102,6 +103,8 @@ static StateTable g_stateTable[] = {
{ XWS_ANY, XWE_NOMORESOCKETS, XWA_NONE, XWS_DEAD },
{ XWS_ANY, XWE_SHUTDOWN, XWA_SHUTDOWN, XWS_DEAD },
/* This doesn't make sense. Can't go straight to ALLCOND if don't have all
players/devices. */
{ XWS_INITED, XWE_RECONNECT, XWA_SEND_RERSP, XWS_ALLCONND },
{ XWS_MSGONLY, XWE_RECONNECT, XWA_SEND_RERSP, XWS_ALLCONND },