bug-gnulib
[Top][All Lists]
Advanced

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

Re: [RFT/RFH] porting the poll module to win32


From: Paolo Bonzini
Subject: Re: [RFT/RFH] porting the poll module to win32
Date: Tue, 19 Aug 2008 08:05:28 +0200
User-agent: Thunderbird 2.0.0.16 (Macintosh/20080707)


What do you think about writing a gnulib self-test that tests whether
poll works correctly?  It would help to test the replacement function on
various platforms quicker, and also helps catch regression.  I suspect
writing a self test may be somewhat complicated though, you'll need to
setup at least two sockets, poll them, and read/write from/to them a
couple of times.

Yes, it can be done. I use poll(2) extensively in GNU Smalltalk, which has a good deal of socket tests and does not work at all if poll(2) does not support console handles.

Alas, I have little time to develop this right now, but can test things
if you work on it.

Yes, here's a follow-up that should fix the syntax errors, to be applied on top of the last patch I sent.

Paolo
diff --git a/lib/poll.c b/lib/poll.c
index ffa6ab0..ff6f4f7 100644
--- a/lib/poll.c
+++ b/lib/poll.c
@@ -25,6 +25,7 @@
 #include "poll.h"
 #include <errno.h>
 #include <limits.h>
+#include <assert.h>
 
 #ifdef __MSVCRT__
 #include <windows.h>
@@ -75,16 +76,16 @@ typedef struct _FILE_PIPE_LOCAL_INFORMATION {
 
 typedef struct _IO_STATUS_BLOCK
 {
-  union u {
-    NTSTATUS Status;
+  union {
+    DWORD Status;
     PVOID Pointer;
-  };
+  } u;
   ULONG_PTR Information;
 } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
 
 #define FilePipeLocalInformation 24
 
-typedef NTSTATUS (NTAPI *PNtQueryInformationFile)
+typedef DWORD (WINAPI *PNtQueryInformationFile)
         (HANDLE, IO_STATUS_BLOCK *, VOID *, ULONG, FILE_INFORMATION_CLASS);
 
 #ifndef PIPE_BUF
@@ -99,6 +100,7 @@ win32_compute_revents (HANDLE h, int sought)
   int i, ret, happened;
   INPUT_RECORD *irbuffer;
   DWORD avail, nbuffer;
+  BOOL bRet;
   IO_STATUS_BLOCK iosb;
   FILE_PIPE_LOCAL_INFORMATION fpli;
   static PNtQueryInformationFile NtQueryInformationFile;
@@ -185,7 +187,7 @@ win32_compute_revents_socket (SOCKET h, int sought,
 
       /* If the event happened on an unconnected server socket,
          that's fine. */
-      else if (r > 0 || ( /* (r == -1) && */ error == ENOTCONN))
+      else if (r > 0 || ( /* (r == -1) && */ error == WSAENOTCONN))
         happened |= (POLLIN | POLLRDNORM) & sought;
 
       /* Distinguish hung-up sockets from other errors.  */
@@ -390,7 +392,7 @@ poll (pfd, nfd, timeout)
   struct timeval tv = { 0, 0 };
   struct timeval *ptv;
   static HANDLE hEvent;
-  HANDLE handle_array[FD_SET_SIZE + 2];
+  HANDLE h, handle_array[FD_SETSIZE + 2];
   DWORD ret, wait_timeout, nhandles;
   int nsock;
   BOOL bRet;
@@ -399,7 +401,7 @@ poll (pfd, nfd, timeout)
   int rc;
   nfds_t i;
 
-  if (nfd < 0 || nfd > FD_SET_SIZE || timeout < 0)
+  if (nfd < 0 || nfd > FD_SETSIZE || timeout < 0)
     {
       errno = EINVAL;
       return -1;
@@ -418,12 +420,12 @@ poll (pfd, nfd, timeout)
   FD_ZERO (&efds);
   for (i = 0; i < nfd; i++)
     {
+      size_t optlen = sizeof(sockbuf);
       if (pfd[i].fd < 0)
         continue;
 
       h = (HANDLE) _get_osfhandle (i);
       assert (h != NULL);
-      optlen = sizeof(sockbuf);
       if ((getsockopt ((SOCKET) h, SOL_SOCKET, SO_TYPE, sockbuf, &optlen)
            != SOCKET_ERROR)
           || WSAGetLastError() != WSAENOTSOCK)
@@ -484,7 +486,7 @@ poll (pfd, nfd, timeout)
     }
 
   /* Now check if the sockets have some event set.  */
-  select (nsock + 1, rfds, wfds, efds, &tv0);
+  select (nsock + 1, &rfds, &wfds, &efds, &tv0);
 
   /* Place a sentinel at the end of the array.  */
   handle_array[nhandles] = NULL;
@@ -503,7 +505,7 @@ poll (pfd, nfd, timeout)
       if (h != handle_array[nhandles])
         {
           /* It's a socket.  */
-          WSAEventSelect (h, 0, 0);
+          WSAEventSelect ((SOCKET) h, 0, 0);
           happened = win32_compute_revents_socket ((SOCKET) h, pfd[i].events,
                                                    &rfds, &wfds, &efds);
         }

reply via email to

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