unset(CMAKE_TRY_COMPILE_TARGET_TYPE)
-if(NOT APPLE)
- set(_source_epilogue "#undef inline")
- add_header_include(HAVE_SYS_POLL_H "sys/poll.h")
- add_header_include(HAVE_POLL_H "poll.h")
- if(NOT CMAKE_CROSSCOMPILING)
- check_c_source_runs("${_source_epilogue}
- #include <stdlib.h>
- int main(void)
- {
- if(0 != poll(0, 0, 10)) {
- return 1; /* fail */
- }
- return 0;
- }" HAVE_POLL_FINE)
- elseif(UNIX)
- check_c_source_compiles("${_source_epilogue}
- #include <stdlib.h>
- int main(void)
- {
- #if defined(__BIONIC__) || \
- defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L
- (void)poll(0, 0, 0);
- #else
- #error force compilation error
- #endif
- }" HAVE_POLL_FINE)
- endif()
-endif()
-
# Detect HAVE_GETADDRINFO_THREADSAFE
if(WIN32)
set(HAVE_NET_IF_H 0)
set(HAVE_IOCTL_SIOCGIFADDR 0)
set(HAVE_POLL_H 0)
-set(HAVE_POLL_FINE 0)
+set(HAVE_POLL 0)
set(HAVE_PWD_H 0)
set(HAVE_SYS_EVENTFD_H 0)
set(HAVE_SYS_FILIO_H 0)
check_symbol_exists("fnmatch" "${CURL_INCLUDES};fnmatch.h" HAVE_FNMATCH)
check_symbol_exists("basename" "${CURL_INCLUDES};string.h" HAVE_BASENAME)
check_symbol_exists("opendir" "${CURL_INCLUDES};dirent.h" HAVE_OPENDIR)
+check_symbol_exists("poll" "${CURL_INCLUDES}" HAVE_POLL)
check_symbol_exists("socket" "${CURL_INCLUDES}" HAVE_SOCKET)
check_symbol_exists("sched_yield" "${CURL_INCLUDES};sched.h" HAVE_SCHED_YIELD)
check_symbol_exists("socketpair" "${CURL_INCLUDES}" HAVE_SOCKETPAIR)
if_nametoindex \
mach_absolute_time \
pipe \
+ poll \
sched_yield \
sendmsg \
sendmmsg \
#define USE_OPENSSL 1
#define HAVE_PIPE 1
-#define HAVE_POLL_FINE 1
+#define HAVE_POLL 1
#define HAVE_POLL_H 1
#define HAVE_PTHREAD_H 1
#define HAVE_SETLOCALE 1
/* Define to 1 if you have the `eventfd' function. */
#cmakedefine HAVE_EVENTFD 1
-/* If you have a fine poll */
-#cmakedefine HAVE_POLL_FINE 1
+/* If you have poll */
+#cmakedefine HAVE_POLL 1
/* Define to 1 if you have the <poll.h> header file. */
#cmakedefine HAVE_POLL_H 1
#include "curl_setup.h"
+#if !defined(HAVE_SELECT) && !defined(HAVE_POLL)
+#error "We cannot compile without select() or poll() support."
+#endif
+
#include <limits.h>
#ifdef HAVE_SYS_SELECT_H
#include <unistd.h>
#endif
-#if !defined(HAVE_SELECT) && !defined(HAVE_POLL_FINE)
-#error "We cannot compile without select() or poll() support."
-#endif
-
#ifdef MSDOS
#include <dos.h> /* delay() */
#endif
#include "memdebug.h"
/*
- * Internal function used for waiting a specific amount of ms
- * in Curl_socket_check() and Curl_poll() when no file descriptor
- * is provided to wait on, just being used to delay execution.
- * Winsock select() and poll() timeout mechanisms need a valid
- * socket descriptor in a not null file descriptor set to work.
- * Waiting indefinitely with this function is not allowed, a
- * zero or negative timeout value will return immediately.
- * Timeout resolution, accuracy, as well as maximum supported
- * value is system dependent, neither factor is a critical issue
- * for the intended use of this function in the library.
+ * Internal function used for waiting a specific amount of ms in
+ * Curl_socket_check() and Curl_poll() when no file descriptor is provided to
+ * wait on, just being used to delay execution. Winsock select() and poll()
+ * timeout mechanisms need a valid socket descriptor in a not null file
+ * descriptor set to work. Waiting indefinitely with this function is not
+ * allowed, a zero or negative timeout value will return immediately. Timeout
+ * resolution, accuracy, as well as maximum supported value is system
+ * dependent, neither factor is a critical issue for the intended use of this
+ * function in the library.
*
* Return values:
* -1 = system call error, or invalid timeout value
#endif
Sleep((ULONG)timeout_ms);
#else
-#if defined(HAVE_POLL_FINE)
- /* prevent overflow, timeout_ms is typecast to int. */
-#if TIMEDIFF_T_MAX > INT_MAX
- if(timeout_ms > INT_MAX)
- timeout_ms = INT_MAX;
-#endif
- r = poll(NULL, 0, (int)timeout_ms);
-#else
+ /* avoid using poll() for this since it behaves incorrectly with no sockets
+ on Apple operating systems */
{
struct timeval pending_tv;
r = select(0, NULL, NULL, NULL, curlx_mstotv(&pending_tv, timeout_ms));
}
-#endif /* HAVE_POLL_FINE */
-#endif /* USE_WINSOCK */
+#endif /* _WIN32 */
if(r) {
if((r == -1) && (SOCKERRNO == EINTR))
/* make EINTR from select or poll not a "lethal" error */
return r;
}
-#ifndef HAVE_POLL_FINE
+#ifndef HAVE_POLL
/*
- * This is a wrapper around select() to aid in Windows compatibility.
- * A negative timeout value makes this function wait indefinitely,
- * unless no valid file descriptor is given, when this happens the
- * negative timeout is ignored and the function times out immediately.
+ * This is a wrapper around select() to aid in Windows compatibility. A
+ * negative timeout value makes this function wait indefinitely, unless no
+ * valid file descriptor is given, when this happens the negative timeout is
+ * ignored and the function times out immediately.
*
* Return values:
* -1 = system call error or fd >= FD_SETSIZE
/*
* Wait for read or write events on a set of file descriptors. It uses poll()
- * when a fine poll() is available, in order to avoid limits with FD_SETSIZE,
+ * when poll() is available, in order to avoid limits with FD_SETSIZE,
* otherwise select() is used. An error is returned if select() is being used
* and a file descriptor is too large for FD_SETSIZE.
*
- * A negative timeout value makes this function wait indefinitely,
- * unless no valid file descriptor is given, when this happens the
- * negative timeout is ignored and the function times out immediately.
+ * A negative timeout value makes this function wait indefinitely, unless no
+ * valid file descriptor is given, when this happens the negative timeout is
+ * ignored and the function times out immediately.
*
* Return values:
* -1 = system call error or fd >= FD_SETSIZE
*/
int Curl_poll(struct pollfd ufds[], unsigned int nfds, timediff_t timeout_ms)
{
-#ifdef HAVE_POLL_FINE
+#ifdef HAVE_POLL
int pending_ms;
#else
fd_set fds_read;
when function is called with a zero timeout or a negative timeout
value indicating a blocking call should be performed. */
-#ifdef HAVE_POLL_FINE
+#ifdef HAVE_POLL
/* prevent overflow, timeout_ms is typecast to int. */
#if TIMEDIFF_T_MAX > INT_MAX
ufds[i].revents |= POLLIN|POLLOUT;
}
-#else /* HAVE_POLL_FINE */
+#else /* HAVE_POLL */
FD_ZERO(&fds_read);
FD_ZERO(&fds_write);
r++;
}
-#endif /* HAVE_POLL_FINE */
+#endif /* HAVE_POLL */
return r;
}
tst_links_poll="unknown"
tst_proto_poll="unknown"
tst_compi_poll="unknown"
- tst_works_poll="unknown"
- tst_allow_poll="unknown"
- #
- case $host in
- *-apple-*|*-*-interix*)
- dnl poll() does not work on these platforms
- dnl Interix: "does provide poll(), but the implementing developer must
- dnl have been in a bad mood, because poll() only works on the /proc
- dnl filesystem here"
- dnl macOS: poll() first didn't exist, then was broken until fixed in 10.9
- dnl only to break again in 10.12.
- curl_disallow_poll="yes"
- tst_compi_poll="no"
- ;;
- esac
#
AC_MSG_CHECKING([if poll can be linked])
AC_LINK_IFELSE([
],[
AC_MSG_RESULT([yes])
tst_compi_poll="yes"
+ AC_DEFINE_UNQUOTED(HAVE_POLL, 1, [If you have poll])
],[
AC_MSG_RESULT([no])
tst_compi_poll="no"
])
fi
#
- dnl only do runtime verification when not cross-compiling
- if test "$tst_compi_poll" = "yes"; then
- if test "x$cross_compiling" != "xyes"; then
- AC_MSG_CHECKING([if poll seems to work])
- CURL_RUN_IFELSE([
- AC_LANG_PROGRAM([[
- $curl_includes_stdlib
- $curl_includes_poll
- ]],[[
- /* detect the original poll() breakage */
- if(0 != poll(0, 0, 10)) {
- return 1; /* fail */
- }
- ]])
- ],[
- AC_MSG_RESULT([yes])
- tst_works_poll="yes"
- ],[
- AC_MSG_RESULT([no])
- tst_works_poll="no"
- ])
- else
- AC_MSG_CHECKING([if native poll seems to be supported])
- AC_COMPILE_IFELSE([
- AC_LANG_PROGRAM([[
- $curl_includes_stdlib
- ]],[[
- #if defined(__BIONIC__) || \
- (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L)
- return 0;
- #else
- #error force compilation error
- #endif
- ]])
- ],[
- AC_MSG_RESULT([yes])
- tst_works_poll="yes"
- ],[
- AC_MSG_RESULT([no])
- tst_works_poll="no"
- ])
- fi
- fi
- #
- if test "$tst_compi_poll" = "yes" &&
- test "$tst_works_poll" != "no"; then
- AC_MSG_CHECKING([if poll usage allowed])
- if test "x$curl_disallow_poll" != "xyes"; then
- AC_MSG_RESULT([yes])
- tst_allow_poll="yes"
- else
- AC_MSG_RESULT([no])
- tst_allow_poll="no"
- fi
- fi
- #
- AC_MSG_CHECKING([if poll might be used])
- if test "$tst_links_poll" = "yes" &&
- test "$tst_proto_poll" = "yes" &&
- test "$tst_compi_poll" = "yes" &&
- test "$tst_allow_poll" = "yes" &&
- test "$tst_works_poll" != "no"; then
- AC_MSG_RESULT([yes])
- AC_DEFINE_UNQUOTED(HAVE_POLL_FINE, 1,
- [If you have a fine poll])
- curl_cv_func_poll="yes"
- else
- AC_MSG_RESULT([no])
- curl_cv_func_poll="no"
- fi
])
delay(ms);
#elif defined(_WIN32)
Sleep((DWORD)ms);
-#elif defined(HAVE_POLL_FINE)
- (void)poll((void *)0, 0, (int)ms);
#else
struct timeval timeout;
timeout.tv_sec = ms / 1000L;
rlim2str(strbuff, sizeof(strbuff), num_open.rlim_max);
fprintf(stderr, "%s file descriptors open\n", strbuff);
-#if !defined(HAVE_POLL_FINE) && !defined(USE_WINSOCK)
+#if !defined(HAVE_POLL) && !defined(USE_WINSOCK)
/*
* when using select() instead of poll() we cannot test
#include "warnless.h"
#include "memdebug.h"
-#if !defined(HAVE_POLL_FINE) && \
- !defined(USE_WINSOCK) && \
- !defined(FD_SETSIZE)
+#if !defined(HAVE_POLL) && !defined(USE_WINSOCK) && !defined(FD_SETSIZE)
#error "this test requires FD_SETSIZE"
#endif
rlim2str(strbuff, sizeof(strbuff), num_open.rlim_max);
fprintf(stderr, "%s file descriptors open\n", strbuff);
-#if !defined(HAVE_POLL_FINE) && !defined(USE_WINSOCK)
+#if !defined(HAVE_POLL) && !defined(USE_WINSOCK)
/*
* when using select() instead of poll() we cannot test
int wait_ms(int timeout_ms)
{
#if !defined(MSDOS) && !defined(USE_WINSOCK)
-#ifndef HAVE_POLL_FINE
+#ifndef HAVE_POLL
struct timeval pending_tv;
#endif
struct timeval initial_tv;
initial_tv = tvnow();
do {
int error;
-#if defined(HAVE_POLL_FINE)
+#ifdef HAVE_POLL
r = poll(NULL, 0, pending_ms);
#else
pending_tv.tv_sec = pending_ms / 1000;
pending_tv.tv_usec = (pending_ms % 1000) * 1000;
r = select(0, NULL, NULL, NULL, &pending_tv);
-#endif /* HAVE_POLL_FINE */
+#endif /* HAVE_POLL */
if(r != -1)
break;
error = errno;