From a7b99fc46339d0c3e1f2c095df371a7c88ed7907 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 27 Jun 2004 21:51:54 +0000 Subject: [PATCH] check for a fine poll() before it is used to sleep subsecond --- CHANGES | 15 +++++++++++++++ configure.ac | 25 +++++++++++++++++++++++++ src/config.h.in | 3 +++ src/main.c | 4 ++-- 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 9f230f0c9..708cf8ff5 100644 --- a/CHANGES +++ b/CHANGES @@ -6,6 +6,21 @@ Changelog +Daniel (27 June 2004) +- Based on Bob's bug report #979480, I wrote a configure check that checks if + poll() can be used to wait on NULL as otherwise select() should be used to + do it. The select() usage was also fixed according to his report. + + Mac OS X 10.3 says "poll() functionality for Mac OS X is implemented via an + emulation layer on top of select(), not in the kernel directly. It is + recommended that programs running under OS X 10.3 prefer select() over + poll(). Configure scripts should look for the _POLL_EMUL_H_ define (instead + of _POLL_H_ or _SYS_POLL_H_) and avoid implementations where poll is not + implemented in the kernel." + + Yes, we can probably use select() on most platforms but today I prefered to + leave the code unaltered. + Daniel (24 June 2004) - The standard curl_version() string now only includes version info about involved libraries and not about particular features. Thus it will no longer diff --git a/configure.ac b/configure.ac index 63aa48493..29d31bd47 100644 --- a/configure.ac +++ b/configure.ac @@ -1201,6 +1201,31 @@ if test "$ac_cv_func_sigsetjmp" != "yes"; then ) fi +dnl poll() might be badly emulated, as in Mac OS X 10.3 (and other BSDs?) and +dnl to find out we make an extra check here! +if test "$ac_cv_func_poll" = "yes"; then + AC_MSG_CHECKING([if poll works with NULL inputs]) + AC_RUN_IFELSE([ +#ifdef HAVE_SYS_POLL_H +#include +#endif + + int main(void) + { + /* make this return 0 == timeout since there's nothing to read from */ + return poll((void *)0, 0, 10 /*ms*/); + } +], + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_POLL_FINE, 1, [If you have a fine poll]), + AC_MSG_RESULT(no), + AC_MSG_RESULT(cross-compiling assumes yes) + AC_DEFINE(HAVE_POLL_FINE, 1, [If you have a fine poll]) + ) dnl end of AC_RUN_IFELSE +fi + + + AC_PATH_PROG( PERL, perl, , $PATH:/usr/local/bin/perl:/usr/bin/:/usr/local/bin ) AC_SUBST(PERL) diff --git a/src/config.h.in b/src/config.h.in index ca36f2b3f..7c5a957db 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -35,6 +35,9 @@ /* Define if you have the `poll' function. */ #undef HAVE_POLL +/* Define if you have a good `poll' function that can wait on NULL. */ +#undef HAVE_POLL_FINE + /* Define if you can write to argc[] strings */ #undef HAVE_WRITABLE_ARGV diff --git a/src/main.c b/src/main.c index 0a5624ba1..126fa4af0 100644 --- a/src/main.c +++ b/src/main.c @@ -2243,7 +2243,7 @@ static void parseconfig(const char *filename, static void go_sleep(long ms) { -#ifdef HAVE_POLL +#ifdef HAVE_POLL_FINE /* portable subsecond "sleep" */ poll((void *)0, 0, ms); #else @@ -2259,7 +2259,7 @@ static void go_sleep(long ms) struct timeval timeout; timeout.tv_sec = ms/1000; - ms -= ms/1000; + ms = ms%1000; timeout.tv_usec = ms * 1000; select(0, NULL, NULL, NULL, &timeout);