From 31e1a46087000423983092bedf2f2a70a465a07e Mon Sep 17 00:00:00 2001 From: ehouse Date: Sun, 3 Apr 2005 17:00:59 +0000 Subject: [PATCH] separate internalization of comms from call to connect to relay since the first must finish before the caller will have a valid reference to comms. call util_addrChange. --- xwords4/common/comms.c | 16 +++++++++++----- xwords4/common/comms.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/xwords4/common/comms.c b/xwords4/common/comms.c index 44fe2b5e7..d5ba650d7 100644 --- a/xwords4/common/comms.c +++ b/xwords4/common/comms.c @@ -317,12 +317,18 @@ comms_makeFromStream( MPFORMAL XWStreamCtxt* stream, XW_UtilCtxt* util, XP_ASSERT( stream_getU32( stream ) == cEND ); #endif - comms->relayState = COMMS_RELAYSTATE_UNCONNECTED; - comms_relayConnect( comms ); - return comms; } /* comms_makeFromStream */ +void +comms_init( CommsCtxt* comms ) +{ + if ( comms->addr.conType == COMMS_CONN_RELAY ) { + comms->relayState = COMMS_RELAYSTATE_UNCONNECTED; + comms_relayConnect( comms ); + } +} + static void addrToStream( XWStreamCtxt* stream, CommsAddrRec* addrP ) { @@ -434,10 +440,10 @@ comms_getInitialAddr( CommsAddrRec* addr ) void comms_setAddr( CommsCtxt* comms, CommsAddrRec* addr ) { - XP_MEMCPY( &comms->addr, addr, sizeof(comms->addr) ); #ifdef BEYOND_IR -/* util_listenPortChange( comms->util, listenPort ); */ + util_addrChange( comms->util, &comms->addr, addr ); #endif + XP_MEMCPY( &comms->addr, addr, sizeof(comms->addr) ); /* We should now have a cookie so we can connect??? */ comms_relayConnect( comms ); diff --git a/xwords4/common/comms.h b/xwords4/common/comms.h index 04cd41be4..378dbc2a7 100644 --- a/xwords4/common/comms.h +++ b/xwords4/common/comms.h @@ -92,6 +92,7 @@ CommsConnType comms_getConType( CommsCtxt* comms ); CommsCtxt* comms_makeFromStream( MPFORMAL XWStreamCtxt* stream, XW_UtilCtxt* util, TransportSend sendproc, void* closure ); +void comms_init( CommsCtxt* comms ); void comms_writeToStream( CommsCtxt* comms, XWStreamCtxt* stream ); XP_S16 comms_send( CommsCtxt* comms, XWStreamCtxt* stream );