New callback called on first connect to relay and on first ALLHERE

message so users can see progress.  Handle new relay message ALLBACK
meaning "ALLHERE but not for the first time".
This commit is contained in:
ehouse 2009-12-14 04:03:17 +00:00
parent 273f3d2f4a
commit 8450c9da2b
2 changed files with 17 additions and 6 deletions

View file

@ -1070,16 +1070,20 @@ relayCmdToStr( XWRELAY_Cmd cmd )
static void
got_connect_cmd( CommsCtxt* comms, XWStreamCtxt* stream,
CommsRelayState newState )
XP_Bool reconnected )
{
XP_U16 nHere, nSought;
set_relay_state( comms, newState );
set_relay_state( comms, reconnected ? COMMS_RELAYSTATE_RECONNECTED
: COMMS_RELAYSTATE_CONNECTED );
comms->r.heartbeat = stream_getU16( stream );
nHere = (XP_U16)stream_getU8( stream );
nSought = (XP_U16)stream_getU8( stream );
/* This may belong as an alert to user so knows has connected. */
nHere = (XP_U16)stream_getU8( stream );
if ( ! reconnected ) {
/* This may belong as an alert to user so knows has connected. */
(*comms->procs.rconnd)( comms->procs.closure, XP_FALSE, nSought - nHere );
}
XP_LOGF( "%s: have %d of %d players", __func__, nHere, nSought );
setHeartbeatTimer( comms );
}
@ -1098,14 +1102,15 @@ relayPreProcess( CommsCtxt* comms, XWStreamCtxt* stream, XWHostID* senderID )
switch( cmd ) {
case XWRELAY_CONNECT_RESP:
got_connect_cmd( comms, stream, COMMS_RELAYSTATE_CONNECTED );
got_connect_cmd( comms, stream, XP_FALSE );
break;
case XWRELAY_RECONNECT_RESP:
got_connect_cmd( comms, stream, COMMS_RELAYSTATE_RECONNECTED );
got_connect_cmd( comms, stream, XP_TRUE );
comms_resendAll( comms );
break;
case XWRELAY_ALLHERE:
case XWRELAY_ALLBACK:
srcID = (XWHostID)stream_getU8( stream );
XP_ASSERT( comms->r.myHostID == HOST_ID_NONE
|| comms->r.myHostID == srcID );
@ -1135,6 +1140,9 @@ relayPreProcess( CommsCtxt* comms, XWStreamCtxt* stream, XWHostID* senderID )
if ( COMMS_RELAYSTATE_RECONNECTED != comms->r.relayState ) {
comms_resendAll( comms );
}
if ( XWRELAY_ALLHERE == cmd ) { /* initial connect? */
(*comms->procs.rconnd)( comms->procs.closure, XP_TRUE, 0 );
}
set_relay_state( comms, COMMS_RELAYSTATE_ALLCONNECTED );
break;
case XWRELAY_MSG_FROMRELAY:

View file

@ -117,6 +117,8 @@ typedef void (*TransportReset)( void* closure );
#ifdef XWFEATURE_RELAY
typedef void (*RelayStatusProc)( void* closure, CommsRelayState newState );
typedef void (*RelayConndProc)( void* closure, XP_Bool allHere,
XP_U16 nMissing );
typedef void (*RelayErrorProc)( void* closure, XWREASON relayErr );
#endif
@ -127,6 +129,7 @@ typedef struct _TransportProcs {
#endif
#ifdef XWFEATURE_RELAY
RelayStatusProc rstatus;
RelayConndProc rconnd;
RelayErrorProc rerror;
#endif
void* closure;