[PATCH] cpukit/mghttpd: Support all descriptors in select

Gedare Bloom gedare at rtems.org
Wed Aug 18 18:15:34 UTC 2021


On Tue, Aug 17, 2021 at 7:20 AM Joel Sherrill <joel at rtems.org> wrote:
>
> Looks ok.
>
> On Tue, Aug 17, 2021, 3:49 AM <chrisj at rtems.org> wrote:
>>
>> From: Chris Johns <chrisj at rtems.org>
>>
>> - 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

This raises again the different question about maintaining a fork of
mghttpd or replacing it with something else (civetweb?). Until we
resolve that, please protect this code with ifdef/ifndef blocks to
preserve changes.

>> ---
>>  cpukit/mghttpd/mongoose.c | 28 ++++++++++++++++++++++++++++
>>  1 file changed, 28 insertions(+)
>>
>> diff --git a/cpukit/mghttpd/mongoose.c b/cpukit/mghttpd/mongoose.c
>> index 0736c836ec..5e7e68e7ea 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
>> +
remove changes outside of the #ifdef section

>>  #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);
>> @@ -5367,6 +5392,9 @@ static void *master_thread(void *thread_func_param) {
>>            accept_new_connection(&ctx->listening_sockets[i], ctx);
>>          }
>>        }
>> +    } else {
>> +      struct timespec t = { .tv_sec = 0, .tv_nsec = 500000000L };
>> +      nanosleep(&t, &t);
Add #ifdef __rtems__

>>      }
>>    }
>>    free(pfd);
>> --
>> 2.19.1
>>
>> _______________________________________________
>> devel mailing list
>> devel at rtems.org
>> http://lists.rtems.org/mailman/listinfo/devel
>
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel


More information about the devel mailing list