From 3c5b6d116a5ca9a979e66919baed802eac2101d1 Mon Sep 17 00:00:00 2001 From: corinna Date: Thu, 29 Aug 2002 09:41:00 +0000 Subject: [PATCH] * poll.cc (poll): Peek sockets ready for read to see if there's actually data. --- winsup/cygwin/ChangeLog | 6 ++++++ winsup/cygwin/poll.cc | 23 ++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 9036d0387d..5c6b53e4bf 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,9 @@ +2002-08-29 Boris Schaeling + Corinna Vinschen + + * poll.cc (poll): Peek sockets ready for read to see if there's + actually data. + 2002-08-28 Christopher Faylor * cygthread.cc (hthreads): Remove unneeded global. diff --git a/winsup/cygwin/poll.cc b/winsup/cygwin/poll.cc index 89a3124d19..36c61cfcc3 100644 --- a/winsup/cygwin/poll.cc +++ b/winsup/cygwin/poll.cc @@ -11,6 +11,7 @@ #include "winsup.h" #include #include +#include #include #include #include "security.h" @@ -85,7 +86,27 @@ poll (struct pollfd *fds, unsigned int nfds, int timeout) else { if (FD_ISSET(fds[i].fd, read_fds)) - fds[i].revents |= POLLIN; + { + char peek[1]; + fhandler_socket *sock = + cygheap->fdtab[fds[i].fd]->is_socket (); + if (!sock) + fds[i].revents |= POLLIN; + else + switch (sock->recvfrom (peek, sizeof(peek), MSG_PEEK, + NULL, NULL)) + { + case -1: /* Something weird happened */ + fds[i].revents |= POLLERR; + break; + case 0: /* Closed on the read side. */ + fds[i].revents |= POLLHUP; + break; + default: + fds[i].revents |= POLLIN; + break; + } + } if (FD_ISSET(fds[i].fd, write_fds)) fds[i].revents |= POLLOUT; if (FD_ISSET(fds[i].fd, except_fds)) -- 2.11.0