Windows select (was RE: A select question)

Tim Peters tim.one at home.com
Tue May 15 01:02:47 EDT 2001


[Victor Muslin, about select on Windows]
> After some experimentation it appears that the number of socket
> objects allowed in select is around 64. This seems to correspond to
> FD_SETSIZE pre-processor constant defined in winsock2.h.

There are three issues here:

1. FD_SETSIZE is used by the Microsoft libraries to allocate space for
select-related structures *at compile time*.  This makes FD_SETSIZE an
absolute upper limit.

2. While you can #define FD_SETSIZE to be as large as you like, there's no
guarantee you can actually use that many sockets.  You have to consult the
docs for your socket provider to find that out (and good luck finding them).

3. You're using an old version of Python.  Recent versions have this at the
top of selectmodule.c:

/* Windows #defines FD_SETSIZE to 64 if FD_SETSIZE isn't already defined.
   64 is too small (too many people have bumped into that limit).
   Here we boost it.
   Users who want even more than the boosted limit should #define
   FD_SETSIZE higher before this; e.g., via compiler /D switch.
*/
#if defined(MS_WINDOWS) && !defined(FD_SETSIZE)
#define FD_SETSIZE 512
#endif

> However, in C or C++ it is possible to redefine FD_SETSIZE before
> including winsock2.h. Is it possible to do something similar in Python
> to wait for data on more than 64 sockets at a time?

As above, since Microsoft's libraries latch on to FD_SETSIZE at compile time,
if 512 isn't enough for you your only choice is to recompile Python from
source yourself, or use another approach entirely.

> If not, how does one write a server in Python that can have more
> than 64 concurrent connections?

Leaving that to someone else.

you-might-even-try-an-os-designed-to-be-used<wink>-ly y'rs  - tim





More information about the Python-list mailing list