summaryrefslogtreecommitdiff
path: root/poll/unix
diff options
context:
space:
mode:
authorbrianp <brianp@13f79535-47bb-0310-9956-ffa450edef68>2002-07-31 01:12:43 +0000
committerbrianp <brianp@13f79535-47bb-0310-9956-ffa450edef68>2002-07-31 01:12:43 +0000
commit4b7ee5abcb3729345adfa267c34f1fd50308a7a0 (patch)
treedce7e41c90b344adf986e146d397e477d67ca64d /poll/unix
parent05e4758ed7d61c57428ae8dc5e97ea3e149eca92 (diff)
downloadlibapr-4b7ee5abcb3729345adfa267c34f1fd50308a7a0.tar.gz
Use storage on the stack instead of apr_palloc in apr_poll()
when the number of descriptors is small (Note: The poll API still needs a rewrite in order to be usable with large numbers of descriptors. This change is just a short-term hack to work around the memory leak that apr_poll() was causing in the httpd.) git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@63745 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poll/unix')
-rw-r--r--poll/unix/poll.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/poll/unix/poll.c b/poll/unix/poll.c
index 9b2deb5dc..f697170c6 100644
--- a/poll/unix/poll.c
+++ b/poll/unix/poll.c
@@ -106,17 +106,29 @@ static apr_int16_t get_revent(apr_int16_t event)
return rv;
}
+#define SMALL_POLLSET_LIMIT 8
+
APR_DECLARE(apr_status_t) apr_poll(apr_pollfd_t *aprset, apr_int32_t num,
apr_int32_t *nsds, apr_interval_time_t timeout)
{
- /* obvious optimization, it would be better if this could be allocated
- * on the stack. For a single file/socket, this can be otpimized
- * very cleanly.
- */
- struct pollfd *pollset = apr_palloc(aprset->p,
- sizeof(struct pollfd) * num);
+ struct pollfd tmp_pollset[SMALL_POLLSET_LIMIT];
+ struct pollfd *pollset;
int i;
+ if (num <= SMALL_POLLSET_LIMIT) {
+ pollset = tmp_pollset;
+ }
+ else {
+ /* XXX There are two problems with this code: it leaks
+ * memory, and it requires an O(n)-time loop to copy
+ * n descriptors from the apr_pollfd_t structs into
+ * the pollfd structs. At the moment, it's best suited
+ * for use with fewer than SMALL_POLLSET_LIMIT
+ * descriptors.
+ */
+ pollset = apr_palloc(aprset->p,
+ sizeof(struct pollfd) * num);
+ }
for (i = 0; i < num; i++) {
if (aprset[i].desc_type == APR_POLL_SOCKET) {
pollset[i].fd = aprset[i].desc.s->socketdes;