summaryrefslogtreecommitdiffstats
path: root/cpukit
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2021-08-17 18:45:19 +1000
committerChris Johns <chrisj@rtems.org>2021-08-19 08:51:39 +1000
commit522db76a965990740a480a3b3856080ec983dbd1 (patch)
treee3515a489fcafea7970d4d68944b31950738ef0a /cpukit
parentaarch64/versal: Enable TX and RX FIFOs (diff)
downloadrtems-522db76a965990740a480a3b3856080ec983dbd1.tar.bz2
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
Diffstat (limited to 'cpukit')
-rw-r--r--cpukit/mghttpd/mongoose.c31
1 files changed, 31 insertions, 0 deletions
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 <stddef.h>
#include <stdio.h>
+#if __rtems__
+#include <time.h>
+#include <sys/param.h>
+#include <rtems/libio_.h>
+#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"));