[Libwebsockets] Dealing with socket file descriptors >30000 on windows

Andy Green andy at warmcat.com
Thu Jan 29 04:00:53 CET 2015



On 01/29/2015 05:36 AM, Bud Davis wrote:
> This patch provides a lookup table for windows file descriptors.
>
> For unix, there should be no change, as the index function is
> implemented as a macro which turns into nothing but the desired index.
>
> The bad news is I used a sequential array, that will not work well with
> thousands on entries.  In my world, the number is in the dozens.....YMMV.
>
> I also reduced the size of the windows array to 1024, same as unix.  The
> 30,000 was only to have space for the sparse indexing, since the index
> is now 'packed' it seemed like the right thing to do.
>
> I write and tested this code, linux and windows, on a version a few
> weeks old.  Had to merge a couple of files....it looked clean but I only
> had a linux machine to check it on.
>
> Being it doesn't use a hash table, this may not be complete enough...but
> in the interim it might be of use to those of us that have an immediate
> issue with this problem.

Thanks... I'm very aware fd handling is reportedly broken in some 
Windows versions at least.

So I started with importing this and trying to improve it... but I think 
if I do it, it'll need to be done from scratch.

So let me give you some comments, if you would like to incorporate them 
and make a new patch that's great, especially since I can't test on 
Windows.  If not, I'll redo it in line with the comments later.

  - instead of lws_lookup_idx, it seems to need something like struct 
libwebsocket *lws_fd_to_wsi(context, fd)

  - something is wrong with retval = 1 in there

  - there should be a separate function to add fd -> wsi mappings, not 
hide it in the lookup function

  - arbitrary limit of 1024 is not really any good... in unix it's not 
set to 1024 you can control its fd limit from the parent process to be 
as few or a many as you like with ulimit.  1024 is just the default in 
some distros.  At least on Windows, you'd need to be able to set this 
number from outside (eg, info struct at context create, or maybe env var 
or whatever "this is not ulimit" scheme Microsoft created to be 
different with)

  - linear search is no good... even if we get up to a 100 connections 
performance will really start to drag.  It needs to use a hashtable. 
But since it's supposedly broken right now, linear search that works as 
a starting point is an 'improvement' we can fix later.

  - have a look in git show dfb23041684e1c3bf01b869f09e5b88c7ad5931c 
which is the commit where the hashtable scheme was replaced, you can cut 
and paste bits out of there if you're interested.

-Andy

>
> regards,
> Bud Davis
>
>
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> http://ml.libwebsockets.org/mailman/listinfo/libwebsockets
>



More information about the Libwebsockets mailing list