You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by mt...@apache.org on 2010/08/26 18:05:40 UTC

svn commit: r989795 - in /apr/apr/branches/1.5.x: apr.dsp file_io/win32/pipe.c include/arch/win32/apr_arch_misc.h libapr.dsp

Author: mturk
Date: Thu Aug 26 16:05:40 2010
New Revision: 989795

URL: http://svn.apache.org/viewvc?rev=989795&view=rev
Log:
Backport Win32 part of poll provider for Vista+

Modified:
    apr/apr/branches/1.5.x/apr.dsp
    apr/apr/branches/1.5.x/file_io/win32/pipe.c
    apr/apr/branches/1.5.x/include/arch/win32/apr_arch_misc.h
    apr/apr/branches/1.5.x/libapr.dsp

Modified: apr/apr/branches/1.5.x/apr.dsp
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/apr.dsp?rev=989795&r1=989794&r2=989795&view=diff
==============================================================================
--- apr/apr/branches/1.5.x/apr.dsp (original)
+++ apr/apr/branches/1.5.x/apr.dsp Thu Aug 26 16:05:40 2010
@@ -416,6 +416,10 @@ SOURCE=.\passwd\apr_getpass.c
 # PROP Default_Filter ""
 # Begin Source File
 
+SOURCE=.\poll\unix\poll.c
+# End Source File
+# Begin Source File
+
 SOURCE=.\poll\unix\pollcb.c
 # End Source File
 # Begin Source File

