From 20fc9a4b4630397d080996548cd3c3d313b8c601 Mon Sep 17 00:00:00 2001 From: Ivan Zhakov Date: Wed, 19 Jan 2022 16:41:59 +0000 Subject: 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. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation@1897208 13f79535-47bb-0310-9956-ffa450edef68 --- file_io/win32/pipe.c | 59 ++++++++++++++-------------------------------------- 1 file changed, 16 insertions(+), 43 deletions(-) (limited to 'file_io') diff --git a/file_io/win32/pipe.c b/file_io/win32/pipe.c index 22d186687..fc2933519 100644 --- a/file_io/win32/pipe.c +++ b/file_io/win32/pipe.c @@ -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(apr_file_t **in, 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; } -- cgit v1.2.1