From 8e31a3c5cb2130b4106aa1b9f0f3afbfd1f8f13a Mon Sep 17 00:00:00 2001 From: ehouse Date: Fri, 6 Mar 2009 13:43:03 +0000 Subject: [PATCH] Close down relay connection when comms going away. Fixes crashes when new game is standalone and prev used relay. Add logging code in comms. --- common/comms.c | 16 ++++++++++++++++ common/comms.h | 1 + wince/cemain.c | 20 +++++++++++++++++--- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/common/comms.c b/common/comms.c index b539645c8..877910c05 100644 --- a/common/comms.c +++ b/common/comms.c @@ -1006,6 +1006,22 @@ relayCmdToStr( XWRELAY_Cmd cmd ) default: return ""; } } + +const char* +ConnType2Str( CommsConnType typ ) +{ + switch( typ ) { + CASESTR(COMMS_CONN_NONE); + CASESTR( COMMS_CONN_IR ); + CASESTR( COMMS_CONN_IP_DIRECT ); + CASESTR( COMMS_CONN_RELAY ); + CASESTR( COMMS_CONN_BT ); + CASESTR( COMMS_CONN_SMS ); + default: + XP_ASSERT(0); + } + return ""; +} # else # define relayCmdToStr( cmd ) # endif diff --git a/common/comms.h b/common/comms.h index c4250bad8..00ce912bd 100644 --- a/common/comms.h +++ b/common/comms.h @@ -143,6 +143,7 @@ XP_Bool comms_checkIncomingStream( CommsCtxt* comms, XWStreamCtxt* stream, # ifdef DEBUG void comms_getStats( CommsCtxt* comms, XWStreamCtxt* stream ); +const char* ConnType2Str( CommsConnType typ ); # endif EXTERN_C_END diff --git a/wince/cemain.c b/wince/cemain.c index c638440ca..5550a9949 100755 --- a/wince/cemain.c +++ b/wince/cemain.c @@ -3375,10 +3375,24 @@ ce_util_remSelected( XW_UtilCtxt* uc ) #ifndef XWFEATURE_STANDALONE_ONLY static void -ce_util_addrChange( XW_UtilCtxt* XP_UNUSED(uc), - const CommsAddrRec* XP_UNUSED(oldAddr), - const CommsAddrRec* XP_UNUSED(newAddr) ) +ce_util_addrChange( XW_UtilCtxt* uc, + const CommsAddrRec* oldAddr, + const CommsAddrRec* newAddr ) { + CEAppGlobals* globals = (CEAppGlobals*)uc->closure; + + XP_LOGF( "%s: old: %s -> new: %s", __func__, + ConnType2Str( oldAddr->conType ), + ConnType2Str( newAddr->conType ) ); + + /* A lot more needs to be tested for and done here... */ + if ( COMMS_CONN_NONE == newAddr->conType ) { + if ( !!globals->socketWrap ) { + ce_sockwrap_delete( globals->socketWrap ); + globals->socketWrap = NULL; + } + } + XP_LOGF( "ce_util_addrChange called; DO SOMETHING." ); } /* ce_util_addrChange */ #endif