The attached patch fixes poll to return POLLIN if an accept is possible.
A much better fix would have been to use SO_ACCEPTCONN, but due to a bug
in the kernel it is not possible to read this option from user mode.
Will apply if nobody complains in a couple of days.
Paolo
2006-11-29 Paolo Bonzini <[EMAIL PROTECTED]>
* lib/poll.c (poll): Define as rpl_poll. On Darwin, fall back to
Apple's broken poll if no data is available.
Index: poll.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/poll.c,v
retrieving revision 1.5
diff -u -r1.5 poll.c
--- poll.c 28 Sep 2006 19:58:33 -0000 1.5
+++ poll.c 29 Nov 2006 08:21:56 -0000
@@ -55,8 +55,10 @@
#define EOVERFLOW EINVAL
#endif
+#undef poll
+
int
-poll (pfd, nfd, timeout)
+rpl_poll (pfd, nfd, timeout)
struct pollfd *pfd;
nfds_t nfd;
int timeout;
@@ -172,6 +174,19 @@
while (r == -1 && (errno == EAGAIN || errno == EINTR));
if (avail < 0)
avail = 0;
+
+ if (avail == 0)
+ {
+ /* The above fails for listening sockets; of course, BSD
+ derivatives have a bug and don't expose SO_ACCEPTCONN to
+ user programs! So we rely on Apple's broken poll(2) in
+ this case. It can't be worse than what we did so far. */
+ struct pollfd pfd_for_apple_poll = pfd[0];
+ extern int poll (struct pollfd *, nfds_t, int);
+ r = poll (&pfd_for_apple_poll, 1, 0);
+ if (r != -1 && (pfd_for_apple_poll.revents & POLLHUP) == 0)
+ avail = 1;
+ }
#else
char data[64];
r = recv (pfd[i].fd, data, 64, MSG_PEEK);