From 68c1e93f42055e53b73bbf0ccc1bbc75641bcc16 Mon Sep 17 00:00:00 2001 From: trawick Date: Mon, 24 Nov 2003 00:17:24 +0000 Subject: on Unix-ish platforms, apr_wait_for_io_or_timeout() can just use poll(2) it is a perfect match for the feature set needed and avoids the setup code at object creation time currently required to use apr_pollset_poll() instead of poll(2) future: select()-based function is trivial too is any platform then left needing the support in apr/(network_io|file_io)/unix for allocating a pollset any time we create a file or socket just in case apr_wait_for_io_or_timeout() will be called? git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@64794 13f79535-47bb-0310-9956-ffa450edef68 --- support/unix/waitio.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'support') 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 +#endif +#ifdef HAVE_SYS_POLL_H +#include +#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 */ -- cgit v1.2.1