diff options
author | Nico Weber <thakis@chromium.org> | 2020-06-22 11:41:51 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-06-23 14:12:20 +0200 |
commit | d2684a86458087a7771975ac1cb72bb2fb5f444a (patch) | |
tree | df6f8e78d7b43c11e5761a2efaa86ad746fd5e45 /Libraries | |
parent | 4b19b99b36bb058394a251d42f5aa331c1627b35 (diff) | |
download | serenity-d2684a86458087a7771975ac1cb72bb2fb5f444a.zip |
LibC+Kernel: Implement ppoll
ppoll() is similar() to poll(), but it takes its timeout
as timespec instead of as int, and it takes an additional
sigmask parameter.
Change the sys$poll parameters to match ppoll() and implement
poll() in terms of ppoll().
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibC/poll.cpp | 17 | ||||
-rw-r--r-- | Libraries/LibC/poll.h | 6 |
2 files changed, 20 insertions, 3 deletions
diff --git a/Libraries/LibC/poll.cpp b/Libraries/LibC/poll.cpp index 46f2fdf49f..256c4528f4 100644 --- a/Libraries/LibC/poll.cpp +++ b/Libraries/LibC/poll.cpp @@ -27,12 +27,25 @@ #include <Kernel/Syscall.h> #include <errno.h> #include <poll.h> +#include <sys/time.h> extern "C" { -int poll(struct pollfd* fds, int nfds, int timeout) +int poll(pollfd* fds, nfds_t nfds, int timeout_ms) { - int rc = syscall(SC_poll, fds, nfds, timeout); + timespec timeout; + timespec* timeout_ts = &timeout; + if (timeout_ms < 0) + timeout_ts = nullptr; + else + timeout = { timeout_ms / 1000, (timeout_ms % 1000) * 1'000'000 }; + return ppoll(fds, nfds, timeout_ts, nullptr); +} + +int ppoll(pollfd* fds, nfds_t nfds, const timespec* timeout, const sigset_t* sigmask) +{ + Syscall::SC_poll_params params { fds, nfds, timeout, sigmask }; + int rc = syscall(SC_poll, ¶ms); __RETURN_WITH_ERRNO(rc, rc, -1); } } diff --git a/Libraries/LibC/poll.h b/Libraries/LibC/poll.h index 051357249a..af0ff254c5 100644 --- a/Libraries/LibC/poll.h +++ b/Libraries/LibC/poll.h @@ -26,6 +26,7 @@ #pragma once +#include <signal.h> #include <sys/cdefs.h> __BEGIN_DECLS @@ -43,6 +44,9 @@ struct pollfd { short revents; }; -int poll(struct pollfd* fds, int nfds, int timeout); +typedef unsigned nfds_t; + +int poll(struct pollfd* fds, nfds_t nfds, int timeout); +int ppoll(struct pollfd* fds, nfds_t nfds, const struct timespec* timeout, const sigset_t* sigmask); __END_DECLS |