windows workaround unsigned fd in emulated poll
authorGraham Newton <gnewton@peavey-eu.com>
Sat, 9 Nov 2013 00:11:41 +0000 (08:11 +0800)
committerAndy Green <andy.green@linaro.org>
Sat, 9 Nov 2013 00:11:41 +0000 (08:11 +0800)
commit7ee4f890a3497997a963fceca256069ecdf829d5
treee98fc59d8ba1b3811e120f4e8087a7905012f10a
parentd1eac60f8194984acc96a6d30f4d414eaf8be6c4
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>
win32port/win32helpers/websock-w32.c