POSIX says the following about poll "A value of 0 indicates that the call timed out and no file descriptors have been selected.". My interpretation is that a return value of 0 would be illegal when timeout = -1.
But when I call poll(..., -1), it seems 0 is returned under some conditions. Looking through the code, it seems that there isn't any efforts to enforce this paragraph; perhaps the included patch is appropriate? This problem currently affects a feature-branch I have against Git for Windows, where this cause a program not to consume input because it assumes that poll(..., -1) cannot return 0. The patch fixes it for me. diff --git a/lib/poll.c b/lib/poll.c index 8ce68c0..4b91606 100644 --- a/lib/poll.c +++ b/lib/poll.c @@ -452,6 +452,7 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout) if (!hEvent) hEvent = CreateEvent (NULL, FALSE, FALSE, NULL); +restart: handle_array[0] = hEvent; nhandles = 1; FD_ZERO (&rfds); @@ -592,6 +593,9 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout) rc++; } + if (!rc && timeout == INFTIM) + goto restart; + return rc; #endif }