add option to drop incoming packets randomly (rather than 1st, then

2nd, then 3rd etc.)
This commit is contained in:
Andy2 2011-06-20 18:55:57 -07:00
parent aecdd8922f
commit c87df3ce16
3 changed files with 20 additions and 8 deletions

View file

@ -686,10 +686,21 @@ linux_relay_receive( CommonGlobals* cGlobals, unsigned char* buf, int bufSize )
strerror(errno) );
}
if ( cGlobals->params->dropNth > 0 ) {
if ( --cGlobals->params->dropNth == 0 ) {
XP_LOGF( "%s: dropping packet per --drop-nth-packet",
__func__ );
LaunchParams* params = cGlobals->params;
++params->nPacketsRcvd;
if ( params->dropNthRcvd == 0 ) {
/* do nothing */
} else if ( params->dropNthRcvd > 0 ) {
if ( params->nPacketsRcvd == params->dropNthRcvd ) {
XP_LOGF( "%s: dropping %dth packet per --drop-nth-packet",
__func__, params->nPacketsRcvd );
nRead = -1;
}
} else {
if ( 0 == XP_RANDOM() % -params->dropNthRcvd ) {
XP_LOGF( "%s: RANDOMLY dropping %dth packet "
"per --drop-nth-packet",
__func__, params->nPacketsRcvd );
nRead = -1;
}
}
@ -1049,7 +1060,7 @@ main( int argc, char** argv )
mainParams.duplicatePackets = XP_TRUE;
break;
case CMD_DROPNTHPACKET:
mainParams.dropNth = atoi( optarg );
mainParams.dropNthRcvd = atoi( optarg );
break;
case CMD_NOHINTS:
mainParams.gi.hintsNotAllowed = XP_TRUE;

View file

@ -54,7 +54,8 @@ typedef struct LaunchParams {
VTableMgr* vtMgr;
XP_U16 nLocalPlayers;
XP_U16 nHidden;
XP_U16 dropNth;
XP_S16 dropNthRcvd; /* negative means use for random calc */
XP_U16 nPacketsRcvd; /* toward dropNthRcvd */
XP_Bool askNewGame;
XP_S16 quitAfter;
XP_Bool sleepOnAnchor;

View file

@ -10,7 +10,7 @@ DICTS=${DICTS:-dict.xwd}
SAVE_GOOD=${SAVE_GOOD:-YES}
MAXDEVS=${MAXDEVS:-4}
RESIGN_RATIO=${RESIGN_RATIO:-$((NGAMES/3))}
DROP_N=1
DROP_N=${DROP_N:-1}
declare -a DICTS_ARR
for DICT in $DICTS; do
@ -257,7 +257,7 @@ run_cmds() {
sleep 2 # make sure it's had some time
kill ${PIDS[$KEY]} || true
PIDS[$KEY]=0
increment_drop $KEY
[ $DROP_N -ge 0 ] && increment_drop $KEY
check_game $KEY
fi
done