diff --git a/xwords4/relay/cref.cpp b/xwords4/relay/cref.cpp index fecc451a0..870522227 100644 --- a/xwords4/relay/cref.cpp +++ b/xwords4/relay/cref.cpp @@ -96,6 +96,12 @@ CookieRef::ReInit( const char* cookie, const char* connName, CookieID id ) m_nHostMsgs = 0; m_in_handleEvents = false; + if ( RelayConfigs::GetConfigs()->GetValueFor( "SEND_DELAY_MILLIS", + &m_delayMicros ) ) { + m_delayMicros *= 1000; /* millis->micros */ + } else { + m_delayMicros = 0; + } RelayConfigs::GetConfigs()->GetValueFor( "HEARTBEAT", &m_heatbeat ); logf( XW_LOGINFO, "initing cref for cookie %s, connName %s", m_cookie.c_str(), m_connName.c_str() ); @@ -882,6 +888,10 @@ CookieRef::forward_or_store( const CRefEvent* evt ) /* This is an ugly hack!!!! */ *buf = XWRELAY_MSG_FROMRELAY; + if ( 0 < m_delayMicros && destSocket != -1 ) { + usleep( m_delayMicros ); + } + if ( (destSocket == -1) || !send_with_length( destSocket, buf, buflen, true ) ) { store_message( dest, buf, buflen ); diff --git a/xwords4/relay/cref.h b/xwords4/relay/cref.h index 2db8092c7..509040c19 100644 --- a/xwords4/relay/cref.h +++ b/xwords4/relay/cref.h @@ -256,6 +256,8 @@ class CookieRef { pthread_t m_locking_thread; /* for debugging only */ bool m_in_handleEvents; /* for debugging only */ + + int m_delayMicros; }; /* CookieRef */ #endif diff --git a/xwords4/relay/xwrelay.conf b/xwords4/relay/xwrelay.conf index 7281af01a..a39ef739b 100644 --- a/xwords4/relay/xwrelay.conf +++ b/xwords4/relay/xwrelay.conf @@ -42,3 +42,7 @@ SERVERNAME=eehouse.org # 0 means errors only, 1 info, 2 verbose and 3 very verbose. LOGLEVEL=0 LOGFILE_PATH=./xwrelay.log + +# Delay sending packets so devices/emulators on the same machine as +# relay have a bit more natural experience +# SEND_DELAY_MILLIS=500