merge with upstream/master

pull/11/head
Boian Bonev 13 years ago
commit 2d1aaf5fd2

@ -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 Thu Apr 26 2012
David Schweikert <david@schweikert.ch> David Schweikert <david@schweikert.ch>
- Revision v3.1 - Revision v3.1

@ -2584,25 +2584,20 @@ char * sprint_tm( int t )
void u_sleep( int u_sec ) void u_sleep( int u_sec )
{ {
int nfound; int nfound;
struct timeval to, tokeep; struct timeval to;
fd_set readset, writeset; fd_set readset, writeset;
select_again:
to.tv_sec = u_sec / 1000000; to.tv_sec = u_sec / 1000000;
to.tv_usec = u_sec - ( to.tv_sec * 1000000 ); to.tv_usec = u_sec - ( to.tv_sec * 1000000 );
tokeep = to;
FD_ZERO( &readset ); FD_ZERO( &readset );
FD_ZERO( &writeset ); FD_ZERO( &writeset );
select_again:
nfound = select( 0, &readset, &writeset, NULL, &to ); nfound = select( 0, &readset, &writeset, NULL, &to );
if(nfound < 0) { if(nfound < 0) {
if(errno == EINTR) { if(errno == EINTR) {
/* interrupted system call: redo the select */ /* interrupted system call: redo the select */
to = tokeep;
FD_ZERO( &readset );
FD_ZERO( &writeset );
goto select_again; goto select_again;
} }
else { else {
@ -2637,36 +2632,32 @@ int recvfrom_wto( int s, char *buf, int len, FPING_SOCKADDR *saddr, long timo )
{ {
unsigned int slen; unsigned int slen;
int nfound, n; int nfound, n;
struct timeval to, tokeep; struct timeval to;
fd_set readset, writeset; fd_set readset, writeset;
to.tv_sec = 0; select_again:
to.tv_usec = timo * 10; if(timo < 100000) {
while (to.tv_usec > 1000000) { to.tv_sec = 0;
to.tv_sec++; to.tv_usec = timo * 10;
to.tv_usec -= 1000000; }
else {
to.tv_sec = timo / 100000 ;
to.tv_usec = (timo % 100000) * 10 ;
} }
tokeep = to;
FD_ZERO( &readset ); FD_ZERO( &readset );
FD_ZERO( &writeset ); FD_ZERO( &writeset );
FD_SET( s, &readset ); FD_SET( s, &readset );
select_again:
nfound = select( s + 1, &readset, &writeset, NULL, &to ); nfound = select( s + 1, &readset, &writeset, NULL, &to );
if(nfound < 0) { if(nfound < 0) {
if(errno == EINTR) { if(errno == EINTR) {
/* interrupted system call: redo the select */ /* interrupted system call: redo the select */
to = tokeep; goto select_again;
}
FD_ZERO( &readset ); else {
FD_ZERO( &writeset ); errno_crash_and_burn( "select" );
FD_SET( s, &readset ); }
goto select_again;
}
else {
errno_crash_and_burn( "select" );
}
} }
if( nfound == 0 ) if( nfound == 0 )

Loading…
Cancel
Save