diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2002-08-29 09:41:00 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2002-08-29 09:41:00 +0000 |
commit | 7382e593a01ee81cea5df91a77a9868281de8c04 (patch) | |
tree | 9fc6e35fd51738d94c9f32c34071b3fffc05a0c2 /winsup/cygwin/poll.cc | |
parent | edb983c141cd64a22815c3a86f84f14fd5762542 (diff) | |
download | newlib-7382e593a01ee81cea5df91a77a9868281de8c04.zip newlib-7382e593a01ee81cea5df91a77a9868281de8c04.tar.gz newlib-7382e593a01ee81cea5df91a77a9868281de8c04.tar.bz2 |
* poll.cc (poll): Peek sockets ready for read to see if there's
actually data.
Diffstat (limited to 'winsup/cygwin/poll.cc')
-rw-r--r-- | winsup/cygwin/poll.cc | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/winsup/cygwin/poll.cc b/winsup/cygwin/poll.cc index 89a3124..36c61cf 100644 --- a/winsup/cygwin/poll.cc +++ b/winsup/cygwin/poll.cc @@ -11,6 +11,7 @@ #include "winsup.h" #include <sys/time.h> #include <sys/poll.h> +#include <sys/socket.h> #include <errno.h> #include <stdlib.h> #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)) |