summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrianp <brianp@13f79535-47bb-0310-9956-ffa450edef68>2005-07-23 04:18:50 +0000
committerbrianp <brianp@13f79535-47bb-0310-9956-ffa450edef68>2005-07-23 04:18:50 +0000
commitb3b62ef2949914968a4a5b2852e90054116f7aed (patch)
tree85791ca0a4e58e5f091f4028726cc7fc0fee6b66
parent611c3b86c97b620efe2a672953920b53d69d3d01 (diff)
downloadlibapr-b3b62ef2949914968a4a5b2852e90054116f7aed.tar.gz
lazy initialization of the pollset within apr_file_t (backport from 1.2)
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/branches/1.0.x@224440 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--CHANGES6
-rw-r--r--STATUS10
-rw-r--r--file_io/unix/filedup.c14
-rw-r--r--file_io/unix/open.c28
-rw-r--r--file_io/unix/pipe.c18
-rw-r--r--support/unix/waitio.c12
6 files changed, 54 insertions, 34 deletions
diff --git a/CHANGES b/CHANGES
index 4096f7a12..66816ed18 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,11 @@
Changes for APR 1.0.2
+ *) Switch to lazy initialization of the pollset that's used within
+ apr_file_t on platforms where apr_wait_for_io_or_timeout() doesn't
+ use poll(2). (This fixes a performance problem observed in httpd-2.x
+ on OS X due to the use of poll now being disabled by default on that
+ platform.) [Brian Pane]
+
*) Support APR_SO_SNDBUF and APR_SO_RCVBUF on Windows. PR 32177.
[Sim <sgobbi datamanagement.it>, Jeff Trawick]
diff --git a/STATUS b/STATUS
index 15342b63e..a6050d926 100644
--- a/STATUS
+++ b/STATUS
@@ -28,16 +28,6 @@ RELEASE 1.0.1 SHOWSTOPPERS:
CURRENT VOTES:
- *) Backport r209931 from 1.2 development trunk:
- "Switch to lazy initialization of the pollset that's used within
- apr_file_t on platforms where apr_wait_for_io_or_timeout() doesn't
- use poll(2). (This fixes a performance problem observed in httpd-2.x
- on OS X due to the use of poll now being disabled by default on that
- platform.)"
- +1: brianp
- 0:
- -1:
-
CURRENT test/testall -v EXCEPTIONS:
Please add any platform anomilies to the following exception list.
diff --git a/file_io/unix/filedup.c b/file_io/unix/filedup.c
index f9f9f1d3e..fdc0358e0 100644
--- a/file_io/unix/filedup.c
+++ b/file_io/unix/filedup.c
@@ -1,4 +1,5 @@
-/* Copyright 2000-2004 The Apache Software Foundation
+/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
+ * applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -92,9 +93,10 @@ static apr_status_t file_dup(apr_file_t **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);
+ /* Start out with no pollset. apr_wait_for_io_or_timeout() will
+ * initialize the pollset if needed.
+ */
+ (*new_file)->pollset = NULL;
#endif
return APR_SUCCESS;
}
@@ -149,9 +151,7 @@ APR_DECLARE(apr_status_t) apr_file_setaside(apr_file_t **new_file,
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);
+ (*new_file)->pollset = NULL;
#endif
return APR_SUCCESS;
}
diff --git a/file_io/unix/open.c b/file_io/unix/open.c
index eab278f64..589c85314 100644
--- a/file_io/unix/open.c
+++ b/file_io/unix/open.c
@@ -1,4 +1,5 @@
-/* Copyright 2000-2004 The Apache Software Foundation
+/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
+ * applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,6 +49,17 @@ apr_status_t apr_unix_file_cleanup(void *thefile)
/* Are there any error conditions other than EINTR or EBADF? */
rv = errno;
}
+#ifndef WAITIO_USES_POLL
+ if (file->pollset != NULL) {
+ apr_status_t pollset_rv = apr_pollset_destroy(file->pollset);
+ /* If the file close failed, return its error value,
+ * not apr_pollset_destroy()'s.
+ */
+ if (rv == APR_SUCCESS) {
+ rv = pollset_rv;
+ }
+ }
+#endif /* !WAITIO_USES_POLL */
return rv != APR_SUCCESS ? rv : flush_rv;
}
@@ -158,9 +170,10 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new,
(*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);
+ /* Start out with no pollset. apr_wait_for_io_or_timeout() will
+ * initialize the pollset if needed.
+ */
+ (*new)->pollset = NULL;
#endif
if (!(flag & APR_FILE_NOCLEANUP)) {
apr_pool_cleanup_register((*new)->pool, (void *)(*new),
@@ -219,9 +232,10 @@ APR_DECLARE(apr_status_t) apr_os_file_put(apr_file_t **file,
(*file)->buffered = (flags & APR_BUFFERED) > 0;
#ifndef WAITIO_USES_POLL
- /* Create a pollset with room for one descriptor. */
- /* ### check return codes */
- (void) apr_pollset_create(&(*file)->pollset, 1, pool, 0);
+ /* Start out with no pollset. apr_wait_for_io_or_timeout() will
+ * initialize the pollset if needed.
+ */
+ (*file)->pollset = NULL;
#endif
if ((*file)->buffered) {
diff --git a/file_io/unix/pipe.c b/file_io/unix/pipe.c
index 7013160cd..d8e52495c 100644
--- a/file_io/unix/pipe.c
+++ b/file_io/unix/pipe.c
@@ -1,4 +1,5 @@
-/* Copyright 2000-2004 The Apache Software Foundation
+/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
+ * applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,7 +43,7 @@ static apr_status_t pipeblock(apr_file_t *thepipe)
fd_flags &= ~O_NONBLOCK;
# elif defined(O_NDELAY)
fd_flags &= ~O_NDELAY;
-# elif defined(FNDELAY)
+# elif defined(O_FNDELAY)
fd_flags &= ~O_FNDELAY;
# else
/* XXXX: this breaks things, but an alternative isn't obvious...*/
@@ -77,7 +78,7 @@ static apr_status_t pipenonblock(apr_file_t *thepipe)
fd_flags |= O_NONBLOCK;
# elif defined(O_NDELAY)
fd_flags |= O_NDELAY;
-# elif defined(FNDELAY)
+# elif defined(O_FNDELAY)
fd_flags |= O_FNDELAY;
# else
/* XXXX: this breaks things, but an alternative isn't obvious...*/
@@ -160,9 +161,10 @@ APR_DECLARE(apr_status_t) apr_os_pipe_put_ex(apr_file_t **file,
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);
+ /* Start out with no pollset. apr_wait_for_io_or_timeout() will
+ * initialize the pollset if needed.
+ */
+ (*file)->pollset = NULL;
#endif
return APR_SUCCESS;
}
@@ -196,7 +198,7 @@ APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, apr_file_t **out
(*in)->thlock = NULL;
#endif
#ifndef WAITIO_USES_POLL
- (void) apr_pollset_create(&(*in)->pollset, 1, pool, 0);
+ (*in)->pollset = NULL;
#endif
(*out) = (apr_file_t *)apr_pcalloc(pool, sizeof(apr_file_t));
(*out)->pool = pool;
@@ -211,7 +213,7 @@ APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, apr_file_t **out
(*out)->thlock = NULL;
#endif
#ifndef WAITIO_USES_POLL
- (void) apr_pollset_create(&(*out)->pollset, 1, pool, 0);
+ (*out)->pollset = NULL;
#endif
apr_pool_cleanup_register((*in)->pool, (void *)(*in), apr_unix_file_cleanup,
apr_pool_cleanup_null);
diff --git a/support/unix/waitio.c b/support/unix/waitio.c
index dae9e3813..167ad6d08 100644
--- a/support/unix/waitio.c
+++ b/support/unix/waitio.c
@@ -1,4 +1,5 @@
-/* Copyright 2000-2004 The Apache Software Foundation
+/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
+ * applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -60,7 +61,7 @@ apr_status_t apr_wait_for_io_or_timeout(apr_file_t *f, apr_socket_t *s,
}
}
-#else
+#else /* !WAITIO_USES_POLL */
apr_status_t apr_wait_for_io_or_timeout(apr_file_t *f, apr_socket_t *s,
int for_read)
@@ -77,6 +78,13 @@ apr_status_t apr_wait_for_io_or_timeout(apr_file_t *f, apr_socket_t *s,
pfd.desc.f = f;
pollset = f->pollset;
+ if (pollset == NULL) {
+ status = apr_pollset_create(&(f->pollset), 1, f->pool, 0);
+ if (status != APR_SUCCESS) {
+ return status;
+ }
+ pollset = f->pollset;
+ }
timeout = f->timeout;
}
else {