[Libwebsockets] trouble with external POLL array handling

"Andy Green (林安廸)" andy at warmcat.com
Sun Jan 20 13:59:03 CET 2013


On 20/01/13 19:46, the mail apparently from Edwin van den Oetelaar included:
> patch to make test-server external poll fully dynamic, no constants.

Thanks, I had meant to do that after doing the library implementation, 
but I forgot.

http://git.libwebsockets.org/cgi-bin/cgit/libwebsockets/commit/?id=596b220c40faa4cc7b889553d41c4cc16518cbd9

BTW I studied the memory footprint situation over all the major 
configuration variations today, I think it's pretty good

http://git.libwebsockets.org/cgi-bin/cgit/libwebsockets/commit/?id=5c81e804fa6b91bd43ed4f1be2e0752cb0b50999

Accounting for static (elf) allocations and the two big mallocs during 
context creation for the pollfd tracking, you can still do an ARM 
embedded http / websocket server for 1024 fd in just over 40Kbytes 
including the code, bss etc, plus around 10Kbytes per connection.

-Andy

> --- a/test-server/test-server.c
> +++ b/test-server/test-server.c
> @@ -35,10 +35,10 @@ static int close_testing;
>   #ifdef EXTERNAL_POLL
>   #define LWS_NO_FORK
>
> -#define MAX_POLL_ELEMENTS 32000
> +int max_poll_elements;
>
> -struct pollfd pollfds[MAX_POLL_ELEMENTS];
> -int fd_lookup[MAX_POLL_ELEMENTS];
> +struct pollfd *pollfds;
> +int *fd_lookup;
>   int count_pollfds;
>
>   #endif /* EXTERNAL_POLL */
> @@ -160,7 +160,7 @@ static int callback_http(struct
> libwebsocket_context *context,
>
>          case LWS_CALLBACK_ADD_POLL_FD:
>
> -               if (count_pollfds >= MAX_POLL_ELEMENTS) {
> +               if (count_pollfds >= max_poll_elements) {
>                          lwsl_err("LWS_CALLBACK_ADD_POLL_FD: too many
> sockets to track\n");
>                          return 1;
>                  }
> @@ -585,7 +585,16 @@ int main(int argc, char **argv)
>                                                      "licensed under LGPL2.1\n");
>          if (!use_ssl)
>                  cert_path = key_path = NULL;
> -
> +#ifdef EXTERNAL_POLL
> +    max_poll_elements = getdtablesize();
> +    pollfds = malloc(max_poll_elements * sizeof (struct pollfd));
> +    fd_lookup = malloc(max_poll_elements * sizeof (int));
> +    if (pollfds == NULL || fd_lookup == NULL) {
> +        lwsl_err("Out of memory pollfds=%d\n", max_poll_elements);
> +        return -1;
> +    }
> +#endif
> +
>          context = libwebsocket_create_context(port, interface, protocols,
>
>
> On Fri, Jan 18, 2013 at 2:28 AM, "Andy Green (林安廸)" <andy at warmcat.com> wrote:
>> On 18/01/13 04:14, the mail apparently from Edwin van den Oetelaar included:
>>
>>> Isn't this a lot of fun :-)




More information about the Libwebsockets mailing list