From 7e09a0cabbc18ed9a55c2a9f762eb064aa097746 Mon Sep 17 00:00:00 2001 From: Boian Bonev Date: Mon, 21 May 2012 17:54:22 +0300 Subject: [PATCH] unify the timeout calculations before select --- src/fping.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/fping.c b/src/fping.c index 3d18554..bc502d6 100644 --- a/src/fping.c +++ b/src/fping.c @@ -2588,8 +2588,14 @@ void u_sleep( int u_sec ) fd_set readset, writeset; select_again: - to.tv_sec = u_sec / 1000000; - to.tv_usec = u_sec - ( to.tv_sec * 1000000 ); + if(u_sec < 1000000) { + to.tv_sec = 0; + to.tv_usec = u_sec; + } + else { + to.tv_sec = u_sec / 1000000 ; + to.tv_usec = u_sec - ( to.tv_sec * 1000000 ); + } FD_ZERO( &readset ); FD_ZERO( &writeset ); @@ -2642,7 +2648,7 @@ select_again: } else { to.tv_sec = timo / 100000 ; - to.tv_usec = (timo % 100000) * 10 ; + to.tv_usec = ( timo - ( to.tv_sec * 100000 ) ) * 10 ; } FD_ZERO( &readset );