Skip to content

Commit

Permalink
fix: select without any fds cause WaitForMultipleObjects stuck on Win…
Browse files Browse the repository at this point in the history
…dows
  • Loading branch information
nurse committed May 19, 2015
1 parent d147d46 commit b8ab928
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ext/libev/ev_select.c
Expand Up @@ -106,6 +106,7 @@ if (__i == ((fd_set *)(set))->fd_count) {\
} while(0)
#define EV_WIN_FD_ZERO(set) (((fd_set *)(set))->fd_count=0)
#define EV_WIN_FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)(fd), (fd_set *)(set))
#define EV_WIN_FD_COUNT(set) (((fd_set *)(set))->fd_count)
/* ######################################## */
#else
#define EV_WIN_FD_CLR FD_CLR
Expand Down Expand Up @@ -192,6 +193,23 @@ select_poll (EV_P_ ev_tstamp timeout)
int res;
int fd_setsize;

#ifdef _WIN32
/* POSIX defines the case when the readfds, writefds, and errorfds arguments
* are all null pointers.
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/select.html
*
* But Windows doesn't define such case; simply say don't so that
* https://msdn.microsoft.com/en-us/library/windows/desktop/ms740141(v=vs.85).aspx
* "Any two of the parameters, readfds, writefds, or exceptfds, can be given
* as null. At least one must be non-null, and any non-null descriptor set
* must contain at least one handle to a socket."
* At least on Windows Server 2012 R2 Datacenter with Visual Studio 2013
* (Visual C++ 12), it cause WaitForMultipleObjects stuck.
*/
if (EV_WIN_FD_COUNT(vec_ri) == 0 && EV_WIN_FD_COUNT(vec_wi) == 0)
return;
#endif

EV_RELEASE_CB;
EV_TV_SET (tv, timeout);

Expand Down

1 comment on commit b8ab928

@nahi
Copy link

@nahi nahi commented on b8ab928 May 20, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.