Modified: apr/apr/branches/1.5.x/file_io/win32/pipe.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/file_io/win32/pipe.c?rev=989795&r1=989794&r2=989795&view=diff
==============================================================================
--- apr/apr/branches/1.5.x/file_io/win32/pipe.c (original)
+++ apr/apr/branches/1.5.x/file_io/win32/pipe.c Thu Aug 26 16:05:40 2010
@@ -229,8 +229,9 @@ APR_DECLARE(apr_status_t) apr_os_pipe_pu
 static apr_status_t create_socket_pipe(SOCKET *rd, SOCKET *wr)
 {
     static int id = 0;
-
+    FD_SET rs;
     SOCKET ls;
+    struct timeval socktm;
     struct sockaddr_in pa;
     struct sockaddr_in la;
     struct sockaddr_in ca;
@@ -238,7 +239,7 @@ static apr_status_t create_socket_pipe(S
     apr_status_t rv = APR_SUCCESS;
     int ll = sizeof(la);
     int lc = sizeof(ca);
-    int bm = 1;
+    unsigned long bm = 1;
     int uid[2];
     int iid[2];
 
@@ -290,17 +291,41 @@ static apr_status_t create_socket_pipe(S
         goto cleanup;
     }
     for (;;) {
+        int ns;
+        int nc = 0;
         /* Listening socket is nonblocking by now.
-         * The accept must create the socket
-         * immediatelly because we connected already.
+         * The accept should create the socket
+         * immediatelly because we are connected already.
+         * However on buys systems this can take a while
+         * until winsock gets a chance to handle the events.
          */
+        FD_ZERO(&rs);
+        FD_SET(ls, &rs);
+
+        socktm.tv_sec  = 1;
+        socktm.tv_usec = 0;
+        if ((ns = select(0, &rs, NULL, NULL, &socktm)) == SOCKET_ERROR) {
+            /* Accept still not signaled */
+            Sleep(100);
+            continue;
+        }
+        if (ns == 0) {
+            /* No connections in the last second */
+            continue;
+        }
         if ((*rd = accept(ls, (SOCKADDR *)&ca, &lc)) == INVALID_SOCKET) {
             rv =  apr_get_netos_error();
             goto cleanup;
         }
         /* Verify the connection by reading the send identification.
          */
-        nrd = recv(*rd, (char *)iid, sizeof(iid), 0);
+        do {
+            if (nc++)
+                Sleep(1);
+            nrd = recv(*rd, (char *)iid, sizeof(iid), 0);
+            rv = nrd == SOCKET_ERROR ? apr_get_netos_error() : APR_SUCCESS;
+        } while (APR_STATUS_IS_EAGAIN(rv));
+
         if (nrd == sizeof(iid)) {
             if (memcmp(uid, iid, sizeof(uid)) == 0) {
                 /* Wow, we recived what we send.
@@ -316,7 +341,6 @@ static apr_status_t create_socket_pipe(S
             }
         }
         else if (nrd == SOCKET_ERROR) {
-            rv =  apr_get_netos_error();
             goto cleanup;
         }
         closesocket(*rd);

Modified: apr/apr/branches/1.5.x/include/arch/win32/apr_arch_misc.h
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/include/arch/win32/apr_arch_misc.h?rev=989795&r1=989794&r2=989795&view=diff
==============================================================================
--- apr/apr/branches/1.5.x/include/arch/win32/apr_arch_misc.h (original)
+++ apr/apr/branches/1.5.x/include/arch/win32/apr_arch_misc.h Thu Aug 26 16:05:40 2010
@@ -186,18 +186,24 @@ FARPROC apr_load_dll_func(apr_dlltoken_e
 /* The apr_load_dll_func call WILL return 0 set error to
  * ERROR_INVALID_FUNCTION if the function cannot be loaded
  */
-
 #define APR_DECLARE_LATE_DLL_FUNC(lib, rettype, calltype, fn, ord, args, names) \
     typedef rettype (calltype *apr_winapi_fpt_##fn) args; \
     static apr_winapi_fpt_##fn apr_winapi_pfn_##fn = NULL; \
-    static APR_INLINE rettype apr_winapi_##fn args \
-    {   if (!apr_winapi_pfn_##fn) \
+    static int apr_winapi_chk_##fn = 0; \
+    static APR_INLINE int apr_winapi_ld_##fn(void) \
+    {   if (apr_winapi_pfn_##fn) return 1; \
+        if (apr_winapi_chk_##fn ++) return 0; \
+        if (!apr_winapi_pfn_##fn) \
             apr_winapi_pfn_##fn = (apr_winapi_fpt_##fn) \
                                       apr_load_dll_func(lib, #fn, ord); \
-        if (apr_winapi_pfn_##fn) \
+        if (apr_winapi_pfn_##fn) return 1; else return 0; }; \
+    static APR_INLINE rettype apr_winapi_##fn args \
+    {   if (apr_winapi_ld_##fn()) \
             return (*(apr_winapi_pfn_##fn)) names; \
         else { SetLastError(ERROR_INVALID_FUNCTION); return 0;} }; \
 
+#define APR_HAVE_LATE_DLL_FUNC(fn) apr_winapi_ld_##fn()
+
 /* Provide late bound declarations of every API function missing from
  * one or more supported releases of the Win32 API
  *
@@ -432,6 +438,48 @@ APR_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI
     (hSnapshot, lppe));
 #define Process32NextW apr_winapi_Process32NextW
 
+#if !defined(POLLERR)
+/* Event flag definitions for WSAPoll(). */
+#define POLLRDNORM  0x0100
+#define POLLRDBAND  0x0200
+#define POLLIN      (POLLRDNORM | POLLRDBAND)
+#define POLLPRI     0x0400
+
+#define POLLWRNORM  0x0010
+#define POLLOUT     (POLLWRNORM)
+#define POLLWRBAND  0x0020
+
+#define POLLERR     0x0001
+#define POLLHUP     0x0002
+#define POLLNVAL    0x0004
+
+typedef struct pollfd {
+    SOCKET  fd;
+    SHORT   events;
+    SHORT   revents;
+
+} WSAPOLLFD, *PWSAPOLLFD, FAR *LPWSAPOLLFD;
+
+#endif /* !defined(POLLERR) */
+#ifdef WSAPoll
+#undef WSAPoll
+#endif
+APR_DECLARE_LATE_DLL_FUNC(DLL_WINSOCK2API, int, WSAAPI, WSAPoll, 0, (
+    IN OUT LPWSAPOLLFD fdArray,
+    IN ULONG fds,
+    IN INT timeout),
+    (fdArray, fds, timeout));
+#define WSAPoll apr_winapi_WSAPoll
+#define HAVE_POLL   1
+
+#ifdef SetDllDirectoryW
+#undef SetDllDirectoryW
+#endif
+APR_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, BOOL, WINAPI, SetDllDirectoryW, 0, (
+    IN LPCWSTR lpPathName),
+    (lpPathName));
+#define SetDllDirectoryW apr_winapi_SetDllDirectoryW
+
 #endif /* !defined(_WIN32_WCE) */
 
 #endif  /* ! MISC_H */

Modified: apr/apr/branches/1.5.x/libapr.dsp
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/libapr.dsp?rev=989795&r1=989794&r2=989795&view=diff
==============================================================================
--- apr/apr/branches/1.5.x/libapr.dsp (original)
+++ apr/apr/branches/1.5.x/libapr.dsp Thu Aug 26 16:05:40 2010
@@ -468,6 +468,10 @@ SOURCE=.\passwd\apr_getpass.c
 # PROP Default_Filter ""
 # Begin Source File
 
+SOURCE=.\poll\unix\poll.c
+# End Source File
+# Begin Source File
+
 SOURCE=.\poll\unix\pollcb.c
 # End Source File
 # Begin Source File