]> granicus.if.org Git - curl/commitdiff
check for a fine poll() before it is used to sleep subsecond
authorDaniel Stenberg <daniel@haxx.se>
Sun, 27 Jun 2004 21:51:54 +0000 (21:51 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Sun, 27 Jun 2004 21:51:54 +0000 (21:51 +0000)
CHANGES
configure.ac
src/config.h.in
src/main.c

diff --git a/CHANGES b/CHANGES
index 9f230f0c93f2b3237f48a3ea80faadc0a1a7c8bb..708cf8ff5315f20449d234de0ff4d684a714ae40 100644 (file)
--- 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
index 63aa48493018091acbd526027aa0bb7b80051f60..29d31bd47d287b14d02e4282a6d3ea4af8efa67b 100644 (file)
@@ -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 <sys/poll.h>
+#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)
index ca36f2b3f9057d2651d7ffd6a4240756a7d988ce..7c5a957db69a6019982bfc27cbc651578fdce2cb 100644 (file)
@@ -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
 
index 0a5624ba13a7e39e2914948d5619e574f849befd..126fa4af0ad8d139fcfc61021dfc4f898ae23199 100644 (file)
@@ -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);