Browse Source

bug #1639: Implement a pselect() wrapper around select() for OpenBSD

Mukund Sivaraman 13 years ago
parent
commit
6ea0b1d62e
2 changed files with 32 additions and 0 deletions
  1. 3 0
      configure.ac
  2. 29 0
      tests/tools/perfdhcp/perfdhcp.c

+ 3 - 0
configure.ac

@@ -930,6 +930,9 @@ EV_SET(&kevent, 0, 0, 0, 0, 0, udata);],
 	])
 fi
 
+# Check for pselect() for use in perfdhcp
+AC_CHECK_FUNCS([pselect])
+
 # perfdhcp: If the clock_gettime() function does not exist on the system,
 # use an alternative supplied in the code based on gettimeofday().
 CLOCK_GETTIME_LDFLAGS=

+ 29 - 0
tests/tools/perfdhcp/perfdhcp.c

@@ -66,6 +66,35 @@ main(const int argc, char* const argv[])
 #include <time.h>
 #include <unistd.h>
 
+#ifndef HAVE_PSELECT
+
+#include <assert.h>
+
+/* Platforms such as OpenBSD don't provide a pselect(), so we use our
+   own implementation for this testcase, which wraps around select() and
+   hence doesn't implement the high precision timer. This implementation
+   is fine for our purpose. */
+
+static int
+pselect (int nfds, fd_set *readfds, fd_set *writefds,
+         fd_set *exceptfds, const struct timespec *timeout,
+         const sigset_t *sigmask)
+{
+    struct timeval my_timeout;
+
+    /* Our particular usage of pselect() doesn't use these fields. */
+    assert(writefds == NULL);
+    assert(exceptfds == NULL);
+    assert(sigmask == NULL);
+
+    my_timeout.tv_sec = timeout->tv_sec;
+    my_timeout.tv_usec = timeout->tv_nsec / 1000;
+
+    return select(nfds, readfds, writefds, exceptfds, &my_timeout);
+}
+
+#endif
+
 /* DHCPv4 defines (to be moved/shared) */
 
 #define DHCP_OFF_OPCODE		0