diff options
-rw-r--r-- | configure.in | 5 | ||||
-rw-r--r-- | file_io/unix/filedup.c | 8 | ||||
-rw-r--r-- | file_io/unix/open.c | 4 | ||||
-rw-r--r-- | file_io/unix/pipe.c | 9 | ||||
-rw-r--r-- | include/arch/unix/apr_arch_file_io.h | 6 | ||||
-rw-r--r-- | include/arch/unix/apr_arch_networkio.h | 5 | ||||
-rw-r--r-- | network_io/unix/sockets.c | 3 | ||||
-rw-r--r-- | support/unix/waitio.c | 36 |
8 files changed, 63 insertions, 13 deletions
diff --git a/configure.in b/configure.in index 164c8c502..84f04c5e3 100644 --- a/configure.in +++ b/configure.in @@ -1720,6 +1720,11 @@ fi AC_SUBST(have_in_addr) AC_SUBST(file_as_socket) +if test "$ac_cv_func_poll $file_as_socket" = "yes 1"; then + AC_DEFINE(WAITIO_USES_POLL, 1, + [Define if apr_wait_for_io_or_timeout() uses poll(2)]) +fi + # Check the types only if we have gethostbyname_r if test "$ac_cv_func_gethostbyname_r" = "yes"; then APR_CHECK_GETHOSTBYNAME_R_STYLE diff --git a/file_io/unix/filedup.c b/file_io/unix/filedup.c index 04aa9a105..f89e2e5a5 100644 --- a/file_io/unix/filedup.c +++ b/file_io/unix/filedup.c @@ -130,11 +130,11 @@ static apr_status_t file_dup(apr_file_t **new_file, apr_pool_cleanup_register((*new_file)->pool, (void *)(*new_file), apr_unix_file_cleanup, apr_unix_file_cleanup); - +#ifndef WAITIO_USES_POLL /* Create a pollset with room for one descriptor. */ /* ### check return codes */ (void) apr_pollset_create(&(*new_file)->pollset, 1, p, 0); - +#endif return APR_SUCCESS; } @@ -187,10 +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); - +#ifndef WAITIO_USES_POLL /* Create a pollset with room for one descriptor. */ /* ### check return codes */ (void) apr_pollset_create(&(*new_file)->pollset, 1, p, 0); - +#endif return APR_SUCCESS; } diff --git a/file_io/unix/open.c b/file_io/unix/open.c index df67b765b..54775e3c8 100644 --- a/file_io/unix/open.c +++ b/file_io/unix/open.c @@ -188,11 +188,11 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, (*new)->bufpos = 0; (*new)->dataRead = 0; (*new)->direction = 0; - +#ifndef WAITIO_USES_POLL /* Create a pollset with room for one descriptor. */ /* ### check return codes */ (void) apr_pollset_create(&(*new)->pollset, 1, pool, 0); - +#endif 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 140c98f8e..5ab52cbdd 100644 --- a/file_io/unix/pipe.c +++ b/file_io/unix/pipe.c @@ -198,10 +198,11 @@ APR_DECLARE(apr_status_t) apr_os_pipe_put_ex(apr_file_t **file, apr_unix_file_cleanup, apr_pool_cleanup_null); } - +#ifndef WAITIO_USES_POLL /* Create a pollset with room for one descriptor. */ /* ### check return codes */ (void) apr_pollset_create(&(*file)->pollset, 1, pool, 0); +#endif return APR_SUCCESS; } @@ -233,8 +234,9 @@ 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 +#ifndef WAITIO_USES_POLL (void) apr_pollset_create(&(*in)->pollset, 1, pool, 0); - +#endif (*out) = (apr_file_t *)apr_pcalloc(pool, sizeof(apr_file_t)); (*out)->pool = pool; (*out)->filedes = filedes[1]; @@ -247,8 +249,9 @@ 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 +#ifndef WAITIO_USES_POLL (void) apr_pollset_create(&(*out)->pollset, 1, pool, 0); - +#endif apr_pool_cleanup_register((*in)->pool, (void *)(*in), apr_unix_file_cleanup, apr_pool_cleanup_null); apr_pool_cleanup_register((*out)->pool, (void *)(*out), apr_unix_file_cleanup, diff --git a/include/arch/unix/apr_arch_file_io.h b/include/arch/unix/apr_arch_file_io.h index aea12e791..3ee5ab8b0 100644 --- a/include/arch/unix/apr_arch_file_io.h +++ b/include/arch/unix/apr_arch_file_io.h @@ -64,7 +64,9 @@ #include "apr_errno.h" #include "apr_lib.h" #include "apr_thread_mutex.h" +#ifndef WAITIO_USES_POLL #include "apr_poll.h" +#endif /* System headers the file I/O library needs */ #if APR_HAVE_FCNTL_H @@ -131,10 +133,10 @@ struct apr_file_t { int buffered; enum {BLK_UNKNOWN, BLK_OFF, BLK_ON } blocking; int ungetchar; /* Last char provided by an unget op. (-1 = no char)*/ - +#ifndef WAITIO_USES_POLL /* if there is a timeout set, then this pollset is used */ apr_pollset_t *pollset; - +#endif /* 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 4938cf6bc..ef5027354 100644 --- a/include/arch/unix/apr_arch_networkio.h +++ b/include/arch/unix/apr_arch_networkio.h @@ -61,7 +61,9 @@ #include "apr_errno.h" #include "apr_general.h" #include "apr_lib.h" +#ifndef WAITIO_USES_POLL #include "apr_poll.h" +#endif /* System headers the network I/O library needs */ #if APR_HAVE_SYS_TYPES_H @@ -153,9 +155,10 @@ struct apr_socket_t { apr_int32_t options; apr_int32_t inherit; sock_userdata_t *userdata; - +#ifndef WAITIO_USES_POLL /* if there is a timeout set, then this pollset is used */ apr_pollset_t *pollset; +#endif }; const char *apr_inet_ntop(int af, const void *src, char *dst, apr_size_t size); diff --git a/network_io/unix/sockets.c b/network_io/unix/sockets.c index 342f619cc..1c1638932 100644 --- a/network_io/unix/sockets.c +++ b/network_io/unix/sockets.c @@ -103,10 +103,11 @@ 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; - +#ifndef WAITIO_USES_POLL /* Create a pollset with room for one descriptor. */ /* ### check return codes */ (void) apr_pollset_create(&(*new)->pollset, 1, p, 0); +#endif } apr_status_t apr_socket_protocol_get(apr_socket_t *sock, int *protocol) diff --git a/support/unix/waitio.c b/support/unix/waitio.c index 84a8483c7..be918b13d 100644 --- a/support/unix/waitio.c +++ b/support/unix/waitio.c @@ -66,6 +66,41 @@ #ifdef USE_WAIT_FOR_IO +#ifdef WAITIO_USES_POLL + +#ifdef HAVE_POLL_H +#include <poll.h> +#endif +#ifdef HAVE_SYS_POLL_H +#include <sys/poll.h> +#endif + +apr_status_t apr_wait_for_io_or_timeout(apr_file_t *f, apr_socket_t *s, + int for_read) +{ + struct pollfd pfd; + int rc, timeout; + + timeout = f ? f->timeout / 1000 : s->timeout / 1000; + pfd.fd = f ? f->filedes : s->socketdes; + pfd.events = for_read ? POLLIN : POLLOUT; + + do { + rc = poll(&pfd, 1, timeout); + } while (rc == -1 && errno == EINTR); + if (rc == 0) { + return APR_TIMEUP; + } + else if (rc > 0) { + return APR_SUCCESS; + } + else { + return errno; + } +} + +#else + apr_status_t apr_wait_for_io_or_timeout(apr_file_t *f, apr_socket_t *s, int for_read) { @@ -114,5 +149,6 @@ apr_status_t apr_wait_for_io_or_timeout(apr_file_t *f, apr_socket_t *s, return status; } +#endif /* WAITIO_USES_POLL */ #endif /* USE_WAIT_FOR_IO */ |