cleanup comms

This commit is contained in:
Eric House 2023-03-25 10:23:41 -07:00
parent 9cd8264e12
commit 7929ddea47

View file

@ -489,8 +489,7 @@ testQueues( CommsCtxt* comms, XWEnv xwe )
for ( int ii = 0; ii < VSIZE(elems); ++ii ) { for ( int ii = 0; ii < VSIZE(elems); ++ii ) {
XP_PlayerAddr channelNo = 0; XP_PlayerAddr channelNo = 0;
MsgQueueElem* elem = makeNewElem( comms, xwe, ii + 1, channelNo ); MsgQueueElem* elem = makeNewElem( comms, xwe, ii + 1, channelNo );
addToQueue( comms, xwe, elem, XP_FALSE ); elems[ii] = addToQueue( comms, xwe, elem, XP_FALSE );
elems[ii] = elem;
} }
XP_ASSERT( comms->queueLen == startLen + VSIZE(elems) ); XP_ASSERT( comms->queueLen == startLen + VSIZE(elems) );
@ -1023,7 +1022,7 @@ comms_makeFromStream( MPFORMAL XWEnv xwe, XWStreamCtxt* stream,
msg->checksum = dutil_md5sum( comms->dutil, xwe, msg->msg, len ); msg->checksum = dutil_md5sum( comms->dutil, xwe, msg->msg, len );
#endif #endif
XP_ASSERT( NULL == msg->next ); XP_ASSERT( NULL == msg->next );
addToQueue( comms, xwe, msg, XP_FALSE ); (void)addToQueue( comms, xwe, msg, XP_FALSE );
} }
XP_ASSERT( queueLen == comms->queueLen ); XP_ASSERT( queueLen == comms->queueLen );
@ -1740,16 +1739,18 @@ comms_invite( CommsCtxt* comms, XWEnv xwe, const NetLaunchInfo* nli,
MsgQueueElem* elem = makeInviteElem( comms, xwe, forceChannel, nli ); MsgQueueElem* elem = makeInviteElem( comms, xwe, forceChannel, nli );
elem = addToQueue( comms, xwe, elem, XP_TRUE ); elem = addToQueue( comms, xwe, elem, XP_TRUE );
if ( !!elem ) {
XP_LOGFF( "added invite on channel %d", elem->channelNo & CHANNEL_MASK ); XP_LOGFF( "added invite on channel %d", elem->channelNo & CHANNEL_MASK );
/* Let's let platform code decide whether to call sendMsg() . On /* Let's let platform code decide whether to call sendMsg() . On
Android creating a game with an invitation in its queue is always Android creating a game with an invitation in its queue is always
followed by opening the game, which results in comms_resendAll() followed by opening the game, which results in comms_resendAll()
getting called leading to a second send immediately after this. So getting called leading to a second send immediately after this. So
let Android drop it. Linux, though, needs it for now. */ let Android drop it. Linux, though, needs it for now. */
if ( sendNow && !!comms->procs.sendInvt ) { if ( sendNow && !!elem && !!comms->procs.sendInvt ) {
sendMsg( comms, xwe, elem, COMMS_CONN_NONE ); sendMsg( comms, xwe, elem, COMMS_CONN_NONE );
} }
} }
}
LOG_RETURN_VOID(); LOG_RETURN_VOID();
} }
@ -1812,10 +1813,12 @@ comms_send( CommsCtxt* comms, XWEnv xwe, XWStreamCtxt* stream )
elem = makeElemWithID( comms, xwe, msgID, rec, channelNo, stream ); elem = makeElemWithID( comms, xwe, msgID, rec, channelNo, stream );
if ( NULL != elem ) { if ( NULL != elem ) {
elem = addToQueue( comms, xwe, elem, XP_TRUE ); elem = addToQueue( comms, xwe, elem, XP_TRUE );
if ( !!elem ) {
printQueue( comms ); printQueue( comms );
result = sendMsg( comms, xwe, elem, COMMS_CONN_NONE ); result = sendMsg( comms, xwe, elem, COMMS_CONN_NONE );
} }
} }
}
THREAD_CHECK_END(); THREAD_CHECK_END();
return result; return result;
} /* comms_send */ } /* comms_send */
@ -1843,6 +1846,12 @@ addToQueue( CommsCtxt* comms, XWEnv xwe, MsgQueueElem* newElem, XP_Bool notify )
MsgQueueElem** head; MsgQueueElem** head;
#ifdef MSGS_IN_CHANNEL #ifdef MSGS_IN_CHANNEL
AddressRecord* rec = getRecordFor( comms, newElem->channelNo ); AddressRecord* rec = getRecordFor( comms, newElem->channelNo );
XP_ASSERT( !!rec ); /* I've seen this once on an old game */
if ( !rec ) {
freeElem( MPPARM(comms->mpool) newElem );
asAdded = NULL;
goto dropPacket;
}
head = &rec->_msgQueueHead; head = &rec->_msgQueueHead;
#else #else
head = &comms->_msgQueueHead; head = &comms->_msgQueueHead;
@ -1874,6 +1883,9 @@ addToQueue( CommsCtxt* comms, XWEnv xwe, MsgQueueElem* newElem, XP_Bool notify )
notifyQueueChanged( comms, xwe ); notifyQueueChanged( comms, xwe );
} }
} }
#ifdef MSGS_IN_CHANNEL
dropPacket:
#endif
XP_ASSERT( comms->queueLen <= 128 ); /* reasonable limit in testing */ XP_ASSERT( comms->queueLen <= 128 ); /* reasonable limit in testing */
THREAD_CHECK_END(); THREAD_CHECK_END();
return asAdded; return asAdded;
@ -1911,7 +1923,6 @@ _assertQueueOk( const CommsCtxt* comms, const char* func )
XP_LOGFF( "(func=%s)", func ); XP_LOGFF( "(func=%s)", func );
XP_U16 count = 0; XP_U16 count = 0;
#ifdef MSGS_IN_CHANNEL #ifdef MSGS_IN_CHANNEL
for ( AddressRecord* recs = comms->recs; !!recs; recs = recs->next ) { for ( AddressRecord* recs = comms->recs; !!recs; recs = recs->next ) {
for ( MsgQueueElem* elem = recs->_msgQueueHead; !!elem; elem = elem->next ) { for ( MsgQueueElem* elem = recs->_msgQueueHead; !!elem; elem = elem->next ) {
@ -1924,7 +1935,10 @@ _assertQueueOk( const CommsCtxt* comms, const char* func )
++count; ++count;
} }
#endif #endif
XP_ASSERT( count == comms->queueLen ); if ( count != comms->queueLen ) {
XP_LOGFF( "count(%d) != comms->queueLen(%d)", count, comms->queueLen );
XP_ASSERT(0);
}
if ( count >= 10 ) { if ( count >= 10 ) {
XP_LOGFF( "queueLen unexpectedly high: %d", count ); XP_LOGFF( "queueLen unexpectedly high: %d", count );
} }