bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PATCH: Fix poll() impl on Win32


From: Jim Meyering
Subject: Re: PATCH: Fix poll() impl on Win32
Date: Wed, 07 Jan 2009 21:03:25 +0100

Jim Meyering <address@hidden> wrote:
> "Daniel P. Berrange" <address@hidden> wrote:
>> I've been using the GNULIB poll() impl in libvirt on Win32 (well Mingw +
>> WINE) and found it was producing really wierd results, such ret=-1 +
>> errno=EAGAIN, or ret=0 even though requested timeout was infinite.
>> After a little debugging I discovered a missing initialization of
>> the 'rc' variable in the Win32 impl of poll(). With this patch
>> applied, it is behaving as desired.
>>
>> diff --git a/gnulib/lib/poll.c b/gnulib/lib/poll.c
>> --- a/gnulib/lib/poll.c
>> +++ b/gnulib/lib/poll.c
>> @@ -405,7 +405,7 @@ poll (pfd, nfd, timeout)
>>    BOOL poll_again;
>>    MSG msg;
>>    char sockbuf[256];
>> -  int rc;
>> +  int rc = 0;
>
> Obviously correct.  Thanks!
> Paolo, ok to push this?
>
> [BTW, would you mind if I filtered poll.c through cppi,
> which indents each cpp directive according to its nesting level?
> That'd be a separate, white-space-only change.
> When they're indented properly it's much easier to determine
> which branch of a cpp conditional any particular line of code is in. ]

Thanks. pushed.

Here's one more:

>From 4dcf138870d17701213458dc6fbd1feedfd81826 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Wed, 7 Jan 2009 21:02:12 +0100
Subject: [PATCH] poll: filter through cppi

* lib/poll.c: Indent cpp directives to reflect nesting.
---
 ChangeLog  |    5 +++++
 lib/poll.c |   50 +++++++++++++++++++++++++-------------------------
 2 files changed, 30 insertions(+), 25 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2eb7a93..74954d5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-01-07  Jim Meyering  <address@hidden>
+
+       poll: filter through cppi
+       * lib/poll.c: Indent cpp directives to reflect nesting.
+
 2009-01-07  Daniel P. Berrange  <address@hidden>

        poll: don't return uninitialized
diff --git a/lib/poll.c b/lib/poll.c
index 35a5d53..c4fdecc 100644
--- a/lib/poll.c
+++ b/lib/poll.c
@@ -29,35 +29,35 @@
 #include <assert.h>

 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-#define WIN32_NATIVE
-#include <winsock2.h>
-#include <windows.h>
-#include <io.h>
-#include <stdio.h>
-#include <conio.h>
+# define WIN32_NATIVE
+# include <winsock2.h>
+# include <windows.h>
+# include <io.h>
+# include <stdio.h>
+# include <conio.h>
 #else
-#include <sys/time.h>
-#include <sys/socket.h>
-#include <sys/select.h>
-#include <unistd.h>
+# include <sys/time.h>
+# include <sys/socket.h>
+# include <sys/select.h>
+# include <unistd.h>
 #endif

 #ifdef HAVE_SYS_IOCTL_H
-#include <sys/ioctl.h>
+# include <sys/ioctl.h>
 #endif
 #ifdef HAVE_SYS_FILIO_H
-#include <sys/filio.h>
+# include <sys/filio.h>
 #endif

 #include <time.h>

 #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 +92,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 +234,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 +243,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 +288,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 +299,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. */
--
1.6.1.121.g866a4a




reply via email to

[Prev in Thread] Current Thread [Next in Thread]