change one return type; improve logging

This commit is contained in:
Andy2 2011-07-04 12:46:48 -07:00
parent 8904f37e1a
commit 0eec455119
2 changed files with 34 additions and 27 deletions

View file

@ -535,6 +535,7 @@ comms_makeFromStream( MPFORMAL XWStreamCtxt* stream, XW_UtilCtxt* util,
comms->channelSeed = 0; comms->channelSeed = 0;
} else { } else {
comms->channelSeed = stream_getU16( stream ); comms->channelSeed = stream_getU16( stream );
XP_LOGF( "%s: loaded seed: %.4X", __func__, comms->channelSeed );
} }
if ( addr.conType == COMMS_CONN_RELAY ) { if ( addr.conType == COMMS_CONN_RELAY ) {
comms->r.myHostID = stream_getU8( stream ); comms->r.myHostID = stream_getU8( stream );
@ -982,7 +983,9 @@ addToQueue( CommsCtxt* comms, MsgQueueElem* newMsgElem )
XP_ASSERT( comms->queueLen > 0 ); XP_ASSERT( comms->queueLen > 0 );
} }
++comms->queueLen; ++comms->queueLen;
XP_STATUSF( "addToQueue: queueLen now %d", comms->queueLen ); XP_LOGF( "%s: queueLen now %d after channelNo: %d; msgID: " XP_LD,
__func__, comms->queueLen,
newMsgElem->channelNo & CHANNEL_MASK, newMsgElem->msgID );
} /* addToQueue */ } /* addToQueue */
#ifdef DEBUG #ifdef DEBUG
@ -1104,8 +1107,10 @@ sendMsg( CommsCtxt* comms, MsgQueueElem* elem )
} else if ( conType == COMMS_CONN_RELAY ) { } else if ( conType == COMMS_CONN_RELAY ) {
if ( comms->r.relayState >= COMMS_RELAYSTATE_CONNECTED ) { if ( comms->r.relayState >= COMMS_RELAYSTATE_CONNECTED ) {
XWHostID destID = getDestID( comms, channelNo ); XWHostID destID = getDestID( comms, channelNo );
result = send_via_relay( comms, XWRELAY_MSG_TORELAY, destID, if ( send_via_relay( comms, XWRELAY_MSG_TORELAY, destID,
elem->msg, elem->len ); elem->msg, elem->len ) ){
result = elem->len;
}
} else { } else {
XP_LOGF( "%s: skipping message: not connected", __func__ ); XP_LOGF( "%s: skipping message: not connected", __func__ );
} }
@ -1129,9 +1134,11 @@ sendMsg( CommsCtxt* comms, MsgQueueElem* elem )
if ( result == elem->len ) { if ( result == elem->len ) {
++elem->sendCount; ++elem->sendCount;
XP_LOGF( "%s: sendCount now %d", __func__, elem->sendCount ); XP_LOGF( "%s: elem's sendCount now %d", __func__, elem->sendCount );
} }
XP_LOGF( "%s(channelNo=%d;msgID=" XP_LD ")=>%d", __func__,
elem->channelNo & CHANNEL_MASK, elem->msgID, result );
return result; return result;
} /* sendMsg */ } /* sendMsg */
@ -1139,27 +1146,24 @@ static void
send_ack( CommsCtxt* comms ) send_ack( CommsCtxt* comms )
{ {
LOG_FUNC(); LOG_FUNC();
send_via_relay( comms, XWRELAY_ACK, comms->r.myHostID, NULL, 0 ); (void)send_via_relay( comms, XWRELAY_ACK, comms->r.myHostID, NULL, 0 );
} }
XP_S16 XP_Bool
comms_resendAll( CommsCtxt* comms ) comms_resendAll( CommsCtxt* comms )
{ {
XP_Bool success = XP_TRUE;
MsgQueueElem* msg; MsgQueueElem* msg;
XP_S16 result = 0;
XP_ASSERT( !!comms ); XP_ASSERT( !!comms );
for ( msg = comms->msgQueueHead; !!msg; msg = msg->next ) { for ( msg = comms->msgQueueHead; !!msg; msg = msg->next ) {
XP_S16 oneResult = sendMsg( comms, msg ); if ( 0 > sendMsg( comms, msg ) ) {
if ( result == 0 && oneResult != 0 ) { success = XP_FALSE;
result = oneResult; break;
} }
XP_STATUSF( "%s: msgID=" XP_LD "; rslt=%d", __func__,
msg->msgID, oneResult );
} }
return success;
return result;
} /* comms_resend */ } /* comms_resend */
#ifdef XWFEATURE_RELAY #ifdef XWFEATURE_RELAY
@ -1312,8 +1316,8 @@ relayPreProcess( CommsCtxt* comms, XWStreamCtxt* stream, XWHostID* senderID )
cookieID = stream_getU16( stream ); cookieID = stream_getU16( stream );
srcID = stream_getU8( stream ); srcID = stream_getU8( stream );
destID = stream_getU8( stream ); destID = stream_getU8( stream );
XP_LOGF( "cookieID: %d; srcID: %x; destID: %x", XP_LOGF( "%s: cookieID: %d; srcID: %x; destID: %x",
cookieID, srcID, destID ); __func__, cookieID, srcID, destID );
/* If these values don't check out, drop it */ /* If these values don't check out, drop it */
/* When a message comes in via proxy (rather than a connection) state /* When a message comes in via proxy (rather than a connection) state
@ -1327,8 +1331,9 @@ relayPreProcess( CommsCtxt* comms, XWStreamCtxt* stream, XWHostID* senderID )
if ( destID == comms->r.myHostID ) { /* When would this not happen? */ if ( destID == comms->r.myHostID ) { /* When would this not happen? */
consumed = XP_FALSE; consumed = XP_FALSE;
} else if ( cookieID == comms->r.cookieID ) { } else if ( cookieID == comms->r.cookieID ) {
XP_LOGF( "%s: keeping message though hostID not what expected (%d vs %d)", XP_LOGF( "%s: keeping message though hostID not what "
__func__, destID, comms->r.myHostID ); "expected (%d vs %d)", __func__, destID,
comms->r.myHostID );
consumed = XP_FALSE; consumed = XP_FALSE;
} }
@ -1645,12 +1650,13 @@ comms_checkIncomingStream( CommsCtxt* comms, XWStreamCtxt* stream,
AddressRecord* rec = NULL; AddressRecord* rec = NULL;
connID = stream_getU32( stream ); connID = stream_getU32( stream );
XP_STATUSF( "%s: read connID (gameID) of %lx", __func__, connID ); XP_LOGF( "%s: read connID (gameID) of %lx", __func__, connID );
channelNo = stream_getU16( stream ); channelNo = stream_getU16( stream );
msgID = stream_getU32( stream ); msgID = stream_getU32( stream );
lastMsgRcd = stream_getU32( stream ); lastMsgRcd = stream_getU32( stream );
XP_DEBUGF( "rcd on channelNo %x: msgID=%ld,lastMsgRcd=%ld ", XP_LOGF( "%s: rcd on channelNo %d(%x): msgID=%ld,lastMsgRcd=%ld ",
channelNo, msgID, lastMsgRcd ); __func__, channelNo & CHANNEL_MASK, channelNo,
msgID, lastMsgRcd );
payloadSize = stream_getSize( stream ) > 0; /* anything left? */ payloadSize = stream_getSize( stream ) > 0; /* anything left? */
@ -1666,9 +1672,9 @@ comms_checkIncomingStream( CommsCtxt* comms, XWStreamCtxt* stream,
messageValid = (NULL != rec) messageValid = (NULL != rec)
&& (0 == rec->lastMsgRcd || rec->lastMsgRcd <= msgID); && (0 == rec->lastMsgRcd || rec->lastMsgRcd <= msgID);
if ( messageValid ) { if ( messageValid ) {
XP_LOGF( "got channelNo=%d;msgID=%ld",
channelNo & CHANNEL_MASK, msgID );
rec->lastMsgRcd = msgID; rec->lastMsgRcd = msgID;
XP_LOGF( "%s: set channel %x's lastMsgRcd to " XP_LD,
__func__, channelNo, msgID );
stream_setAddress( stream, channelNo ); stream_setAddress( stream, channelNo );
messageValid = payloadSize > 0; messageValid = payloadSize > 0;
} }
@ -1799,7 +1805,8 @@ p_comms_timerFired( void* closure, XWTimerReason XP_UNUSED_DBG(why) )
#if defined XWFEATURE_RELAY && defined RELAY_HEARTBEAT #if defined XWFEATURE_RELAY && defined RELAY_HEARTBEAT
} else if ( (comms->addr.conType == COMMS_CONN_RELAY ) } else if ( (comms->addr.conType == COMMS_CONN_RELAY )
&& (comms->r.heartbeat != HEARTBEAT_NONE) ) { && (comms->r.heartbeat != HEARTBEAT_NONE) ) {
send_via_relay( comms, XWRELAY_HEARTBEAT, HOST_ID_NONE, NULL, 0 ); (void)send_via_relay( comms, XWRELAY_HEARTBEAT, HOST_ID_NONE,
NULL, 0 );
/* No need to reset timer. send_via_relay does that. */ /* No need to reset timer. send_via_relay does that. */
#endif #endif
#ifdef COMMS_HEARTBEAT #ifdef COMMS_HEARTBEAT
@ -2159,8 +2166,8 @@ relayDisconnect( CommsCtxt* comms )
LOG_FUNC(); LOG_FUNC();
if ( comms->addr.conType == COMMS_CONN_RELAY ) { if ( comms->addr.conType == COMMS_CONN_RELAY ) {
if ( comms->r.relayState > COMMS_RELAYSTATE_CONNECT_PENDING ) { if ( comms->r.relayState > COMMS_RELAYSTATE_CONNECT_PENDING ) {
send_via_relay( comms, XWRELAY_GAME_DISCONNECT, HOST_ID_NONE, (void)send_via_relay( comms, XWRELAY_GAME_DISCONNECT, HOST_ID_NONE,
NULL, 0 ); NULL, 0 );
} }
set_relay_state( comms, COMMS_RELAYSTATE_UNCONNECTED ); set_relay_state( comms, COMMS_RELAYSTATE_UNCONNECTED );
} }

View file

@ -179,7 +179,7 @@ void comms_start( CommsCtxt* comms );
void comms_writeToStream( const CommsCtxt* comms, XWStreamCtxt* stream ); void comms_writeToStream( const CommsCtxt* comms, XWStreamCtxt* stream );
XP_S16 comms_send( CommsCtxt* comms, XWStreamCtxt* stream ); XP_S16 comms_send( CommsCtxt* comms, XWStreamCtxt* stream );
XP_S16 comms_resendAll( CommsCtxt* comms ); XP_Bool comms_resendAll( CommsCtxt* comms );
XP_U16 comms_getChannelSeed( CommsCtxt* comms ); XP_U16 comms_getChannelSeed( CommsCtxt* comms );