summaryrefslogtreecommitdiff
path: root/support
diff options
context:
space:
mode:
authortrawick <trawick@13f79535-47bb-0310-9956-ffa450edef68>2003-11-24 00:17:24 +0000
committertrawick <trawick@13f79535-47bb-0310-9956-ffa450edef68>2003-11-24 00:17:24 +0000
commit68c1e93f42055e53b73bbf0ccc1bbc75641bcc16 (patch)
tree4576f6e50f7167bf9049e3d9b680c1288b43b82c /support
parent438b4efe110fd3e6ee558a5f5135e09013f6685b (diff)
downloadlibapr-68c1e93f42055e53b73bbf0ccc1bbc75641bcc16.tar.gz
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
Diffstat (limited to 'support')
-rw-r--r--support/unix/waitio.c36
1 files changed, 36 insertions, 0 deletions
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 */