You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by iv...@apache.org on 2022/01/19 16:41:59 UTC

svn commit: r1897208 - in /apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation: file_io/win32/ include/arch/unix/ include/arch/win32/ poll/unix/

Author: ivan
Date: Wed Jan 19 16:41:59 2022
New Revision: 1897208

URL: http://svn.apache.org/viewvc?rev=1897208&view=rev
Log:
On 'win32-pollset-wakeup-no-file-socket-emulation' branch:

Windows: For the pollset wakeup, use apr_socket_t directly instead of using a
socket disguised as an apr_file_t.

* file_io/win32/pipe.c
  (): Include apr_arch_networkio.h.
  (socket_pipe_cleanup, apr_file_socket_pipe_create,
   apr_file_socket_pipe_close): Update to use apr_socket_t instead of apr_file_t.

* include/arch/unix/apr_arch_poll_private.h
  (WAKEUP_USES_PIPE): New #define to specify mechanism used for pollset wakeup.
  (apr_pollset_t, apr_pollcb_t): Add wakeup_socket if not WAKEUP_USES_PIPE.
  (apr_poll_create_wakeup_socket, apr_poll_close_wakeup_socket,
   apr_poll_drain_wakeup_socket): Declare if not WAKEUP_USES_PIPE.

* include/arch/win32/apr_arch_file_io.h
  (apr_file_socket_pipe_create, apr_file_socket_pipe_close): Update to use
   apr_socket_t instead of apr_file_t.
  
* poll/unix/poll.c
  (impl_pollset_add): Remove hack that allows apr_file_t even if
   APR_FILES_AS_SOCKETS == 0.
  (impl_pollset_poll, impl_pollcb_poll): Use wakeup_pipe or wakeup_socket
   depending of WAKEUP_USES_PIPE.

* poll/unix/pollcb.c
  (pollcb_cleanup, apr_pollcb_create_ex, apr_pollcb_wakeup): Use wakeup_pipe
   or wakeup_socket depending of WAKEUP_USES_PIPE.

* poll/unix/pollset.c
  (pollset_cleanup, apr_pollset_create_ex, apr_pollset_wakeup): Use wakeup_pipe
   or wakeup_socket depending of WAKEUP_USES_PIPE.

* poll/unix/select.c
  (impl_pollset_add): Remove hack that allows apr_file_t even if
   APR_FILES_AS_SOCKETS == 0.
  (impl_pollset_poll): Use wakeup_pipe or wakeup_socket depending of
   WAKEUP_USES_PIPE.

* poll/unix/wakeup.c
  (apr_poll_create_wakeup_pipe): Rename to apr_poll_create_wakeup_socket()
   on Windows and use apr_socket_t instead of apr_file_t.
  (apr_poll_close_wakeup_pipe): Rename to apr_poll_close_wakeup_socket()
   on Windows and use apr_socket_t instead of apr_file_t.
  (apr_poll_drain_wakeup_socket): New.

Modified:
    apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/file_io/win32/pipe.c
    apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/include/arch/unix/apr_arch_poll_private.h
    apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/include/arch/win32/apr_arch_file_io.h
    apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/poll/unix/poll.c
    apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/poll/unix/pollcb.c
    apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/poll/unix/pollset.c
    apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/poll/unix/select.c
    apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/poll/unix/wakeup.c

Modified: apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/file_io/win32/pipe.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/file_io/win32/pipe.c?rev=1897208&r1=1897207&r2=1897208&view=diff
==============================================================================
--- apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/file_io/win32/pipe.c (original)
+++ apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/file_io/win32/pipe.c Wed Jan 19 16:41:59 2022
@@ -15,6 +15,7 @@
  */
 
 #include "apr_arch_file_io.h"
+#include "apr_arch_networkio.h"
 #include "apr_file_io.h"
 #include "apr_general.h"
 #include "apr_strings.h"
