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/02/09 10:46:13 UTC
svn commit: r1897895 - in /apr/apr/trunk: ./ file_io/win32/ include/arch/unix/ include/arch/win32/ network_io/win32/ poll/unix/
Author: ivan
Date: Wed Feb 9 10:46:13 2022
New Revision: 1897895
URL: http://svn.apache.org/viewvc?rev=1897895&view=rev
Log:
Merge 'win32-pollset-wakeup-no-file-socket-emulation' branch to trunk.
Rework win32 poll wakeup implementation:
- Explicitly use apr_socket_t instead of apr_file_t for wakeup `pipe`
- Remove code in win32 apr_file_t implementation that emulates working with
sockets as files. Sockets on Windows are not kernel objects and should be
used only via Winsock API.
Added:
apr/apr/trunk/network_io/win32/socket_pipe.c
- copied unchanged from r1897894, apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation/network_io/win32/socket_pipe.c
Modified:
apr/apr/trunk/ (props changed)
apr/apr/trunk/CMakeLists.txt
apr/apr/trunk/file_io/win32/pipe.c
apr/apr/trunk/file_io/win32/readwrite.c
apr/apr/trunk/include/arch/unix/apr_arch_poll_private.h
apr/apr/trunk/include/arch/win32/apr_arch_file_io.h
apr/apr/trunk/include/arch/win32/apr_arch_networkio.h
apr/apr/trunk/poll/unix/poll.c
apr/apr/trunk/poll/unix/pollcb.c
apr/apr/trunk/poll/unix/pollset.c
apr/apr/trunk/poll/unix/select.c
apr/apr/trunk/poll/unix/wakeup.c
Propchange: apr/apr/trunk/
------------------------------------------------------------------------------
Merged /apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation:r1897199-1897894
Modified: apr/apr/trunk/CMakeLists.txt
URL: http://svn.apache.org/viewvc/apr/apr/trunk/CMakeLists.txt?rev=1897895&r1=1897894&r2=1897895&view=diff
==============================================================================
--- apr/apr/trunk/CMakeLists.txt (original)
+++ apr/apr/trunk/CMakeLists.txt Wed Feb 9 10:46:13 2022
@@ -351,6 +351,7 @@ SET(APR_SOURCES
network_io/unix/sockaddr.c
network_io/unix/socket_util.c
network_io/win32/sendrecv.c
+ network_io/win32/socket_pipe.c
network_io/win32/sockets.c
network_io/win32/sockopt.c
passwd/apr_getpass.c
Modified: apr/apr/trunk/file_io/win32/pipe.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/win32/pipe.c?rev=1897895&r1=1897894&r2=1897895&view=diff
==============================================================================
--- apr/apr/trunk/file_io/win32/pipe.c (original)
+++ apr/apr/trunk/file_io/win32/pipe.c Wed Feb 9 10:46:13 2022
@@ -274,212 +274,3 @@ APR_DECLARE(apr_status_t) apr_os_pipe_pu
{
return apr_os_pipe_put_ex(file, thefile, 0, pool);
}
-
-static apr_status_t create_socket_pipe(SOCKET *rd, SOCKET *wr)
-{
- FD_SET rs;
- SOCKET ls;
- struct timeval socktm;
- struct sockaddr_in pa;
- struct sockaddr_in la;
- struct sockaddr_in ca;
- int nrd;
- apr_status_t rv;
- int ll = sizeof(la);
- int lc = sizeof(ca);
- unsigned long bm = 1;
- char uid[8];
- char iid[8];
-
- *rd = INVALID_SOCKET;
- *wr = INVALID_SOCKET;
-
- /* Create the unique socket identifier
- * so that we know the connection originated
- * from us.
- */
- rv = apr_generate_random_bytes(uid, sizeof(uid));
- if (rv != APR_SUCCESS) {
- return rv;
- }
-
- if ((ls = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) {
- return apr_get_netos_error();
- }
-
- pa.sin_family = AF_INET;
- pa.sin_port = 0;
- pa.sin_addr.s_addr = inet_addr("127.0.0.1");
-
- if (bind(ls, (SOCKADDR *)&pa, sizeof(pa)) == SOCKET_ERROR) {
- rv = apr_get_netos_error();
- goto cleanup;
- }
- if (getsockname(ls, (SOCKADDR *)&la, &ll) == SOCKET_ERROR) {
- rv = apr_get_netos_error();
- goto cleanup;
- }
- if (listen(ls, 1) == SOCKET_ERROR) {
- rv = apr_get_netos_error();
- goto cleanup;
- }
- if ((*wr = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) {
- rv = apr_get_netos_error();
- goto cleanup;
- }
- if (connect(*wr, (SOCKADDR *)&la, sizeof(la)) == SOCKET_ERROR) {
- rv = apr_get_netos_error();
- goto cleanup;
- }
- if (send(*wr, uid, sizeof(uid), 0) != sizeof(uid)) {
- if ((rv = apr_get_netos_error()) == 0) {
- rv = APR_EINVAL;
- }
- goto cleanup;
- }
- if (ioctlsocket(ls, FIONBIO, &bm) == SOCKET_ERROR) {
- rv = apr_get_netos_error();
- goto cleanup;
- }
- for (;;) {
- int ns;
- int nc = 0;
- /* Listening socket is nonblocking by now.
- * 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/waiting for the identification */
- bm = 0;
- if (ioctlsocket(*rd, FIONBIO, &bm) == SOCKET_ERROR) {
- rv = apr_get_netos_error();
- goto cleanup;
- }
- nrd = recv(*rd, iid, sizeof(iid), 0);
- if (nrd == SOCKET_ERROR) {
- rv = apr_get_netos_error();
- 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;
- }
- break;
- }
- closesocket(*rd);
- }
- /* We don't need the listening socket any more */
- closesocket(ls);
- return 0;
-
-cleanup:
- /* Don't leak resources */
- closesocket(ls);
- if (*rd != INVALID_SOCKET)
- closesocket(*rd);
- if (*wr != INVALID_SOCKET)
- closesocket(*wr);
-
- *rd = INVALID_SOCKET;
- *wr = INVALID_SOCKET;
- return rv;
-}
-
-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;
- }
- return APR_SUCCESS;
-}
-
-apr_status_t apr_file_socket_pipe_create(apr_file_t **in,
- apr_file_t **out,
- apr_pool_t *p)
-{
- apr_status_t rv;
- SOCKET rd;
- SOCKET wr;
-
- 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_pool_cleanup_register(p, (void *)(*in), socket_pipe_cleanup,
- apr_pool_cleanup_null);
- apr_pool_cleanup_register(p, (void *)(*out), socket_pipe_cleanup,
- apr_pool_cleanup_null);
-
- return rv;
-}
-
-apr_status_t apr_file_socket_pipe_close(apr_file_t *file)
-{
- 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);
- }
-
- return APR_SUCCESS;
- }
- return stat;
-}
Modified: apr/apr/trunk/file_io/win32/readwrite.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/win32/readwrite.c?rev=1897895&r1=1897894&r2=1897895&view=diff
==============================================================================
--- apr/apr/trunk/file_io/win32/readwrite.c (original)
+++ apr/apr/trunk/file_io/win32/readwrite.c Wed Feb 9 10:46:13 2022
@@ -20,7 +20,6 @@
#include "apr_strings.h"
#include "apr_lib.h"
#include "apr_errno.h"
-#include "apr_arch_networkio.h"
#include "apr_arch_atime.h"
#include "apr_arch_misc.h"
@@ -74,23 +73,8 @@ static apr_status_t read_with_timeout(ap
file->pOverlapped->OffsetHigh = (DWORD)(file->filePtr >> 32);
}
- if (file->ftype == APR_FILETYPE_SOCKET) {
- WSABUF wsaData;
- DWORD flags = 0;
-
- wsaData.buf = (char*) buf;
- wsaData.len = (u_long)len;
- if (WSARecv((SOCKET)file->filehand, &wsaData, 1, &bytesread,
- &flags, NULL, NULL) == SOCKET_ERROR) {
- rv = apr_get_netos_error();
- bytesread = 0;
- }
- else {
- rv = APR_SUCCESS;
- }
- }
- else if (ReadFile(file->filehand, buf, len,
- &bytesread, file->pOverlapped)) {
+ if (ReadFile(file->filehand, buf, len,
+ &bytesread, file->pOverlapped)) {
rv = APR_SUCCESS;
}
else {
@@ -426,25 +410,9 @@ APR_DECLARE(apr_status_t) apr_file_write
if (thefile->flags & APR_FOPEN_XTHREAD) {
apr_thread_mutex_unlock(thefile->mutex);
}
- }
- else if (thefile->ftype == APR_FILETYPE_SOCKET) {
- WSABUF wsaData;
- DWORD flags = 0;
-
- wsaData.buf = (char*) buf;
- wsaData.len = (u_long)*nbytes;
- if (WSASend((SOCKET)thefile->filehand, &wsaData, 1, &bwrote,
- flags, NULL, NULL) == SOCKET_ERROR) {
- rv = apr_get_netos_error();
- bwrote = 0;
- }
- else {
- rv = APR_SUCCESS;
- }
- *nbytes = bwrote;
- }
- else {
- if (thefile->ftype != APR_FILETYPE_FILE) {
+ return rv;
+ } else {
+ if (thefile->ftype == APR_FILETYPE_PIPE) {
rv = WriteFile(thefile->filehand, buf, (DWORD)*nbytes, &bwrote,
thefile->pOverlapped);
}
Modified: apr/apr/trunk/include/arch/unix/apr_arch_poll_private.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/arch/unix/apr_arch_poll_private.h?rev=1897895&r1=1897894&r2=1897895&view=diff
==============================================================================
--- apr/apr/trunk/include/arch/unix/apr_arch_poll_private.h (original)
+++ apr/apr/trunk/include/arch/unix/apr_arch_poll_private.h Wed Feb 9 10:46:13 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/trunk/include/arch/win32/apr_arch_file_io.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/arch/win32/apr_arch_file_io.h?rev=1897895&r1=1897894&r2=1897895&view=diff
==============================================================================
--- apr/apr/trunk/include/arch/win32/apr_arch_file_io.h (original)
+++ apr/apr/trunk/include/arch/win32/apr_arch_file_io.h Wed Feb 9 10:46:13 2022
@@ -161,8 +161,7 @@ apr_status_t more_finfo(apr_finfo_t *fin
typedef enum {
APR_FILETYPE_FILE = 0,
- APR_FILETYPE_PIPE,
- APR_FILETYPE_SOCKET
+ APR_FILETYPE_PIPE
} apr_filetype_e;
struct apr_file_t {
@@ -250,12 +249,4 @@ 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_pool_t *p);
-
-extern apr_status_t
-apr_file_socket_pipe_close(apr_file_t *file);
-
#endif /* ! FILE_IO_H */
Modified: apr/apr/trunk/include/arch/win32/apr_arch_networkio.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/arch/win32/apr_arch_networkio.h?rev=1897895&r1=1897894&r2=1897895&view=diff
==============================================================================
--- apr/apr/trunk/include/arch/win32/apr_arch_networkio.h (original)
+++ apr/apr/trunk/include/arch/win32/apr_arch_networkio.h Wed Feb 9 10:46:13 2022
@@ -77,5 +77,13 @@ void apr_sockaddr_vars_set(apr_sockaddr_
(skt)->options &= ~(option); \
} while (0)
+extern apr_status_t
+apr_socket_pipe_create(apr_socket_t **in,
+ apr_socket_t **out,
+ apr_pool_t *p);
+
+extern apr_status_t
+apr_socket_pipe_close(apr_socket_t *socket);
+
#endif /* ! NETWORK_IO_H */
Modified: apr/apr/trunk/poll/unix/poll.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/poll/unix/poll.c?rev=1897895&r1=1897894&r2=1897895&view=diff
==============================================================================
--- apr/apr/trunk/poll/unix/poll.c (original)
+++ apr/apr/trunk/poll/unix/poll.c Wed Feb 9 10:46:13 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/trunk/poll/unix/pollcb.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/poll/unix/pollcb.c?rev=1897895&r1=1897894&r2=1897895&view=diff
==============================================================================
--- apr/apr/trunk/poll/unix/pollcb.c (original)
+++ apr/apr/trunk/poll/unix/pollcb.c Wed Feb 9 10:46:13 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/trunk/poll/unix/pollset.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/poll/unix/pollset.c?rev=1897895&r1=1897894&r2=1897895&view=diff
==============================================================================
--- apr/apr/trunk/poll/unix/pollset.c (original)
+++ apr/apr/trunk/poll/unix/pollset.c Wed Feb 9 10:46:13 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/trunk/poll/unix/select.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/poll/unix/select.c?rev=1897895&r1=1897894&r2=1897895&view=diff
==============================================================================
--- apr/apr/trunk/poll/unix/select.c (original)
+++ apr/apr/trunk/poll/unix/select.c Wed Feb 9 10:46:13 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/trunk/poll/unix/wakeup.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/poll/unix/wakeup.c?rev=1897895&r1=1897894&r2=1897895&view=diff
==============================================================================
--- apr/apr/trunk/poll/unix/wakeup.c (original)
+++ apr/apr/trunk/poll/unix/wakeup.c Wed Feb 9 10:46:13 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_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_socket_pipe_close(wakeup_socket[0]);
+ wakeup_socket[0] = NULL;
+ }
+ if (wakeup_socket[1]) {
+ rv1 = apr_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