From 74066a00ea229a06318654dc456d79a9b5dfbb89 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Mon, 21 May 2012 14:56:01 +0200 Subject: [PATCH 1/2] Performance optimization for big select timeouts (#10, Andrey Bondarenko), Fix restart of select call after interrupt signal (#8, Boian Bonev) --- ChangeLog | 4 ++++ src/fping.c | 16 +++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index c04274e..2186074 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Unreleased + * Performance optimization for big select timeouts (#10, Andrey Bondarenko) + * Fix restart of select call after interrupt signal (#8, Boian Bonev) + Thu Apr 26 2012 David Schweikert - Revision v3.1 diff --git a/src/fping.c b/src/fping.c index 464193d..3af42e6 100644 --- a/src/fping.c +++ b/src/fping.c @@ -2587,13 +2587,13 @@ void u_sleep( int u_sec ) struct timeval to; fd_set readset, writeset; +select_again: to.tv_sec = u_sec / 1000000; to.tv_usec = u_sec - ( to.tv_sec * 1000000 ); FD_ZERO( &readset ); FD_ZERO( &writeset ); -select_again: nfound = select( 0, &readset, &writeset, NULL, &to ); if(nfound < 0) { if(errno == EINTR) { @@ -2635,18 +2635,20 @@ int recvfrom_wto( int s, char *buf, int len, FPING_SOCKADDR *saddr, long timo ) struct timeval to; fd_set readset, writeset; - to.tv_sec = 0; - to.tv_usec = timo * 10; - while (to.tv_usec > 1000000) { - to.tv_sec++; - to.tv_usec -= 1000000; +select_again: + if(timo < 100000) { + to.tv_sec = 0; + to.tv_usec = timo * 10; + } + else { + to.tv_sec = timo / 100000 ; + to.tv_usec = (timo % 100000) * 10 ; } FD_ZERO( &readset ); FD_ZERO( &writeset ); FD_SET( s, &readset ); -select_again: nfound = select( s + 1, &readset, &writeset, NULL, &to ); if(nfound < 0) { if(errno == EINTR) { From ecaca317d7001f0feb8c7f071db5f98f8f1b8186 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Mon, 21 May 2012 15:03:33 +0200 Subject: [PATCH 2/2] trivial: fix indenting --- src/fping.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/fping.c b/src/fping.c index 3af42e6..3d18554 100644 --- a/src/fping.c +++ b/src/fping.c @@ -2637,12 +2637,12 @@ int recvfrom_wto( int s, char *buf, int len, FPING_SOCKADDR *saddr, long timo ) select_again: if(timo < 100000) { - to.tv_sec = 0; - to.tv_usec = timo * 10; + to.tv_sec = 0; + to.tv_usec = timo * 10; } else { - to.tv_sec = timo / 100000 ; - to.tv_usec = (timo % 100000) * 10 ; + to.tv_sec = timo / 100000 ; + to.tv_usec = (timo % 100000) * 10 ; } FD_ZERO( &readset ); @@ -2651,13 +2651,13 @@ select_again: nfound = select( s + 1, &readset, &writeset, NULL, &to ); if(nfound < 0) { - if(errno == EINTR) { - /* interrupted system call: redo the select */ - goto select_again; - } - else { - errno_crash_and_burn( "select" ); - } + if(errno == EINTR) { + /* interrupted system call: redo the select */ + goto select_again; + } + else { + errno_crash_and_burn( "select" ); + } } if( nfound == 0 )