select() on sockets considered harmful, use poll() instead?

Dan Kegel dank at
Wed Nov 1 09:01:49 CST 2006

This probably won't bite us for a while, but
I noticed several uses of select() on sockets in the
wine source code.  This will fail in programs
that need more than FD_SETSIZE file descriptors
if one of the sockets being selected on
happens to have a value of FD_SETSIZE or higher.
Glibc fixes FD_SETSIZE at 1024, and does not allow
this limit to be changed.
Wine also uses poll(), which does not suffer from
this limitation.  We might want to rewrite this
code to use poll() instead of select() sometime.

The suspect statements are:

dinput/joystick_linux.c:      if (1>select(This->joyfd+1,&readfds,...
dinput/joystick_linuxinput.c: if (1>select(This->joyfd+1,&readfds,...
icmp/icmp_main.c:             while ((res=select(icp->sid+1,&fdr,...
netapi32/nbt.c:               r = select(fd + 1, &fds, ...
wininet/internet.c:           if (select(nSocket+1,&infd,...
wininet/netconnection.c:      if (select(connection->socketFD+1,&infd,...
ws2_32/socket.c:              if( (highfd = select(highfd + 1, p_read,
p_write, p_except, timeoutaddr))

Instance of select() that don't use file descriptors
(i.e. that are just for delay) are safe, as are
instances in conformance tests.

Might make a nice little project for a new wine hacker...
- Dan

More information about the wine-devel mailing list