diff --git a/xwords4/relay/cref.cpp b/xwords4/relay/cref.cpp index fe3bab6ad..bea704060 100644 --- a/xwords4/relay/cref.cpp +++ b/xwords4/relay/cref.cpp @@ -1048,34 +1048,37 @@ void CookieRef::forward_or_store( const CRefEvent* evt ) { unsigned char* buf = evt->u.fwd.buf; - int buflen = evt->u.fwd.buflen; - HostID dest = evt->u.fwd.dest; + do { + /* This is an ugly hack!!!! */ + if ( *buf == XWRELAY_MSG_TORELAY ) { + *buf = XWRELAY_MSG_FROMRELAY; + } else if ( *buf == XWRELAY_MSG_TORELAY_NOCONN ) { + *buf = XWRELAY_MSG_FROMRELAY_NOCONN; + } else { + logf( XW_LOGERROR, "%s: got XWRELAY type of %d", __func__, + *buf ); + break; + } - int destSocket = SocketForHost( dest ); + int buflen = evt->u.fwd.buflen; + HostID dest = evt->u.fwd.dest; + int destSocket = SocketForHost( dest ); - /* This is an ugly hack!!!! */ - if ( *buf == XWRELAY_MSG_TORELAY ) { - *buf = XWRELAY_MSG_FROMRELAY; - } else if ( *buf == XWRELAY_MSG_TORELAY_NOCONN ) { - *buf = XWRELAY_MSG_FROMRELAY_NOCONN; - } else { - assert( 0 ); /* don't ship this */ - } + if ( 0 < m_delayMicros && destSocket != -1 ) { + usleep( m_delayMicros ); + } - if ( 0 < m_delayMicros && destSocket != -1 ) { - usleep( m_delayMicros ); - } + if ( (destSocket == -1) + || !send_with_length( destSocket, buf, buflen, true ) ) { + store_message( dest, buf, buflen ); + } - if ( (destSocket == -1) - || !send_with_length( destSocket, buf, buflen, true ) ) { - store_message( dest, buf, buflen ); - } - - /* also note that we've heard from src recently */ + /* also note that we've heard from src recently */ #ifdef RELAY_HEARTBEAT - HostID src = evt->u.fwd.src; - pushHeartbeatEvent( src, SocketForHost(src) ); + HostID src = evt->u.fwd.src; + pushHeartbeatEvent( src, SocketForHost(src) ); #endif + } while ( 0 ); } /* forward_or_store */ void