From: Florian Schmidt Date: Tue, 28 May 2019 07:55:29 +0000 (+0200) Subject: Add poll() and select() support via lwIP if available X-Git-Tag: RELEASE-0.4~96 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=318d984b9742c7498828869dec3fd98ffb0a6bce;p=unikraft%2Flibs%2Fnewlib.git Add poll() and select() support via lwIP if available Otherwise, provide dummy stubs. Signed-off-by: Florian Schmidt Reviewed-by: Felipe Huici --- diff --git a/file.c b/file.c index 02f1b6f..d9c1194 100644 --- a/file.c +++ b/file.c @@ -35,7 +35,15 @@ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY. */ +#include +#include #include +#if CONFIG_LWIP_SOCKET +#include +#else +#include +#include +#endif #include #include #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 */ diff --git a/include/sys/poll.h b/include/sys/poll.h index 2afbbde..556e038 100644 --- a/include/sys/poll.h +++ b/include/sys/poll.h @@ -34,6 +34,10 @@ #ifndef _POSIX_SYS_POLL_H_ #define _POSIX_SYS_POLL_H_ +/* LWIP's socket interface provides poll primitives */ +#include +#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_ */