Output from a test run on mingw Unconnected socket test... passed Connected sockets test... passed General socket test with fork... passed Pipe test... failed (expecting POLLHUP after shutdown) FAIL: test-poll.exe
This affects the attempt to make libvirtd working on Windows. libvirtd relies on poll blocking on a pipe until an event occurs when calling poll with a timeout of -1. But poll doesn't behave that way under mingw. Here's and example program: #include <config.h> #include <stdio.h> #include <errno.h> #include <poll.h> #include <fcntl.h> int main() { int ret; int p[2]; struct pollfd fds[1]; // libvirt uses a non-blocking pipe, but a // "normal" pipe also shows the same problem //pipe2(p, O_NONBLOCK); pipe(p); fds[0].fd = p[0]; fds[0].events = POLLIN; fds[0].revents = 0; printf("before\n"); ret = poll(fds, 1, -1); printf("after %d, errno %d, revents %d\n", ret, errno, fds[0].revents); return 0; } The poll call here is supposed to block forever. This works on Linux, but on mingw poll just returns and the printf after it prints "after 0, errno 0, revents 0". This results in libvirtd uselessly calling poll over and over again. When I alter the test-poll.c test via this patch --- a/gnulib/tests/test-poll.c 2011-05-25 16:25:03 +0000 +++ b/gnulib/tests/test-poll.c 2011-05-25 15:58:10 +0000 @@ -306,7 +306,7 @@ != POLLWRNORM) failed ("expecting POLLWRNORM before writing"); - write (wd, "foo", 3); + //write (wd, "foo", 3); if (poll1_wait (rd, POLLIN | POLLRDNORM) != (POLLIN | POLLRDNORM)) failed ("expecting POLLIN | POLLRDNORM after writing"); if (poll1_nowait (rd, POLLIN) != POLLIN) @@ -314,7 +314,7 @@ if (poll1_nowait (rd, POLLRDNORM) != POLLRDNORM) failed ("expecting POLLRDNORM after writing"); - read (rd, buf, 3); + //read (rd, buf, 3); } @@ -372,8 +372,8 @@ #endif result = test (test_connect_first, "Unconnected socket test"); - result += test (test_socket_pair, "Connected sockets test"); - result += test (test_accept_first, "General socket test with fork"); + //result += test (test_socket_pair, "Connected sockets test"); + //result += test (test_accept_first, "General socket test with fork"); result += test (test_pipe, "Pipe test"); exit (result); then the poll1_wait call after the disabled write call results in the call to poll being blocked on Linux. On mingw this test outputs Unconnected socket test... passed Pipe test... failed (expecting POLLIN | POLLRDNORM after writing) failed (expecting POLLIN after writing) failed (expecting POLLRDNORM after writing) failed (expecting POLLHUP after shutdown) Again this is with recent gnulib version: f4c4af09bcf3f0497dc3347ecc0a0b3c9ee1ff63 Matthias