[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnurl] 147/205: multi: make curl_multi_wait avoid malloc i
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnurl] 147/205: multi: make curl_multi_wait avoid malloc in the typical case |
Date: |
Thu, 20 Apr 2017 16:21:27 +0200 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a commit to annotated tag gnurl-7.54.0
in repository gnurl.
commit 5f1163517e1597339d980b6504dbbece43c7027c
Author: Daniel Stenberg <address@hidden>
AuthorDate: Sat Apr 1 01:27:24 2017 +0200
multi: make curl_multi_wait avoid malloc in the typical case
When only a few additional file descriptors are used, avoid the malloc.
Closes #1377
---
lib/multi.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/lib/multi.c b/lib/multi.c
index 47e24005a..47101376a 100644
--- a/lib/multi.c
+++ b/lib/multi.c
@@ -974,6 +974,8 @@ CURLMcode curl_multi_fdset(struct Curl_multi *multi,
return CURLM_OK;
}
+#define NUM_POLLS_ON_STACK 10
+
CURLMcode curl_multi_wait(struct Curl_multi *multi,
struct curl_waitfd extra_fds[],
unsigned int extra_nfds,
@@ -987,8 +989,10 @@ CURLMcode curl_multi_wait(struct Curl_multi *multi,
unsigned int nfds = 0;
unsigned int curlfds;
struct pollfd *ufds = NULL;
+ bool ufds_malloc = FALSE;
long timeout_internal;
int retcode = 0;
+ struct pollfd a_few_on_stack[NUM_POLLS_ON_STACK];
if(!GOOD_MULTI_HANDLE(multi))
return CURLM_BAD_HANDLE;
@@ -1028,9 +1032,14 @@ CURLMcode curl_multi_wait(struct Curl_multi *multi,
nfds += extra_nfds; /* add the externally provided ones */
if(nfds || extra_nfds) {
- ufds = malloc(nfds * sizeof(struct pollfd));
- if(!ufds)
- return CURLM_OUT_OF_MEMORY;
+ if(nfds > NUM_POLLS_ON_STACK) {
+ ufds = malloc(nfds * sizeof(struct pollfd));
+ if(!ufds)
+ return CURLM_OUT_OF_MEMORY;
+ ufds_malloc = TRUE;
+ }
+ else
+ ufds = &a_few_on_stack[0];
}
nfds = 0;
@@ -1108,7 +1117,8 @@ CURLMcode curl_multi_wait(struct Curl_multi *multi,
}
}
- free(ufds);
+ if(ufds_malloc)
+ free(ufds);
if(ret)
*ret = retcode;
return CURLM_OK;
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [gnurl] 199/205: openssl: fix thread-safety bugs in error-handling, (continued)
- [GNUnet-SVN] [gnurl] 199/205: openssl: fix thread-safety bugs in error-handling, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 121/205: conncache: make hashkey avoid malloc, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 167/205: low_speed_limit: improved function for longer time periods, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 157/205: multi: fix queueing of pending easy handles, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 78/205: Improve code readbility, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 118/205: http: Fix proxy connection reuse with basic-auth, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 108/205: asiohiper: make sure socket is open in event_cb, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 140/205: libcurl.def: removed, unused, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 182/205: openssl: fix this statement may fall through [-Wimplicit-fallthrough=], gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 48/205: insecure.d: clarify that this is for server connections, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 147/205: multi: make curl_multi_wait avoid malloc in the typical case,
gnunet <=
- [GNUnet-SVN] [gnurl] 196/205: extern-scan.pl: strip trailing CR, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 174/205: vtls: fix unreferenced variable warnings, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 191/205: http2: fix handle leak in error path, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 24/205: fix some typos in the doc (#1306), gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 64/205: authneg: clear auth.multi flag at http_done, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 104/205: tests/README: mention nroff for --manual tests, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 73/205: tests: clear the SSL_CERT_FILE variable on --libcurl tests, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 55/205: mkhelp: simplified the gzip code, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 102/205: travis: run tests-nonflaky instead of tests-full, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 77/205: winbuild: add basic support for OpenSSL 1.1.x, gnunet, 2017/04/20