summaryrefslogtreecommitdiffstats
path: root/openbsd-compat/bsd-poll.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@dtucker.net>2021-11-18 23:11:37 +1100
committerDarren Tucker <dtucker@dtucker.net>2021-11-18 23:11:37 +1100
commit21dd5a9a3fb35e8299a1fbcf8d506f1f6b752b85 (patch)
tree091ced589ec4131cfaad1851592b28a6ebc4cc5c /openbsd-compat/bsd-poll.c
parentb544ce1ad4afb7ee2b09f714aa63efffc73fa93a (diff)
Add compat implementation of ppoll using pselect.
Diffstat (limited to 'openbsd-compat/bsd-poll.c')
-rw-r--r--openbsd-compat/bsd-poll.c40
1 files changed, 27 insertions, 13 deletions
diff --git a/openbsd-compat/bsd-poll.c b/openbsd-compat/bsd-poll.c
index c8e6222c..f1b2f119 100644
--- a/openbsd-compat/bsd-poll.c
+++ b/openbsd-compat/bsd-poll.c
@@ -15,7 +15,7 @@
*/
#include "includes.h"
-#if !defined(HAVE_POLL)
+#if !defined(HAVE_PPOLL) || !defined(HAVE_POLL)
#include <sys/types.h>
#include <sys/time.h>
@@ -24,12 +24,14 @@
#endif
#include <errno.h>
+#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include "bsd-poll.h"
+#ifndef HAVE_PPOLL
/*
- * A minimal implementation of poll(2), built on top of select(2).
+ * A minimal implementation of ppoll(2), built on top of pselect(2).
*
* Only supports POLLIN and POLLOUT flags in pfd.events, and POLLIN, POLLOUT
* and POLLERR flags in revents.
@@ -38,13 +40,13 @@
*/
int
-poll(struct pollfd *fds, nfds_t nfds, int timeout)
+ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmoutp,
+ const sigset_t *sigmask)
{
nfds_t i;
int saved_errno, ret, fd, maxfd = 0;
fd_set *readfds = NULL, *writefds = NULL, *exceptfds = NULL;
size_t nmemb;
- struct timeval tv, *tvp = NULL;
for (i = 0; i < nfds; i++) {
fd = fds[i].fd;
@@ -79,14 +81,7 @@ poll(struct pollfd *fds, nfds_t nfds, int timeout)
}
}
- /* poll timeout is msec, select is timeval (sec + usec) */
- if (timeout >= 0) {
- tv.tv_sec = timeout / 1000;
- tv.tv_usec = (timeout % 1000) * 1000;
- tvp = &tv;
- }
-
- ret = select(maxfd + 1, readfds, writefds, exceptfds, tvp);
+ ret = pselect(maxfd + 1, readfds, writefds, exceptfds, tmoutp, sigmask);
saved_errno = errno;
/* scan through select results and set poll() flags */
@@ -114,4 +109,23 @@ out:
errno = saved_errno;
return ret;
}
-#endif
+#endif /* HAVE_PPOLL */
+
+#ifdef HAVE_POLL
+int
+poll(struct pollfd *fds, nfds_t nfds, int timeout)
+{
+ struct timespec ts, *tsp = NULL;
+
+ /* poll timeout is msec, ppoll is timespec (sec + nsec) */
+ if (timeout >= 0) {
+ ts.tv_sec = timeout / 1000;
+ ts.tv_nsec = (timeout % 1000000) * 1000000;
+ tsp = &ts;
+ }
+
+ return ppoll(fds, nfds, tsp, NULL);
+}
+#endif /* HAVE_POLL */
+
+#endif /* HAVE_PPOLL || HAVE_POLL */