aboutsummaryrefslogtreecommitdiff
path: root/lib/url.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/url.c')
-rw-r--r--lib/url.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/url.c b/lib/url.c
index 71463164a..4f9969dcf 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -377,11 +377,13 @@ CURLcode Curl_close(struct SessionHandle *data)
}
/* create a connection cache of a private or multi type */
-struct conncache *Curl_mk_connc(int type)
+struct conncache *Curl_mk_connc(int type,
+ int amount) /* set -1 to use default */
{
/* It is subject for debate how many default connections to have for a multi
connection cache... */
- int default_amount = (type == CONNCACHE_PRIVATE)?5:10;
+ int default_amount = amount == -1?
+ ((type == CONNCACHE_PRIVATE)?5:10):amount;
struct conncache *c;
c= calloc(sizeof(struct conncache), 1);
@@ -407,6 +409,20 @@ CURLcode Curl_ch_connc(struct SessionHandle *data,
long i;
struct connectdata **newptr;
+ if(newamount < 1)
+ newamount = 1; /* we better have at least one entry */
+
+ if(!c) {
+ /* we get a NULL pointer passed in as connection cache, which means that
+ there is no cache created for this SessionHandle just yet, we create a
+ brand new with the requested size.
+ */
+ data->state.connc = Curl_mk_connc(CONNCACHE_PRIVATE, newamount);
+ if(!data->state.connc)
+ return CURLE_OUT_OF_MEMORY;
+ return CURLE_OK;
+ }
+
if(newamount < c->num) {
/* Since this number is *decreased* from the existing number, we must
close the possibly open connections that live on the indexes that