windows workaround unsigned fd in emulated poll

A common practise to temporarily disable a socket in a poll call is to negate the socket fd.  poll should then ignore the socket.
emulated_poll does this with the following code:
        if (poll_fd->fd < 0 || !poll_fd->events)
            goto skip1;

However on Windows the fd field in WSAPOLLFD is unsigned int!!!  So the check for a negative fd value always fails.
This results in select returning an error with an error code of 10038 -- Socket operation on nonsocket.
The fix is to type cast fd like so:
        if ((int)poll_fd->fd < 0 || !poll_fd->events)

This may be the cause of some high CPU load reports.  I noticed the load being 50% with my application running on Windows XP.

Signed-off-by: Graham Newton <gnewton@peavey-eu.com>
This commit is contained in:
Graham Newton 2013-11-09 08:11:41 +08:00 committed by Andy Green
parent d1eac60f81
commit 7ee4f890a3

View file

@ -46,7 +46,7 @@ INT WSAAPI emulated_poll(LPWSAPOLLFD fdarray, ULONG nfds, INT timeout)
poll_fd->revents = 0;
if (poll_fd->fd < 0 || !poll_fd->events)
if ((int)poll_fd->fd < 0 || !poll_fd->events)
goto skip1;
if (max_socket < poll_fd->fd)