From 522db76a965990740a480a3b3856080ec983dbd1 Mon Sep 17 00:00:00 2001 From: Chris Johns Date: Tue, 17 Aug 2021 18:45:19 +1000 Subject: cpukit/mghttpd: Support all descriptors in select - Support all possible descriptors in a select call. Borrowed from Christain and his mDNS change in LibBSD - If select (or poll) fails pause for a bit rather than locking up in a hard loop --- cpukit/mghttpd/mongoose.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'cpukit') diff --git a/cpukit/mghttpd/mongoose.c b/cpukit/mghttpd/mongoose.c index 0736c836ec..623d6a501f 100644 --- a/cpukit/mghttpd/mongoose.c +++ b/cpukit/mghttpd/mongoose.c @@ -81,6 +81,12 @@ #include #include +#if __rtems__ +#include +#include +#include +#endif + #if defined(_WIN32) && !defined(__SYMBIAN32__) // Windows specific #undef _WIN32_WINNT #define _WIN32_WINNT 0x0400 // To make it link in VS2005 @@ -1516,13 +1522,32 @@ static int set_non_blocking_mode(SOCKET sock) { #ifndef HAVE_POLL static int poll(struct pollfd *pfd, int n, int milliseconds) { struct timeval tv; +#if __rtems__ + #define set (*set_prealloc) + static fd_set *set_prealloc; + static size_t set_size; +#else fd_set set; +#endif int i, result; SOCKET maxfd = 0; tv.tv_sec = milliseconds / 1000; tv.tv_usec = (milliseconds % 1000) * 1000; +#if __rtems__ + if (set_prealloc == NULL) { + set_size = + sizeof(fd_set) * (howmany(rtems_libio_number_iops, sizeof(fd_set) * 8)); + set_prealloc = malloc(set_size); + if (set_prealloc == NULL) { + errno = ENOMEM; + return -1; + } + } + memset(set_prealloc, 0, set_size); +#else FD_ZERO(&set); +#endif for (i = 0; i < n; i++) { FD_SET((SOCKET) pfd[i].fd, &set); @@ -5368,6 +5393,12 @@ static void *master_thread(void *thread_func_param) { } } } +#if __rtems__ + else { + struct timespec t = { .tv_sec = 0, .tv_nsec = 500000000L }; + nanosleep(&t, &t); + } +#endif /* __rtems__ */ } free(pfd); DEBUG_TRACE(("stopping workers")); -- cgit v1.2.3