diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2002-11-20 08:03:50 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2002-11-20 08:03:50 +0000 |
commit | 03b65245db3457d7df414ea7b07c56594362c20a (patch) | |
tree | 019df8eb47c0923d1fea13490bf18e75e1d8a526 /winsup/cygwin/poll.cc | |
parent | ec97538aa23e27bf1b79486ada811e97aa31e741 (diff) | |
download | newlib-03b65245db3457d7df414ea7b07c56594362c20a.zip newlib-03b65245db3457d7df414ea7b07c56594362c20a.tar.gz newlib-03b65245db3457d7df414ea7b07c56594362c20a.tar.bz2 |
* poll.cc (poll): Don't set POLLERR if a listening socket has a
pending connect. Don't use errno value from call to
fhandler_socket::recvfrom().
Diffstat (limited to 'winsup/cygwin/poll.cc')
-rw-r--r-- | winsup/cygwin/poll.cc | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/winsup/cygwin/poll.cc b/winsup/cygwin/poll.cc index 3c61c56..52c05dd 100644 --- a/winsup/cygwin/poll.cc +++ b/winsup/cygwin/poll.cc @@ -8,12 +8,16 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ +#define __INSIDE_CYGWIN_NET__ + #include "winsup.h" #include <sys/time.h> #include <sys/poll.h> #include <sys/socket.h> #include <errno.h> #include <stdlib.h> +#define USE_SYS_TYPES_FD_SET +#include <winsock2.h> #include "security.h" #include "fhandler.h" #include "path.h" @@ -93,19 +97,33 @@ poll (struct pollfd *fds, unsigned int nfds, int timeout) 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; - } + { + /* The following action can change errno. We have to + reset it to it's old value. */ + int old_errno = get_errno (); + switch (sock->recvfrom (peek, sizeof (peek), MSG_PEEK, + NULL, NULL)) + { + case -1: /* Something weird happened */ + /* When select returns that data is available, + that could mean that the socket is in + listen mode and a client tries to connect. + Unfortunately, recvfrom() doesn't make much + sense then. It returns WSAENOTCONN in that + case. Since that's not actually an error, + we must not set POLLERR. */ + if (WSAGetLastError () != WSAENOTCONN) + fds[i].revents |= POLLERR; + break; + case 0: /* Closed on the read side. */ + fds[i].revents |= POLLHUP; + break; + default: + fds[i].revents |= POLLIN; + break; + } + set_errno (old_errno); + } } if (FD_ISSET(fds[i].fd, write_fds)) fds[i].revents |= POLLOUT; |