summaryrefslogtreecommitdiff
path: root/lib/url.c
diff options
context:
space:
mode:
authorRichy Kim <richy@fb.com>2016-12-20 05:48:15 -0500
committerDaniel Stenberg <daniel@haxx.se>2017-01-19 23:38:04 +0100
commit6b7616690e5370c21e3a760321af6bf4edbabfb6 (patch)
tree15ff13a118a311f3a604686103b6d0eaaee6ced4 /lib/url.c
parent81cb255cb355ca35453e7297af9cbc8ff7798416 (diff)
downloadcurl-6b7616690e5370c21e3a760321af6bf4edbabfb6.tar.gz
CURLOPT_BUFFERSIZE: support enlarging receive buffer
Replace use of fixed macro BUFSIZE to define the size of the receive buffer. Reappropriate CURLOPT_BUFFERSIZE to include enlarging receive buffer size. Upon setting, resize buffer if larger than the current default size up to a MAX_BUFSIZE (512KB). This can benefit protocols like SFTP. Closes #1222
Diffstat (limited to 'lib/url.c')
-rw-r--r--lib/url.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/lib/url.c b/lib/url.c
index 1434d8f80..f5039bad8 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -452,6 +452,7 @@ CURLcode Curl_close(struct Curl_easy *data)
}
data->change.url = NULL;
+ Curl_safefree(data->state.buffer);
Curl_safefree(data->state.headerbuff);
Curl_flush_cookies(data, 1);
@@ -641,6 +642,12 @@ CURLcode Curl_open(struct Curl_easy **curl)
/* We do some initial setup here, all those fields that can't be just 0 */
+ data->state.buffer = malloc(BUFSIZE + 1);
+ if(!data->state.buffer) {
+ DEBUGF(fprintf(stderr, "Error: malloc of buffer failed\n"));
+ result = CURLE_OUT_OF_MEMORY;
+ }
+
data->state.headerbuff = malloc(HEADERSIZE);
if(!data->state.headerbuff) {
DEBUGF(fprintf(stderr, "Error: malloc of headerbuff failed\n"));
@@ -671,6 +678,7 @@ CURLcode Curl_open(struct Curl_easy **curl)
if(result) {
Curl_resolver_cleanup(data->state.resolver);
+ free(data->state.buffer);
free(data->state.headerbuff);
Curl_freeset(data);
free(data);
@@ -2268,9 +2276,20 @@ CURLcode Curl_setopt(struct Curl_easy *data, CURLoption option,
*/
data->set.buffer_size = va_arg(param, long);
- if((data->set.buffer_size> (BUFSIZE -1)) ||
- (data->set.buffer_size < 1))
- data->set.buffer_size = 0; /* huge internal default */
+ if(data->set.buffer_size > MAX_BUFSIZE)
+ data->set.buffer_size = MAX_BUFSIZE; /* huge internal default */
+ else if(data->set.buffer_size < 1)
+ data->set.buffer_size = BUFSIZE;
+
+ /* Resize only if larger than default buffer size. */
+ if(data->set.buffer_size > BUFSIZE) {
+ data->state.buffer = realloc(data->state.buffer,
+ data->set.buffer_size + 1);
+ if(!data->state.buffer) {
+ DEBUGF(fprintf(stderr, "Error: realloc of buffer failed\n"));
+ result = CURLE_OUT_OF_MEMORY;
+ }
+ }
break;