X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fpoll.c;h=ed76098036e922ce6016b38e8c64b590f4b5ffec;hb=9fbf8e1a391ab49dca9c608a32af9a42831f3445;hp=b4001283d38bcde1c0d56f077dd9f6b83f47bb95;hpb=cc4349c8e593003e079213d82f19d62e5b524a77;p=gnulib.git diff --git a/lib/poll.c b/lib/poll.c index b4001283d..ed7609803 100644 --- a/lib/poll.c +++ b/lib/poll.c @@ -1,7 +1,7 @@ /* Emulation for poll(2) Contributed by Paolo Bonzini. - Copyright 2001, 2002, 2003, 2006, 2007, 2008 Free Software Foundation, Inc. + Copyright 2001-2003, 2006-2009 Free Software Foundation, Inc. This file is part of gnulib. @@ -19,6 +19,11 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +/* Tell gcc not to warn about the (nfd < 0) tests, below. */ +#if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__ +# pragma GCC diagnostic ignored "-Wtype-limits" +#endif + #include #include @@ -29,35 +34,35 @@ #include #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ -#define WIN32_NATIVE -#include -#include -#include -#include -#include +# define WIN32_NATIVE +# include +# include +# include +# include +# include #else -#include -#include -#include -#include +# include +# include +# include +# include #endif #ifdef HAVE_SYS_IOCTL_H -#include +# include #endif #ifdef HAVE_SYS_FILIO_H -#include +# include #endif #include #ifndef INFTIM -#define INFTIM (-1) +# define INFTIM (-1) #endif /* BeOS does not have MSG_PEEK. */ #ifndef MSG_PEEK -#define MSG_PEEK 0 +# define MSG_PEEK 0 #endif #ifdef WIN32_NATIVE @@ -92,9 +97,9 @@ typedef enum _FILE_INFORMATION_CLASS { typedef DWORD (WINAPI *PNtQueryInformationFile) (HANDLE, IO_STATUS_BLOCK *, VOID *, ULONG, FILE_INFORMATION_CLASS); -#ifndef PIPE_BUF -#define PIPE_BUF 512 -#endif +# ifndef PIPE_BUF +# define PIPE_BUF 512 +# endif /* Compute revents values for file handle H. */ @@ -234,7 +239,7 @@ compute_revents (int fd, int sought, fd_set *rfds, fd_set *wfds, fd_set *efds) int r; int socket_errno; -#if defined __MACH__ && defined __APPLE__ +# if defined __MACH__ && defined __APPLE__ /* There is a bug in Mac OS X that causes it to ignore MSG_PEEK for some kinds of descriptors. Detect if this descriptor is a connected socket, a server socket, or something else using a @@ -243,11 +248,11 @@ compute_revents (int fd, int sought, fd_set *rfds, fd_set *wfds, fd_set *efds) socket_errno = (r < 0) ? errno : 0; if (r == 0 || socket_errno == ENOTSOCK) ioctl (fd, FIONREAD, &r); -#else +# else char data[64]; r = recv (fd, data, sizeof (data), MSG_PEEK); socket_errno = (r < 0) ? errno : 0; -#endif +# endif if (r == 0) happened |= POLLHUP; @@ -288,7 +293,7 @@ poll (pfd, nfd, timeout) int maxfd, rc; nfds_t i; -#ifdef _SC_OPEN_MAX +# ifdef _SC_OPEN_MAX static int sc_open_max = -1; if (nfd < 0 @@ -299,15 +304,15 @@ poll (pfd, nfd, timeout) errno = EINVAL; return -1; } -#else /* !_SC_OPEN_MAX */ -#ifdef OPEN_MAX +# else /* !_SC_OPEN_MAX */ +# ifdef OPEN_MAX if (nfd < 0 || nfd > OPEN_MAX) { errno = EINVAL; return -1; } -#endif /* OPEN_MAX -- else, no check is needed */ -#endif /* !_SC_OPEN_MAX */ +# endif /* OPEN_MAX -- else, no check is needed */ +# endif /* !_SC_OPEN_MAX */ /* EFAULT is not necessary to implement, but let's do it in the simplest case. */ @@ -404,8 +409,7 @@ poll (pfd, nfd, timeout) fd_set rfds, wfds, xfds; BOOL poll_again; MSG msg; - char sockbuf[256]; - int rc; + int rc = 0; nfds_t i; if (nfd < 0 || timeout < -1) @@ -426,7 +430,6 @@ poll (pfd, nfd, timeout) /* Classify socket handles and create fd sets. */ for (i = 0; i < nfd; i++) { - size_t optlen = sizeof(sockbuf); pfd[i].revents = 0; if (pfd[i].fd < 0) continue; @@ -543,7 +546,7 @@ poll (pfd, nfd, timeout) ev.lNetworkEvents |= FD_WRITE | FD_CONNECT; if (FD_ISSET ((SOCKET) h, &xfds)) ev.lNetworkEvents |= FD_OOB; - + happened = win32_compute_revents_socket ((SOCKET) h, pfd[i].events, ev.lNetworkEvents); }