]> xenbits.xensource.com Git - unikraft/libs/newlib.git/commitdiff
Add poll() and select() support via lwIP if available
authorFlorian Schmidt <florian.schmidt@neclab.eu>
Tue, 28 May 2019 07:55:29 +0000 (09:55 +0200)
committerFelipe Huici <felipe.huici@neclab.eu>
Wed, 29 May 2019 12:41:02 +0000 (14:41 +0200)
Otherwise, provide dummy stubs.

Signed-off-by: Florian Schmidt <florian.schmidt@neclab.eu>
Reviewed-by: Felipe Huici <felipe.huici@neclab.eu>
file.c
include/sys/poll.h

diff --git a/file.c b/file.c
index 02f1b6f36562108a55354a57b66208a7c1892e8b..d9c1194d63477ac0ad7f1a77db07cd9764246812 100644 (file)
--- a/file.c
+++ b/file.c
  * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
  */
 
+#include <uk/config.h>
+#include <uk/sched.h>
 #include <uk/plat/console.h>
+#if CONFIG_LWIP_SOCKET
+#include <lwip/sockets.h>
+#else
+#include <poll.h>
+#include <sys/select.h>
+#endif
 #include <sys/stat.h>
 #include <errno.h>
 #undef errno
@@ -66,3 +74,28 @@ int munmap(void *addr __unused, size_t len __unused)
 {
        return 0;
 }
+
+#if !CONFIG_LWIP_SOCKET
+int poll(struct pollfd _pfd[] __unused, nfds_t _nfds __unused,
+               int _timeout __unused)
+{
+       errno = ENOTSUP;
+       return -1;
+}
+
+int select(int nfds, fd_set *readfds __unused, fd_set *writefds __unused,
+               fd_set *exceptfds __unused, struct timeval *timeout)
+{
+       uint64_t nsecs;
+
+       if (nfds == 0) {
+               nsecs = timeout->tv_sec * 1000000000;
+               nsecs += timeout->tv_usec * 1000;
+               uk_sched_thread_sleep(nsecs);
+               return 0;
+       }
+
+       errno = ENOTSUP;
+       return -1;
+}
+#endif /* !CONFIG_LWIP_SOCKET */
index 2afbbdedcdac39fa4e4d75bce63a4101e0113876..556e038d6ce13d7818eb6b9469e575b6fd6e68da 100644 (file)
 #ifndef _POSIX_SYS_POLL_H_
 #define _POSIX_SYS_POLL_H_
 
+/* LWIP's socket interface provides poll primitives */
+#include <uk/config.h>
+#if !CONFIG_LWIP_SOCKET
+
 /*
  * This file is intended to be compatible with the traditional poll.h.
  */
@@ -77,4 +81,5 @@ struct pollfd {
 
 int poll(struct pollfd _pfd[], nfds_t _nfds, int _timeout);
 
+#endif /* !CONFIG_LWIP_SOCKET */
 #endif /* _POSIX_SYS_POLL_H_ */