@@ -411,53 +412,31 @@ cleanup:
 
 static apr_status_t socket_pipe_cleanup(void *thefile)
 {
-    apr_file_t *file = thefile;
-    if (file->filehand != INVALID_HANDLE_VALUE) {
-        shutdown((SOCKET)file->filehand, SD_BOTH);
-        closesocket((SOCKET)file->filehand);
-        file->filehand = INVALID_HANDLE_VALUE;
+    apr_socket_t *file = thefile;
+    if (file->socketdes != INVALID_SOCKET) {
+        shutdown(file->socketdes, SD_BOTH);
+        closesocket(file->socketdes);
+        file->socketdes = INVALID_SOCKET;
     }
     return APR_SUCCESS;
 }
 
-apr_status_t apr_file_socket_pipe_create(apr_file_t **in,
-                                         apr_file_t **out,
+apr_status_t apr_file_socket_pipe_create(apr_socket_t **in,
+                                         apr_socket_t **out,
                                          apr_pool_t *p)
 {
     apr_status_t rv;
     SOCKET rd;
     SOCKET wr;
 
+    *in = NULL;
+    *out = NULL;
+
     if ((rv = create_socket_pipe(&rd, &wr)) != APR_SUCCESS) {
         return rv;
     }
-    (*in) = (apr_file_t *)apr_pcalloc(p, sizeof(apr_file_t));
-    (*in)->pool = p;
-    (*in)->fname = NULL;
-    (*in)->ftype = APR_FILETYPE_SOCKET;
-    (*in)->timeout = 0; /* read end of the pipe is non-blocking */
-    (*in)->ungetchar = -1;
-    (*in)->eof_hit = 0;
-    (*in)->filePtr = 0;
-    (*in)->bufpos = 0;
-    (*in)->dataRead = 0;
-    (*in)->direction = 0;
-    (*in)->pOverlapped = NULL;
-    (*in)->filehand = (HANDLE)rd;
-
-    (*out) = (apr_file_t *)apr_pcalloc(p, sizeof(apr_file_t));
-    (*out)->pool = p;
-    (*out)->fname = NULL;
-    (*out)->ftype = APR_FILETYPE_SOCKET;
-    (*out)->timeout = -1;
-    (*out)->ungetchar = -1;
-    (*out)->eof_hit = 0;
-    (*out)->filePtr = 0;
-    (*out)->bufpos = 0;
-    (*out)->dataRead = 0;
-    (*out)->direction = 0;
-    (*out)->pOverlapped = NULL;
-    (*out)->filehand = (HANDLE)wr;
+    apr_os_sock_put(in, &rd, p);
+    apr_os_sock_put(out, &wr, p);
 
     apr_pool_cleanup_register(p, (void *)(*in), socket_pipe_cleanup,
                               apr_pool_cleanup_null);
@@ -467,17 +446,11 @@ apr_status_t apr_file_socket_pipe_create
     return rv;
 }
 
-apr_status_t apr_file_socket_pipe_close(apr_file_t *file)
+apr_status_t apr_file_socket_pipe_close(apr_socket_t *socket)
 {
     apr_status_t stat;
-    if (file->ftype != APR_FILETYPE_SOCKET)
-        return apr_file_close(file);
-    if ((stat = socket_pipe_cleanup(file)) == APR_SUCCESS) {
-        apr_pool_cleanup_kill(file->pool, file, socket_pipe_cleanup);
-
-        if (file->mutex) {
-            apr_thread_mutex_destroy(file->mutex);
-        }
+    if ((stat = socket_pipe_cleanup(socket)) == APR_SUCCESS) {
+        apr_pool_cleanup_kill(socket->pool, socket, socket_pipe_cleanup);
 
         return APR_SUCCESS;
     }

Modified: apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/include/arch/unix/apr_arch_poll_private.h
URL: http://svn.apache.org/viewvc/apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/include/arch/unix/apr_arch_poll_private.h?rev=1897208&r1=1897207&r2=1897208&view=diff
==============================================================================
--- apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/include/arch/unix/apr_arch_poll_private.h (original)
+++ apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/include/arch/unix/apr_arch_poll_private.h Wed Jan 19 16:41:59 2022
@@ -81,6 +81,12 @@
 #endif
 #endif
 
+#ifdef WIN32
+#define WAKEUP_USES_PIPE 0
+#else
+#define WAKEUP_USES_PIPE 1
+#endif
+
 #if defined(POLLSET_USES_KQUEUE) || defined(POLLSET_USES_EPOLL) || defined(POLLSET_USES_PORT) || defined(POLLSET_USES_AIO_MSGQ)
 
 #include "apr_ring.h"
@@ -121,7 +127,11 @@ struct apr_pollset_t
     apr_uint32_t nalloc;
     apr_uint32_t flags;
     /* Pipe descriptors used for wakeup */
+#if WAKEUP_USES_PIPE
     apr_file_t *wakeup_pipe[2];
+#else
+    apr_socket_t *wakeup_socket[2];
+#endif
     apr_pollfd_t wakeup_pfd;
     volatile apr_uint32_t wakeup_set;
     apr_pollset_private_t *p;
@@ -150,7 +160,11 @@ struct apr_pollcb_t {
     apr_uint32_t nalloc;
     apr_uint32_t flags;
     /* Pipe descriptors used for wakeup */
+#if WAKEUP_USES_PIPE
     apr_file_t *wakeup_pipe[2];
+#else
+    apr_socket_t *wakeup_socket[2];
+#endif
     apr_pollfd_t wakeup_pfd;
     volatile apr_uint32_t wakeup_set;
     int fd;
@@ -181,9 +195,16 @@ struct apr_pollcb_provider_t {
  * Private functions used for the implementation of both apr_pollcb_* and 
  * apr_pollset_*
  */
-apr_status_t apr_poll_create_wakeup_pipe(apr_pool_t *pool, apr_pollfd_t *pfd, 
+#if WAKEUP_USES_PIPE
+apr_status_t apr_poll_create_wakeup_pipe(apr_pool_t *pool, apr_pollfd_t *pfd,
                                          apr_file_t **wakeup_pipe);
 apr_status_t apr_poll_close_wakeup_pipe(apr_file_t **wakeup_pipe);
 void apr_poll_drain_wakeup_pipe(volatile apr_uint32_t *wakeup_set, apr_file_t **wakeup_pipe);
+#else
+apr_status_t apr_poll_create_wakeup_socket(apr_pool_t *pool, apr_pollfd_t *pfd,
+                                         apr_socket_t **wakeup_socket);
+apr_status_t apr_poll_close_wakeup_socket(apr_socket_t **wakeup_socket);
+void apr_poll_drain_wakeup_socket(volatile apr_uint32_t *wakeup_set, apr_socket_t **wakeup_socket);
+#endif
 
 #endif /* APR_ARCH_POLL_PRIVATE_H */

Modified: apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/include/arch/win32/apr_arch_file_io.h
URL: http://svn.apache.org/viewvc/apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/include/arch/win32/apr_arch_file_io.h?rev=1897208&r1=1897207&r2=1897208&view=diff
==============================================================================
--- apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/include/arch/win32/apr_arch_file_io.h (original)
+++ apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/include/arch/win32/apr_arch_file_io.h Wed Jan 19 16:41:59 2022
@@ -251,11 +251,11 @@ apr_status_t filepath_root_case(char **r
 apr_status_t file_cleanup(void *);
 
 extern apr_status_t
-apr_file_socket_pipe_create(apr_file_t **in,
-                            apr_file_t **out,
+apr_file_socket_pipe_create(apr_socket_t **in,
+                            apr_socket_t **out,
                             apr_pool_t *p);
 
 extern apr_status_t
-apr_file_socket_pipe_close(apr_file_t *file);
+apr_file_socket_pipe_close(apr_socket_t *socket);
 
 #endif  /* ! FILE_IO_H */

Modified: apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/poll/unix/poll.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/poll/unix/poll.c?rev=1897208&r1=1897207&r2=1897208&view=diff
==============================================================================
--- apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/poll/unix/poll.c (original)
+++ apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/poll/unix/poll.c Wed Jan 19 16:41:59 2022
@@ -187,11 +187,7 @@ static apr_status_t impl_pollset_add(apr
 #if APR_FILES_AS_SOCKETS
         pollset->p->pollset[pollset->nelts].fd = descriptor->desc.f->filedes;
 #else
-        if ((pollset->flags & APR_POLLSET_WAKEABLE) &&
-            descriptor->desc.f == pollset->wakeup_pipe[0])
-            pollset->p->pollset[pollset->nelts].fd = (SOCKET)descriptor->desc.f->filedes;
-        else
-            return APR_EBADF;
+        return APR_EBADF;
 #endif
     }
     pollset->p->pollset[pollset->nelts].events =
@@ -272,12 +268,21 @@ static apr_status_t impl_pollset_poll(ap
                 /* Check if the polled descriptor is our
                  * wakeup pipe. In that case do not put it result set.
                  */
+#if WAKEUP_USES_PIPE
                 if ((pollset->flags & APR_POLLSET_WAKEABLE) &&
                     pollset->p->query_set[i].desc_type == APR_POLL_FILE &&
                     pollset->p->query_set[i].desc.f == pollset->wakeup_pipe[0]) {
                     apr_poll_drain_wakeup_pipe(&pollset->wakeup_set, pollset->wakeup_pipe);
                     rv = APR_EINTR;
                 }
+#else
+                if ((pollset->flags & APR_POLLSET_WAKEABLE) &&
+                    pollset->p->query_set[i].desc_type == APR_POLL_SOCKET &&
+                    pollset->p->query_set[i].desc.s == pollset->wakeup_socket[0]) {
+                    apr_poll_drain_wakeup_socket(&pollset->wakeup_set, pollset->wakeup_socket);
+                    rv = APR_EINTR;
+                }
+#endif
                 else {
                     pollset->p->result_set[j] = pollset->p->query_set[i];
                     pollset->p->result_set[j].rtnevents =
@@ -419,13 +424,21 @@ static apr_status_t impl_pollcb_poll(apr
             if (pollcb->pollset.ps[i].revents != 0) {
                 apr_pollfd_t *pollfd = pollcb->copyset[i];
 
+#if WAKEUP_USES_PIPE
                 if ((pollcb->flags & APR_POLLSET_WAKEABLE) &&
                     pollfd->desc_type == APR_POLL_FILE &&
                     pollfd->desc.f == pollcb->wakeup_pipe[0]) {
                     apr_poll_drain_wakeup_pipe(&pollcb->wakeup_set, pollcb->wakeup_pipe);
                     return APR_EINTR;
                 }
-
+#else
+                if ((pollcb->flags & APR_POLLSET_WAKEABLE) &&
+                    pollfd->desc_type == APR_POLL_SOCKET &&
+                    pollfd->desc.s == pollcb->wakeup_socket[0]) {
+                    apr_poll_drain_wakeup_socket(&pollcb->wakeup_set, pollcb->wakeup_socket);
+                    return APR_EINTR;
+                }
+#endif
                 pollfd->rtnevents = get_revent(pollcb->pollset.ps[i].revents);                    
                 rv = func(baton, pollfd);
                 if (rv) {

Modified: apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/poll/unix/pollcb.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/poll/unix/pollcb.c?rev=1897208&r1=1897207&r2=1897208&view=diff
==============================================================================
--- apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/poll/unix/pollcb.c (original)
+++ apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/poll/unix/pollcb.c Wed Jan 19 16:41:59 2022
@@ -82,7 +82,11 @@ static apr_status_t pollcb_cleanup(void
         (*pollcb->provider->cleanup)(pollcb);
     }
     if (pollcb->flags & APR_POLLSET_WAKEABLE) {
+#if WAKEUP_USES_PIPE
         apr_poll_close_wakeup_pipe(pollcb->wakeup_pipe);
+#else
+        apr_poll_close_wakeup_socket(pollcb->wakeup_socket);
+#endif
     }
 
     return APR_SUCCESS;
@@ -163,12 +167,21 @@ APR_DECLARE(apr_status_t) apr_pollcb_cre
     }
 
     if (flags & APR_POLLSET_WAKEABLE) {
+#if WAKEUP_USES_PIPE
         /* Create wakeup pipe */
         if ((rv = apr_poll_create_wakeup_pipe(pollcb->pool, &pollcb->wakeup_pfd,
-                                              pollcb->wakeup_pipe)) 
-                != APR_SUCCESS) {
+                                              pollcb->wakeup_pipe))
+            != APR_SUCCESS) {
             return rv;
         }
+#else
+        /* Create wakeup socket */
+        if ((rv = apr_poll_create_wakeup_socket(pollcb->pool, &pollcb->wakeup_pfd,
+                                                pollcb->wakeup_socket))
+            != APR_SUCCESS) {
+            return rv;
+        }
+#endif
 
         if ((rv = apr_pollcb_add(pollcb, &pollcb->wakeup_pfd)) != APR_SUCCESS) {
             return rv;
@@ -217,8 +230,14 @@ APR_DECLARE(apr_status_t) apr_pollcb_wak
     if (!(pollcb->flags & APR_POLLSET_WAKEABLE))
         return APR_EINIT;
 
-    if (apr_atomic_cas32(&pollcb->wakeup_set, 1, 0) == 0)
+    if (apr_atomic_cas32(&pollcb->wakeup_set, 1, 0) == 0) {
+#if WAKEUP_USES_PIPE
         return apr_file_putc(1, pollcb->wakeup_pipe[1]);
+#else
+        apr_size_t len = 1;
+        return apr_socket_send(pollcb->wakeup_socket[1], "\1", &len);
+#endif
+    }
 
     return APR_SUCCESS;
 }

Modified: apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/poll/unix/pollset.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/poll/unix/pollset.c?rev=1897208&r1=1897207&r2=1897208&view=diff
==============================================================================
--- apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/poll/unix/pollset.c (original)
+++ apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/poll/unix/pollset.c Wed Jan 19 16:41:59 2022
@@ -38,7 +38,11 @@ static apr_status_t pollset_cleanup(void
         (*pollset->provider->cleanup)(pollset);
     }
     if (pollset->flags & APR_POLLSET_WAKEABLE) {
+#if WAKEUP_USES_PIPE
         apr_poll_close_wakeup_pipe(pollset->wakeup_pipe);
+#else
+        apr_poll_close_wakeup_socket(pollset->wakeup_socket);
+#endif
     }
 
     return APR_SUCCESS;
@@ -162,13 +166,21 @@ APR_DECLARE(apr_status_t) apr_pollset_cr
         return rv;
     }
     if (flags & APR_POLLSET_WAKEABLE) {
+#if WAKEUP_USES_PIPE
         /* Create wakeup pipe */
         if ((rv = apr_poll_create_wakeup_pipe(pollset->pool, &pollset->wakeup_pfd,
                                               pollset->wakeup_pipe))
                 != APR_SUCCESS) {
             return rv;
         }
-
+#else
+        /* Create wakeup socket */
+        if ((rv = apr_poll_create_wakeup_socket(pollset->pool, &pollset->wakeup_pfd,
+                                                pollset->wakeup_socket))
+            != APR_SUCCESS) {
+            return rv;
+        }
+#endif
         if ((rv = apr_pollset_add(pollset, &pollset->wakeup_pfd)) != APR_SUCCESS) {
             return rv;
         }
@@ -221,8 +233,14 @@ APR_DECLARE(apr_status_t) apr_pollset_wa
     if (!(pollset->flags & APR_POLLSET_WAKEABLE))
         return APR_EINIT;
 
-    if (apr_atomic_cas32(&pollset->wakeup_set, 1, 0) == 0)
+    if (apr_atomic_cas32(&pollset->wakeup_set, 1, 0) == 0) {
+#if WAKEUP_USES_PIPE
         return apr_file_putc(1, pollset->wakeup_pipe[1]);
+#else
+        apr_size_t len = 1;
+        return apr_socket_send(pollset->wakeup_socket[1], "\1", &len);
+#endif
+    }
 
     return APR_SUCCESS;
 }

Modified: apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/poll/unix/select.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/poll/unix/select.c?rev=1897208&r1=1897207&r2=1897208&view=diff
==============================================================================
--- apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/poll/unix/select.c (original)
+++ apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/poll/unix/select.c Wed Jan 19 16:41:59 2022
@@ -248,11 +248,7 @@ static apr_status_t impl_pollset_add(apr
     }
     else {
 #if !APR_FILES_AS_SOCKETS
-        if ((pollset->flags & APR_POLLSET_WAKEABLE) &&
-            descriptor->desc.f == pollset->wakeup_pipe[0])
-            fd = (apr_os_sock_t)descriptor->desc.f->filedes;
-        else
-            return APR_EBADF;
+        return APR_EBADF;
 #else
 #ifdef NETWARE
         /* NetWare can't handle mixed descriptor types in select() */
@@ -395,23 +391,34 @@ static apr_status_t impl_pollset_poll(ap
     j = 0;
     for (i = 0; i < pollset->nelts; i++) {
         apr_os_sock_t fd;
-        if (pollset->p->query_set[i].desc_type == APR_POLL_SOCKET) {
-            fd = pollset->p->query_set[i].desc.s->socketdes;
-        }
-        else {
-            if ((pollset->flags & APR_POLLSET_WAKEABLE) &&
+
+        if (pollset->flags & APR_POLLSET_WAKEABLE) {
+#if WAKEUP_USES_PIPE
+            if (pollset->p->query_set[i].desc_type == APR_POLL_FILE &&
                 pollset->p->query_set[i].desc.f == pollset->wakeup_pipe[0]) {
                 apr_poll_drain_wakeup_pipe(&pollset->wakeup_set, pollset->wakeup_pipe);
                 rv = APR_EINTR;
                 continue;
             }
-            else {
+#else
+            if (pollset->p->query_set[i].desc_type == APR_POLL_SOCKET &&
+                pollset->p->query_set[i].desc.s == pollset->wakeup_socket[0]) {
+                apr_poll_drain_wakeup_socket(&pollset->wakeup_set, pollset->wakeup_socket);
+                rv = APR_EINTR;
+                continue;
+            }
+#endif
+        }
+
+        if (pollset->p->query_set[i].desc_type == APR_POLL_SOCKET) {
+            fd = pollset->p->query_set[i].desc.s->socketdes;
+        }
+        else {
 #if !APR_FILES_AS_SOCKETS
-                return APR_EBADF;
+            return APR_EBADF;
 #else
-                fd = pollset->p->query_set[i].desc.f->filedes;
+            fd = pollset->p->query_set[i].desc.f->filedes;
 #endif
-            }
         }
         if (FD_ISSET(fd, &readset) || FD_ISSET(fd, &writeset) ||
             FD_ISSET(fd, &exceptset)) {

Modified: apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/poll/unix/wakeup.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/poll/unix/wakeup.c?rev=1897208&r1=1897207&r2=1897208&view=diff
==============================================================================
--- apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/poll/unix/wakeup.c (original)
+++ apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/poll/unix/wakeup.c Wed Jan 19 16:41:59 2022
@@ -28,34 +28,34 @@
 
 #ifdef WIN32
 
-apr_status_t apr_poll_create_wakeup_pipe(apr_pool_t *pool, apr_pollfd_t *pfd,
-                                         apr_file_t **wakeup_pipe)
+apr_status_t apr_poll_create_wakeup_socket(apr_pool_t *pool, apr_pollfd_t *pfd,
+                                           apr_socket_t **wakeup_socket)
 {
     apr_status_t rv;
 
-    if ((rv = apr_file_socket_pipe_create(&wakeup_pipe[0], &wakeup_pipe[1],
+    if ((rv = apr_file_socket_pipe_create(&wakeup_socket[0], &wakeup_socket[1],
                                           pool)) != APR_SUCCESS)
         return rv;
 
     pfd->reqevents = APR_POLLIN;
-    pfd->desc_type = APR_POLL_FILE;
-    pfd->desc.f = wakeup_pipe[0];
+    pfd->desc_type = APR_POLL_SOCKET;
+    pfd->desc.s = wakeup_socket[0];
     return APR_SUCCESS;
 }
 
-apr_status_t apr_poll_close_wakeup_pipe(apr_file_t **wakeup_pipe)
+apr_status_t apr_poll_close_wakeup_socket(apr_socket_t **wakeup_socket)
 {
     apr_status_t rv0 = APR_SUCCESS;
     apr_status_t rv1 = APR_SUCCESS;
 
     /* Close both sides of the wakeup pipe */
-    if (wakeup_pipe[0]) {
-        rv0 = apr_file_socket_pipe_close(wakeup_pipe[0]);
-        wakeup_pipe[0] = NULL;
-    }
-    if (wakeup_pipe[1]) {
-        rv1 = apr_file_socket_pipe_close(wakeup_pipe[1]);
-        wakeup_pipe[1] = NULL;
+    if (wakeup_socket[0]) {
+        rv0 = apr_file_socket_pipe_close(wakeup_socket[0]);
+        wakeup_socket[0] = NULL;
+    }
+    if (wakeup_socket[1]) {
+        rv1 = apr_file_socket_pipe_close(wakeup_socket[1]);
+        wakeup_socket[1] = NULL;
     }
     return rv0 ? rv0 : rv1;
 }
@@ -134,6 +134,7 @@ apr_status_t apr_poll_close_wakeup_pipe(
 
 #endif /* APR_FILES_AS_SOCKETS */
 
+#if WAKEUP_USES_PIPE
 /* Read and discard whatever is in the wakeup pipe.
  */
 void apr_poll_drain_wakeup_pipe(volatile apr_uint32_t *wakeup_set, apr_file_t **wakeup_pipe)
@@ -143,4 +144,15 @@ void apr_poll_drain_wakeup_pipe(volatile
     (void)apr_file_getc(&ch, wakeup_pipe[0]);
     apr_atomic_set32(wakeup_set, 0);
 }
+#else
+/* Read and discard whatever is in the wakeup socket.
+ */
+void apr_poll_drain_wakeup_socket(volatile apr_uint32_t *wakeup_set, apr_socket_t **wakeup_socket)
+{
+    char ch;
+    apr_size_t len;
 
+    (void)apr_socket_recv(wakeup_socket[0], &ch, &len);
+    apr_atomic_set32(wakeup_set, 0);
+}
+#endif
\ No newline at end of file



Re: svn commit: r1897208 - in /apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation: file_io/win32/ include/arch/unix/ include/arch/win32/ poll/unix/

Posted by Ivan Zhakov <iv...@visualsvn.com>.
On Thu, 20 Jan 2022 at 01:00, Yann Ylavic <yl...@gmail.com> wrote:

> On Wed, Jan 19, 2022 at 5:42 PM <iv...@apache.org> wrote:
> >
> > Author: ivan
> > Date: Wed Jan 19 16:41:59 2022
> > New Revision: 1897208
> >
> > URL: http://svn.apache.org/viewvc?rev=1897208&view=rev
> > Log:
> > On 'win32-pollset-wakeup-no-file-socket-emulation' branch:
> >
> > Windows: For the pollset wakeup, use apr_socket_t directly instead of
> using a
> > socket disguised as an apr_file_t.
> []
> >
> > -apr_status_t apr_file_socket_pipe_create(apr_file_t **in,
> > -                                         apr_file_t **out,
> > +apr_status_t apr_file_socket_pipe_create(apr_socket_t **in,
> > +                                         apr_socket_t **out,
> >                                           apr_pool_t *p)
> >  {
> >      apr_status_t rv;
> >      SOCKET rd;
> >      SOCKET wr;
> >
> > +    *in = NULL;
> > +    *out = NULL;
> > +
> >      if ((rv = create_socket_pipe(&rd, &wr)) != APR_SUCCESS) {
> >          return rv;
> >      }
> > -    (*in) = (apr_file_t *)apr_pcalloc(p, sizeof(apr_file_t));
> > -    (*in)->pool = p;
> > -    (*in)->fname = NULL;
> > -    (*in)->ftype = APR_FILETYPE_SOCKET;
> > -    (*in)->timeout = 0; /* read end of the pipe is non-blocking */
> > -    (*in)->ungetchar = -1;
> > -    (*in)->eof_hit = 0;
> > -    (*in)->filePtr = 0;
> > -    (*in)->bufpos = 0;
> > -    (*in)->dataRead = 0;
> > -    (*in)->direction = 0;
> > -    (*in)->pOverlapped = NULL;
> > -    (*in)->filehand = (HANDLE)rd;
> > -
> > -    (*out) = (apr_file_t *)apr_pcalloc(p, sizeof(apr_file_t));
> > -    (*out)->pool = p;
> > -    (*out)->fname = NULL;
> > -    (*out)->ftype = APR_FILETYPE_SOCKET;
> > -    (*out)->timeout = -1;
> > -    (*out)->ungetchar = -1;
> > -    (*out)->eof_hit = 0;
> > -    (*out)->filePtr = 0;
> > -    (*out)->bufpos = 0;
> > -    (*out)->dataRead = 0;
> > -    (*out)->direction = 0;
> > -    (*out)->pOverlapped = NULL;
> > -    (*out)->filehand = (HANDLE)wr;
> > +    apr_os_sock_put(in, &rd, p);
> > +    apr_os_sock_put(out, &wr, p);
>
> I think that the *in apr_socket and the underlying socket descriptor
> are not aligned w.r.t. non-blocking.
> We probably need to call apr_socket_timeout_set(*in, 0) here to make
> that happen, thus remove the last ioctlsocket() in
> create_socket_pipe() that sets the descriptor non-blocking before
> leaving (which would be useless now).
>
> Something like the below on top of your branch?
>
> Index: file_io/win32/pipe.c
> ===================================================================
> --- file_io/win32/pipe.c    (revision 1897212)
> +++ file_io/win32/pipe.c    (working copy)
> @@ -381,14 +381,7 @@ static apr_status_t create_socket_pipe(SOCKET *rd,
>              goto cleanup;
>          }
>          if (nrd == (int)sizeof(uid) && memcmp(iid, uid, sizeof(uid)) ==
> 0) {
> -            /* Got the right identifier, put the poll()able read side of
> -             * the pipe in nonblocking mode and return.
> -             */
> -            bm = 1;
> -            if (ioctlsocket(*rd, FIONBIO, &bm) == SOCKET_ERROR) {
> -                rv = apr_get_netos_error();
> -                goto cleanup;
> -            }
> +            /* Got the right identifier, return. */
>              break;
>          }
>          closesocket(*rd);
> @@ -438,6 +431,9 @@ apr_status_t apr_file_socket_pipe_create(apr_socke
>      apr_os_sock_put(in, &rd, p);
>      apr_os_sock_put(out, &wr, p);
>
> +    /* read end of the pipe is non-blocking */
> +    apr_socket_timeout_set(*in, 0);
> +
>      apr_pool_cleanup_register(p, (void *)(*in), socket_pipe_cleanup,
>                                apr_pool_cleanup_null);
>      apr_pool_cleanup_register(p, (void *)(*out), socket_pipe_cleanup,
> --
>
>
Makes sense to me. Committed  in r1897245 .

Thanks!


-- 
Ivan Zhakov

Re: svn commit: r1897208 - in /apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation: file_io/win32/ include/arch/unix/ include/arch/win32/ poll/unix/

Posted by Yann Ylavic <yl...@gmail.com>.
On Wed, Jan 19, 2022 at 5:42 PM <iv...@apache.org> wrote:
>
> Author: ivan
> Date: Wed Jan 19 16:41:59 2022
> New Revision: 1897208
>
> URL: http://svn.apache.org/viewvc?rev=1897208&view=rev
> Log:
> On 'win32-pollset-wakeup-no-file-socket-emulation' branch:
>
> Windows: For the pollset wakeup, use apr_socket_t directly instead of using a
> socket disguised as an apr_file_t.
[]
>
> -apr_status_t apr_file_socket_pipe_create(apr_file_t **in,
> -                                         apr_file_t **out,
> +apr_status_t apr_file_socket_pipe_create(apr_socket_t **in,
> +                                         apr_socket_t **out,
>                                           apr_pool_t *p)
>  {
>      apr_status_t rv;
>      SOCKET rd;
>      SOCKET wr;
>
> +    *in = NULL;
> +    *out = NULL;
> +
>      if ((rv = create_socket_pipe(&rd, &wr)) != APR_SUCCESS) {
>          return rv;
>      }
> -    (*in) = (apr_file_t *)apr_pcalloc(p, sizeof(apr_file_t));
> -    (*in)->pool = p;
> -    (*in)->fname = NULL;
> -    (*in)->ftype = APR_FILETYPE_SOCKET;
> -    (*in)->timeout = 0; /* read end of the pipe is non-blocking */
> -    (*in)->ungetchar = -1;
> -    (*in)->eof_hit = 0;
> -    (*in)->filePtr = 0;
> -    (*in)->bufpos = 0;
> -    (*in)->dataRead = 0;
> -    (*in)->direction = 0;
> -    (*in)->pOverlapped = NULL;
> -    (*in)->filehand = (HANDLE)rd;
> -
> -    (*out) = (apr_file_t *)apr_pcalloc(p, sizeof(apr_file_t));
> -    (*out)->pool = p;
> -    (*out)->fname = NULL;
> -    (*out)->ftype = APR_FILETYPE_SOCKET;
> -    (*out)->timeout = -1;
> -    (*out)->ungetchar = -1;
> -    (*out)->eof_hit = 0;
> -    (*out)->filePtr = 0;
> -    (*out)->bufpos = 0;
> -    (*out)->dataRead = 0;
> -    (*out)->direction = 0;
> -    (*out)->pOverlapped = NULL;
> -    (*out)->filehand = (HANDLE)wr;
> +    apr_os_sock_put(in, &rd, p);
> +    apr_os_sock_put(out, &wr, p);

I think that the *in apr_socket and the underlying socket descriptor
are not aligned w.r.t. non-blocking.
We probably need to call apr_socket_timeout_set(*in, 0) here to make
that happen, thus remove the last ioctlsocket() in
create_socket_pipe() that sets the descriptor non-blocking before
leaving (which would be useless now).

Something like the below on top of your branch?

Index: file_io/win32/pipe.c
===================================================================
--- file_io/win32/pipe.c    (revision 1897212)
+++ file_io/win32/pipe.c    (working copy)
@@ -381,14 +381,7 @@ static apr_status_t create_socket_pipe(SOCKET *rd,
             goto cleanup;
         }
         if (nrd == (int)sizeof(uid) && memcmp(iid, uid, sizeof(uid)) == 0) {
-            /* Got the right identifier, put the poll()able read side of
-             * the pipe in nonblocking mode and return.
-             */
-            bm = 1;
-            if (ioctlsocket(*rd, FIONBIO, &bm) == SOCKET_ERROR) {
-                rv = apr_get_netos_error();
-                goto cleanup;
-            }
+            /* Got the right identifier, return. */
             break;
         }
         closesocket(*rd);
@@ -438,6 +431,9 @@ apr_status_t apr_file_socket_pipe_create(apr_socke
     apr_os_sock_put(in, &rd, p);
     apr_os_sock_put(out, &wr, p);

+    /* read end of the pipe is non-blocking */
+    apr_socket_timeout_set(*in, 0);
+
     apr_pool_cleanup_register(p, (void *)(*in), socket_pipe_cleanup,
                               apr_pool_cleanup_null);
     apr_pool_cleanup_register(p, (void *)(*out), socket_pipe_cleanup,
--


Regards;
Yann.