diff options
author | gstein <gstein@13f79535-47bb-0310-9956-ffa450edef68> | 2003-11-17 01:41:18 +0000 |
---|---|---|
committer | gstein <gstein@13f79535-47bb-0310-9956-ffa450edef68> | 2003-11-17 01:41:18 +0000 |
commit | 4825d7e302a225991dec3d211c9ff42ba90b5039 (patch) | |
tree | 3a246b886518c4c5ac54eb4381929d7cd4d6659f | |
parent | 5703b123e764ea25f6c02096bca7ad701126c22d (diff) | |
download | libapr-4825d7e302a225991dec3d211c9ff42ba90b5039.tar.gz |
With the removal of apr_poll(), the apr_wait_for_io_or_timeout() function
needed to be rebuilt. Specifically, it needs a pollset, but we don't want
to allocate that all the time. Thus, we need to create it once at socket
or file creation time, and then reuse that pollset.
NOTE: this makes the library compile, but some of the test programs may
not. I have also not verified this work yet (in favor of just getting it
to at least compile...)
For the apr_arch_*.h files, I added a pollset member to the file and
socket structures.
For the various open/dup/etc functions, I added the creation of that
pollset whenever a file or socket is created.
(I may have missed some and will verify further)
For the socket create and sendrecv function, I added the creation of the
pollset.
(again, may have missed some, but if everybody uses alloc_socket, then we
should be okay)
* support/unix/waitio.c: rebuild in terms of the pollset
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@64759 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | file_io/os2/filedup.c | 9 | ||||
-rw-r--r-- | file_io/os2/open.c | 9 | ||||
-rw-r--r-- | file_io/os2/pipe.c | 3 | ||||
-rw-r--r-- | file_io/unix/filedup.c | 9 | ||||
-rw-r--r-- | file_io/unix/open.c | 4 | ||||
-rw-r--r-- | file_io/unix/pipe.c | 6 | ||||
-rw-r--r-- | file_io/win32/filedup.c | 9 | ||||
-rw-r--r-- | file_io/win32/open.c | 8 | ||||
-rw-r--r-- | file_io/win32/pipe.c | 2 | ||||
-rw-r--r-- | include/apr_support.h | 2 | ||||
-rw-r--r-- | include/arch/netware/apr_arch_file_io.h | 4 | ||||
-rw-r--r-- | include/arch/os2/apr_arch_file_io.h | 4 | ||||
-rw-r--r-- | include/arch/os2/apr_arch_networkio.h | 5 | ||||
-rw-r--r-- | include/arch/unix/apr_arch_file_io.h | 4 | ||||
-rw-r--r-- | include/arch/unix/apr_arch_networkio.h | 4 | ||||
-rw-r--r-- | include/arch/win32/apr_arch_file_io.h | 4 | ||||
-rw-r--r-- | include/arch/win32/apr_arch_networkio.h | 4 | ||||
-rw-r--r-- | network_io/beos/sendrecv.c | 10 | ||||
-rw-r--r-- | network_io/os2/sockets.c | 6 | ||||
-rw-r--r-- | network_io/unix/sockets.c | 5 | ||||
-rw-r--r-- | network_io/win32/sockets.c | 4 | ||||
-rw-r--r-- | support/unix/waitio.c | 46 |
22 files changed, 141 insertions, 20 deletions
diff --git a/file_io/os2/filedup.c b/file_io/os2/filedup.c index 10e8566eb..59530d90c 100644 --- a/file_io/os2/filedup.c +++ b/file_io/os2/filedup.c @@ -96,6 +96,10 @@ static apr_status_t file_dup(apr_file_t **new_file, apr_file_t *old_file, apr_po *new_file = dup_file; } + /* Create a pollset with room for one descriptor. */ + /* ### check return codes */ + (void) apr_pollset_create(&(*new)->pollset, 1, p, 0); + return APR_SUCCESS; } @@ -158,5 +162,10 @@ APR_DECLARE(apr_status_t) apr_file_setaside(apr_file_t **new_file, old_file->filedes = -1; apr_pool_cleanup_kill(old_file->pool, (void *)old_file, apr_file_cleanup); + + /* Create a pollset with room for one descriptor. */ + /* ### check return codes */ + (void) apr_pollset_create(&(*new)->pollset, 1, p, 0); + return APR_SUCCESS; } diff --git a/file_io/os2/open.c b/file_io/os2/open.c index 3b7ef8358..db7df5ffc 100644 --- a/file_io/os2/open.c +++ b/file_io/os2/open.c @@ -144,6 +144,10 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname, apr dafile->direction = 0; dafile->pipe = FALSE; + /* Create a pollset with room for one descriptor. */ + /* ### check return codes */ + (void) apr_pollset_create(&dafile->pollset, 1, cont, 0); + if (!(flag & APR_FILE_NOCLEANUP)) { apr_pool_cleanup_register(dafile->pool, dafile, apr_file_cleanup, apr_file_cleanup); } @@ -239,6 +243,11 @@ APR_DECLARE(apr_status_t) apr_os_file_put(apr_file_t **file, apr_os_file_t *thef if (rv) return rv; } + + /* Create a pollset with room for one descriptor. */ + /* ### check return codes */ + (void) apr_pollset_create(&(*new)->pollset, 1, cont, 0); + return APR_SUCCESS; } diff --git a/file_io/os2/pipe.c b/file_io/os2/pipe.c index decf88b45..083bb63d2 100644 --- a/file_io/os2/pipe.c +++ b/file_io/os2/pipe.c @@ -123,6 +123,7 @@ APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, apr_file_t **out (*in)->pipe = 1; (*in)->timeout = -1; (*in)->blocking = BLK_ON; + (void) apr_pollset_create(&(*in)->pollset, 1, pool, 0); apr_pool_cleanup_register(pool, *in, apr_file_cleanup, apr_pool_cleanup_null); (*out) = (apr_file_t *)apr_palloc(pool, sizeof(apr_file_t)); @@ -135,6 +136,7 @@ APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, apr_file_t **out (*out)->pipe = 1; (*out)->timeout = -1; (*out)->blocking = BLK_ON; + (void) apr_pollset_create(&(*out)->pollset, 1, pool, 0); apr_pool_cleanup_register(pool, *out, apr_file_cleanup, apr_pool_cleanup_null); return APR_SUCCESS; @@ -196,6 +198,7 @@ APR_DECLARE(apr_status_t) apr_os_pipe_put_ex(apr_file_t **file, (*file)->blocking = BLK_UNKNOWN; /* app needs to make a timeout call */ (*file)->timeout = -1; (*file)->filedes = *thefile; + (void) apr_pollset_create(&(*file)->pollset, 1, pool, 0); if (register_cleanup) { apr_pool_cleanup_register(pool, *file, apr_file_cleanup, diff --git a/file_io/unix/filedup.c b/file_io/unix/filedup.c index 34ca7de82..4e9cece90 100644 --- a/file_io/unix/filedup.c +++ b/file_io/unix/filedup.c @@ -131,6 +131,10 @@ static apr_status_t _file_dup(apr_file_t **new_file, apr_unix_file_cleanup, apr_unix_file_cleanup); + /* Create a pollset with room for one descriptor. */ + /* ### check return codes */ + (void) apr_pollset_create(&(*new_file)->pollset, 1, p, 0); + return APR_SUCCESS; } @@ -183,5 +187,10 @@ APR_DECLARE(apr_status_t) apr_file_setaside(apr_file_t **new_file, old_file->filedes = -1; apr_pool_cleanup_kill(old_file->pool, (void *)old_file, apr_unix_file_cleanup); + + /* Create a pollset with room for one descriptor. */ + /* ### check return codes */ + (void) apr_pollset_create(&(*new_file)->pollset, 1, p, 0); + return APR_SUCCESS; } diff --git a/file_io/unix/open.c b/file_io/unix/open.c index 1f6473a16..df67b765b 100644 --- a/file_io/unix/open.c +++ b/file_io/unix/open.c @@ -189,6 +189,10 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, (*new)->dataRead = 0; (*new)->direction = 0; + /* Create a pollset with room for one descriptor. */ + /* ### check return codes */ + (void) apr_pollset_create(&(*new)->pollset, 1, pool, 0); + if (!(flag & APR_FILE_NOCLEANUP)) { apr_pool_cleanup_register((*new)->pool, (void *)(*new), apr_unix_file_cleanup, diff --git a/file_io/unix/pipe.c b/file_io/unix/pipe.c index 41b6cfc4b..140c98f8e 100644 --- a/file_io/unix/pipe.c +++ b/file_io/unix/pipe.c @@ -198,6 +198,10 @@ APR_DECLARE(apr_status_t) apr_os_pipe_put_ex(apr_file_t **file, apr_unix_file_cleanup, apr_pool_cleanup_null); } + + /* Create a pollset with room for one descriptor. */ + /* ### check return codes */ + (void) apr_pollset_create(&(*file)->pollset, 1, pool, 0); return APR_SUCCESS; } @@ -229,6 +233,7 @@ APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, apr_file_t **out #if APR_HAS_THREADS (*in)->thlock = NULL; #endif + (void) apr_pollset_create(&(*in)->pollset, 1, pool, 0); (*out) = (apr_file_t *)apr_pcalloc(pool, sizeof(apr_file_t)); (*out)->pool = pool; @@ -242,6 +247,7 @@ APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, apr_file_t **out #if APR_HAS_THREADS (*out)->thlock = NULL; #endif + (void) apr_pollset_create(&(*out)->pollset, 1, pool, 0); apr_pool_cleanup_register((*in)->pool, (void *)(*in), apr_unix_file_cleanup, apr_pool_cleanup_null); diff --git a/file_io/win32/filedup.c b/file_io/win32/filedup.c index f676daea2..b14b16bdd 100644 --- a/file_io/win32/filedup.c +++ b/file_io/win32/filedup.c @@ -86,6 +86,10 @@ APR_DECLARE(apr_status_t) apr_file_dup(apr_file_t **new_file, apr_pool_cleanup_register((*new_file)->pool, (void *)(*new_file), file_cleanup, apr_pool_cleanup_null); + /* Create a pollset with room for one descriptor. */ + /* ### check return codes */ + (void) apr_pollset_create(&(*new_file)->pollset, 1, p, 0); + return APR_SUCCESS; #endif /* !defined(_WIN32_WCE) */ } @@ -190,5 +194,10 @@ APR_DECLARE(apr_status_t) apr_file_setaside(apr_file_t **new_file, old_file->filehand = INVALID_HANDLE_VALUE; apr_pool_cleanup_kill(old_file->pool, (void *)old_file, file_cleanup); + + /* Create a pollset with room for one descriptor. */ + /* ### check return codes */ + (void) apr_pollset_create(&(*new_file)->pollset, 1, p, 0); + return APR_SUCCESS; } diff --git a/file_io/win32/open.c b/file_io/win32/open.c index 550206b88..76a9388c1 100644 --- a/file_io/win32/open.c +++ b/file_io/win32/open.c @@ -436,6 +436,10 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname, } } + /* Create a pollset with room for one descriptor. */ + /* ### check return codes */ + (void) apr_pollset_create(&(*new)->pollset, 1, cont, 0); + if (!(flag & APR_FILE_NOCLEANUP)) { apr_pool_cleanup_register((*new)->pool, (void *)(*new), file_cleanup, apr_pool_cleanup_null); @@ -575,6 +579,10 @@ APR_DECLARE(apr_status_t) apr_os_file_put(apr_file_t **file, } } + /* Create a pollset with room for one descriptor. */ + /* ### check return codes */ + (void) apr_pollset_create(&(*file)->pollset, 1, pool, 0); + /* XXX... we pcalloc above so all others are zeroed. * Should we be testing if thefile is a handle to * a PIPE and set up the mechanics appropriately? diff --git a/file_io/win32/pipe.c b/file_io/win32/pipe.c index 1d43e3de6..21746c892 100644 --- a/file_io/win32/pipe.c +++ b/file_io/win32/pipe.c @@ -148,6 +148,7 @@ apr_status_t apr_create_nt_pipe(apr_file_t **in, apr_file_t **out, (*in)->dataRead = 0; (*in)->direction = 0; (*in)->pOverlapped = NULL; + (void) apr_pollset_create(&(*in)->pollset, 1, p, 0); (*out) = (apr_file_t *)apr_pcalloc(p, sizeof(apr_file_t)); (*out)->pool = p; @@ -161,6 +162,7 @@ apr_status_t apr_create_nt_pipe(apr_file_t **in, apr_file_t **out, (*out)->dataRead = 0; (*out)->direction = 0; (*out)->pOverlapped = NULL; + (void) apr_pollset_create(&(*out)->pollset, 1, p, 0); if (apr_os_level >= APR_WIN_NT) { /* Create the read end of the pipe */ diff --git a/include/apr_support.h b/include/apr_support.h index 50a4789e6..8b3f257f5 100644 --- a/include/apr_support.h +++ b/include/apr_support.h @@ -76,6 +76,8 @@ extern "C" { /** * Wait for IO to occur or timeout. + * + * Uses POOL for temporary allocations. */ apr_status_t apr_wait_for_io_or_timeout(apr_file_t *f, apr_socket_t *s, int for_read); diff --git a/include/arch/netware/apr_arch_file_io.h b/include/arch/netware/apr_arch_file_io.h index e17a7004e..54dabe29b 100644 --- a/include/arch/netware/apr_arch_file_io.h +++ b/include/arch/netware/apr_arch_file_io.h @@ -63,6 +63,7 @@ #include "apr_file_info.h" #include "apr_errno.h" #include "apr_lib.h" +#include "apr_poll.h" /* System headers the file I/O library needs */ #if APR_HAVE_FCNTL_H @@ -120,6 +121,9 @@ struct apr_file_t { enum {BLK_UNKNOWN, BLK_OFF, BLK_ON } blocking; int ungetchar; /* Last char provided by an unget op. (-1 = no char)*/ + /* if there is a timeout set, then this pollset is used */ + apr_pollset_t *pollset; + /* Stuff for buffered mode */ char *buffer; int bufpos; /* Read/Write position in buffer */ diff --git a/include/arch/os2/apr_arch_file_io.h b/include/arch/os2/apr_arch_file_io.h index 3fb44bdd6..624b7445d 100644 --- a/include/arch/os2/apr_arch_file_io.h +++ b/include/arch/os2/apr_arch_file_io.h @@ -61,6 +61,7 @@ #include "apr_file_io.h" #include "apr_file_info.h" #include "apr_errno.h" +#include "apr_poll.h" /* We have an implementation of mkstemp but it's not very multi-threading * friendly & is part of the POSIX emulation rather than native so don't @@ -83,6 +84,9 @@ struct apr_file_t { HEV pipeSem; enum { BLK_UNKNOWN, BLK_OFF, BLK_ON } blocking; + /* if there is a timeout set, then this pollset is used */ + apr_pollset_t *pollset; + /* Stuff for buffered mode */ char *buffer; int bufpos; // Read/Write position in buffer diff --git a/include/arch/os2/apr_arch_networkio.h b/include/arch/os2/apr_arch_networkio.h index fbb9cb989..dd93fa24c 100644 --- a/include/arch/os2/apr_arch_networkio.h +++ b/include/arch/os2/apr_arch_networkio.h @@ -59,6 +59,8 @@ #include "apr_network_io.h" #include "apr_general.h" #include "apr_arch_os2calls.h" +#include "apr_poll.h" + #if APR_HAVE_NETDB_H #include <netdb.h> #endif @@ -85,6 +87,9 @@ struct apr_socket_t { apr_int32_t options; apr_int32_t inherit; sock_userdata_t *userdata; + + /* if there is a timeout set, then this pollset is used */ + apr_pollset_t *pollset; }; /* Error codes returned from sock_errno() */ diff --git a/include/arch/unix/apr_arch_file_io.h b/include/arch/unix/apr_arch_file_io.h index f04b41517..aea12e791 100644 --- a/include/arch/unix/apr_arch_file_io.h +++ b/include/arch/unix/apr_arch_file_io.h @@ -64,6 +64,7 @@ #include "apr_errno.h" #include "apr_lib.h" #include "apr_thread_mutex.h" +#include "apr_poll.h" /* System headers the file I/O library needs */ #if APR_HAVE_FCNTL_H @@ -131,6 +132,9 @@ struct apr_file_t { enum {BLK_UNKNOWN, BLK_OFF, BLK_ON } blocking; int ungetchar; /* Last char provided by an unget op. (-1 = no char)*/ + /* if there is a timeout set, then this pollset is used */ + apr_pollset_t *pollset; + /* Stuff for buffered mode */ char *buffer; int bufpos; /* Read/Write position in buffer */ diff --git a/include/arch/unix/apr_arch_networkio.h b/include/arch/unix/apr_arch_networkio.h index 0af3c482d..4938cf6bc 100644 --- a/include/arch/unix/apr_arch_networkio.h +++ b/include/arch/unix/apr_arch_networkio.h @@ -61,6 +61,7 @@ #include "apr_errno.h" #include "apr_general.h" #include "apr_lib.h" +#include "apr_poll.h" /* System headers the network I/O library needs */ #if APR_HAVE_SYS_TYPES_H @@ -152,6 +153,9 @@ struct apr_socket_t { apr_int32_t options; apr_int32_t inherit; sock_userdata_t *userdata; + + /* if there is a timeout set, then this pollset is used */ + apr_pollset_t *pollset; }; const char *apr_inet_ntop(int af, const void *src, char *dst, apr_size_t size); diff --git a/include/arch/win32/apr_arch_file_io.h b/include/arch/win32/apr_arch_file_io.h index 30e863a83..c5dd2103f 100644 --- a/include/arch/win32/apr_arch_file_io.h +++ b/include/arch/win32/apr_arch_file_io.h @@ -65,6 +65,7 @@ #include "apr_file_info.h" #include "apr_errno.h" #include "apr_arch_misc.h" +#include "apr_poll.h" #ifdef HAVE_SYS_STAT_H #include <sys/stat.h> @@ -215,6 +216,9 @@ struct apr_file_t { apr_off_t filePtr; // position in file of handle apr_thread_mutex_t *mutex; // mutex semaphore, must be owned to access the above fields + /* if there is a timeout set, then this pollset is used */ + apr_pollset_t *pollset; + /* Pipe specific info */ }; diff --git a/include/arch/win32/apr_arch_networkio.h b/include/arch/win32/apr_arch_networkio.h index 2897e0d17..4aab1dc13 100644 --- a/include/arch/win32/apr_arch_networkio.h +++ b/include/arch/win32/apr_arch_networkio.h @@ -57,6 +57,7 @@ #include "apr_network_io.h" #include "apr_general.h" +#include "apr_poll.h" typedef struct sock_userdata_t sock_userdata_t; struct sock_userdata_t { @@ -81,6 +82,9 @@ struct apr_socket_t { apr_int32_t options; apr_int32_t inherit; sock_userdata_t *userdata; + + /* if there is a timeout set, then this pollset is used */ + apr_pollset_t *pollset; }; #ifdef _WIN32_WCE diff --git a/network_io/beos/sendrecv.c b/network_io/beos/sendrecv.c index 965ea8857..58bbced43 100644 --- a/network_io/beos/sendrecv.c +++ b/network_io/beos/sendrecv.c @@ -59,7 +59,7 @@ #include "apr_arch_networkio.h" #include "apr_time.h" -apr_status_t apr_wait_for_io_or_timeout(apr_socket_t *sock, int for_read) +static apr_status_t wait_for_io_or_timeout(apr_socket_t *sock, int for_read) { struct timeval tv, *tvptr; fd_set fdset; @@ -139,7 +139,7 @@ APR_DECLARE(apr_status_t) apr_socket_recv(apr_socket_t *sock, char *buf, } while (rv == -1 && errno == EINTR); if (rv == -1 && errno == EWOULDBLOCK && sock->timeout > 0) { - apr_status_t arv = apr_wait_for_io_or_timeout(sock, 1); + apr_status_t arv = wait_for_io_or_timeout(sock, 1); if (arv != APR_SUCCESS) { *len = 0; return arv; @@ -185,7 +185,7 @@ APR_DECLARE(apr_status_t) apr_socket_sendto(apr_socket_t *sock, if (rv == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) && sock->timeout != 0) { - apr_status_t arv = apr_wait_for_io_or_timeout(sock, 0); + apr_status_t arv = wait_for_io_or_timeout(sock, 0); if (arv != APR_SUCCESS) { *len = 0; return arv; @@ -226,7 +226,7 @@ APR_DECLARE(apr_status_t) apr_socket_recvfrom(apr_sockaddr_t *from, if (rv == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) && sock->timeout != 0) { - apr_status_t arv = apr_wait_for_io_or_timeout(sock, 1); + apr_status_t arv = wait_for_io_or_timeout(sock, 1); if (arv != APR_SUCCESS) { *len = 0; return arv; @@ -249,4 +249,4 @@ APR_DECLARE(apr_status_t) apr_socket_recvfrom(apr_sockaddr_t *from, return APR_SUCCESS; } -#endif +#endif /* ! BEOS_BONE */ diff --git a/network_io/os2/sockets.c b/network_io/os2/sockets.c index 5c13fe39f..66949b573 100644 --- a/network_io/os2/sockets.c +++ b/network_io/os2/sockets.c @@ -103,6 +103,10 @@ static void alloc_socket(apr_socket_t **new, apr_pool_t *p) (*new)->remote_addr = (apr_sockaddr_t *)apr_pcalloc((*new)->cntxt, sizeof(apr_sockaddr_t)); (*new)->remote_addr->pool = p; + + /* Create a pollset with room for one descriptor. */ + /* ### check return codes */ + (void) apr_pollset_create(&(*new)->pollset, 1, p, 0); } APR_DECLARE(apr_status_t) apr_socket_protocol_get(apr_socket_t *sock, int *protocol) @@ -115,6 +119,7 @@ APR_DECLARE(apr_status_t) apr_socket_create(apr_socket_t **new, int family, int int protocol, apr_pool_t *cont) { int downgrade = (family == AF_UNSPEC); + apr_pollfd_t pfd; if (family == AF_UNSPEC) { #if APR_HAVE_IPV6 @@ -143,6 +148,7 @@ APR_DECLARE(apr_status_t) apr_socket_create(apr_socket_t **new, int family, int (*new)->nonblock = FALSE; apr_pool_cleanup_register((*new)->cntxt, (void *)(*new), socket_cleanup, apr_pool_cleanup_null); + return APR_SUCCESS; } diff --git a/network_io/unix/sockets.c b/network_io/unix/sockets.c index 26a90d5e2..97c0eb2c4 100644 --- a/network_io/unix/sockets.c +++ b/network_io/unix/sockets.c @@ -103,6 +103,10 @@ static void alloc_socket(apr_socket_t **new, apr_pool_t *p) (*new)->remote_addr = (apr_sockaddr_t *)apr_pcalloc((*new)->cntxt, sizeof(apr_sockaddr_t)); (*new)->remote_addr->pool = p; + + /* Create a pollset with room for one descriptor. */ + /* ### check return codes */ + (void) apr_pollset_create(&(*new)->pollset, 1, p, 0); } apr_status_t apr_socket_protocol_get(apr_socket_t *sock, int *protocol) @@ -144,6 +148,7 @@ apr_status_t apr_socket_create(apr_socket_t **new, int ofamily, int type, (*new)->inherit = 0; apr_pool_cleanup_register((*new)->cntxt, (void *)(*new), socket_cleanup, socket_cleanup); + return APR_SUCCESS; } diff --git a/network_io/win32/sockets.c b/network_io/win32/sockets.c index 5ef459e5e..fffbc7c71 100644 --- a/network_io/win32/sockets.c +++ b/network_io/win32/sockets.c @@ -94,6 +94,10 @@ static void alloc_socket(apr_socket_t **new, apr_pool_t *p) (*new)->remote_addr = (apr_sockaddr_t *)apr_pcalloc((*new)->cntxt, sizeof(apr_sockaddr_t)); (*new)->remote_addr->pool = p; + + /* Create a pollset with room for one descriptor. */ + /* ### check return codes */ + (void) apr_pollset_create(&(*new)->pollset, 1, cont, 0); } APR_DECLARE(apr_status_t) apr_socket_protocol_get(apr_socket_t *sock, diff --git a/support/unix/waitio.c b/support/unix/waitio.c index de72b7e9c..84a8483c7 100644 --- a/support/unix/waitio.c +++ b/support/unix/waitio.c @@ -65,38 +65,54 @@ #endif #ifdef USE_WAIT_FOR_IO + apr_status_t apr_wait_for_io_or_timeout(apr_file_t *f, apr_socket_t *s, - int for_read) + int for_read) { apr_interval_time_t timeout; - apr_pollfd_t pollset; - int srv, n; + apr_pollfd_t pfd; int type = for_read ? APR_POLLIN : APR_POLLOUT; + apr_pollset_t *pollset; + apr_status_t status; /* TODO - timeout should be less each time through this loop */ if (f) { - pollset.desc_type = APR_POLL_FILE; - pollset.desc.f = f; - pollset.p = f->pool; + pfd.desc_type = APR_POLL_FILE; + pfd.desc.f = f; + + pollset = f->pollset; timeout = f->timeout; } else { - pollset.desc_type = APR_POLL_SOCKET; - pollset.desc.s = s; - pollset.p = s->cntxt; + pfd.desc_type = APR_POLL_SOCKET; + pfd.desc.s = s; + + pollset = s->pollset; timeout = s->timeout; } - pollset.reqevents = type; + pfd.reqevents = type; + + /* Remove the object if it was in the pollset, then add in the new + * object with the correct reqevents value. Ignore the status result + * on the remove, because it might not be in there (yet). + */ + (void) apr_pollset_remove(pollset, &pfd); + + /* ### check status code */ + (void) apr_pollset_add(pollset, &pfd); do { - srv = apr_poll(&pollset, 1, &n, timeout); + int numdesc; + const apr_pollfd_t *pdesc; + + status = apr_pollset_poll(pollset, timeout, &numdesc, &pdesc); - if (n == 1 && pollset.rtnevents & type) { + if (numdesc == 1 && (pdesc[0].rtnevents & type) != 0) { return APR_SUCCESS; } - } while (APR_STATUS_IS_EINTR(srv)); + } while (APR_STATUS_IS_EINTR(status)); - return srv; + return status; } -#endif +#endif /* USE_WAIT_FOR_IO */ |