From 06bd023d07eaa8b5ff848f3d3d4a3126fda7fb73 Mon Sep 17 00:00:00 2001 From: Costin Lupu Date: Mon, 25 Nov 2019 09:47:43 +0200 Subject: [PATCH] sockets.c: Add ppoll() function This ppoll() implementation is adapted from its man page. If tmo_p is NULL, then ppoll() can block indefinitely. Signed-off-by: Costin Lupu Reviewed-by: Stefan Teodorescu --- Config.uk | 6 ++++++ sockets.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/Config.uk b/Config.uk index 8f501fc..debf0c7 100644 --- a/Config.uk +++ b/Config.uk @@ -170,6 +170,12 @@ if LWIP_SOCKET lwip's select() implementation supports only sockets. This configuration option makes it possible to use other file descriptor types as well, even though they are not supported by lwip. + + config LWIP_SOCKET_PPOLL + bool "Enable ppoll()" + default y + help + Enable ppoll() implementation. endif menuconfig LWIP_DEBUG diff --git a/sockets.c b/sockets.c index c2cf57f..8fde21a 100644 --- a/sockets.c +++ b/sockets.c @@ -34,7 +34,11 @@ */ /* network stub calls */ +#include #include +#if CONFIG_LWIP_SOCKET_PPOLL +#include +#endif #include #include #include @@ -473,6 +477,38 @@ EXIT: return ret; } +#if CONFIG_LWIP_SOCKET_PPOLL +#if CONFIG_LIBPTHREAD_EMBEDDED +#define __sigmask pthread_sigmask +#else +#define __sigmask sigprocmask +#endif +int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmo_p, + const sigset_t *sigmask) +{ + sigset_t origmask; + int timeout, rc, _rc; + + if (!fds) { + errno = EFAULT; + rc = -1; + goto out; + } + + timeout = (tmo_p == NULL) ? -1 : + (tmo_p->tv_sec * 1000 + tmo_p->tv_nsec / 1000000); + rc = __sigmask(SIG_SETMASK, sigmask, &origmask); + if (rc) + goto out; + rc = poll(fds, nfds, timeout); + _rc = __sigmask(SIG_SETMASK, &origmask, NULL); + if (rc == 0 && _rc != 0) + rc = _rc; +out: + return rc; +} +#endif /* CONFIG_LWIP_SOCKET_PPOLL */ + int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) { -- 2.39.5