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

View file

@ -61,16 +61,15 @@ typedef struct StateTable {
*/ */
static StateTable g_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_WAITMORE, XWE_RECONNECT, XWA_SEND_RERSP, XWS_WAITMORE }, */
{ XWS_ALLCONND, XWE_RECONNECT, XWA_SEND_RERSP, XWS_ALLCONND }, /* { XWS_ALLCONND, XWE_RECONNECT, XWA_SEND_RERSP, XWS_ALLCONND }, */
/* { XWS_WAITMORE, XWE_GAMEFULL, XWA_SENDALLHERE, XWS_ALLCONND }, */ /* { XWS_WAITMORE, XWE_GAMEFULL, XWA_SENDALLHERE, XWS_ALLCONND }, */
/* { XWS_WAITMORE, XWE_CHECKFULL, XWA_, XWS_WAITMORE }, */ /* { 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_HAVE_ROOM, XWA_SEND_GUEST_RSP, XWS_CHK_ALLHERE }, */
/* { XWS_ROOMCHK, XWE_TOO_MANY, XWA_SEND_TOO_MANY, XWS_WAITGUESTS }, */ /* { XWS_ROOMCHK, XWE_TOO_MANY, XWA_SEND_TOO_MANY, XWS_WAITGUESTS }, */
{ XWS_CHK_ALLHERE, XWE_ALLHERE, XWA_SENDALLHERE, XWS_ALLCONND }, { XWS_CHK_ALLHERE, XWE_ALLHERE, XWA_SENDALLHERE, XWS_ALLCONND },
{ XWS_ALLCONND, XWE_SOMEMISSING, XWA_NONE, XWS_MISSING }, { XWS_ALLCONND, XWE_SOMEMISSING, XWA_NONE, XWS_MISSING },
{ XWS_CHK_ALLHERE, XWE_SOMEMISSING, XWA_NONE, XWS_WAITMORE }, { 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_NOMORESOCKETS, XWA_NONE, XWS_DEAD },
{ XWS_ANY, XWE_SHUTDOWN, XWA_SHUTDOWN, 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_INITED, XWE_RECONNECT, XWA_SEND_RERSP, XWS_ALLCONND },
{ XWS_MSGONLY, XWE_RECONNECT, XWA_SEND_RERSP, XWS_ALLCONND }, { XWS_MSGONLY, XWE_RECONNECT, XWA_SEND_RERSP, XWS_ALLCONND },