add option, off by default, to stall each message forward by some time

to better simulate network conditions when testing against local relay.
This commit is contained in:
eehouse 2010-03-28 16:09:07 +00:00
parent 603462fc33
commit f4b64fe97d
3 changed files with 16 additions and 0 deletions

View file

@ -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 );

View file

@ -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

View file

@ -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