]> xenbits.xensource.com Git - unikraft/libs/lwip.git/commitdiff
sockets.c: Add ppoll() function
authorCostin Lupu <costin.lupu@cs.pub.ro>
Mon, 25 Nov 2019 07:47:43 +0000 (09:47 +0200)
committerCostin Lupu <costin.lup@gmail.com>
Thu, 28 Nov 2019 15:41:57 +0000 (17:41 +0200)
This ppoll() implementation is adapted from its man page. If tmo_p is NULL,
then ppoll() can block indefinitely.

Signed-off-by: Costin Lupu <costin.lupu@cs.pub.ro>
Reviewed-by: Stefan Teodorescu <stefanl.teodorescu@gmail.com>
Config.uk
sockets.c

index 8f501fc5ed39f3e282817a912313ea2fb79e5cf9..debf0c71f26f7aca3622bfae4517928083dc5216 100644 (file)
--- 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
index c2cf57ffe509bfddcd04d706254164983fc1ffb6..8fde21a425cd28f5af456778a3030b992215d0e1 100644 (file)
--- a/sockets.c
+++ b/sockets.c
  */
 
 /* network stub calls */
+#include <uk/config.h>
 #include <sys/time.h>
+#if CONFIG_LWIP_SOCKET_PPOLL
+#include <signal.h>
+#endif
 #include <vfscore/dentry.h>
 #include <vfscore/file.h>
 #include <vfscore/fs.h>
@@ -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)
 {