aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2006-09-16 21:50:29 +0000
committerDaniel Stenberg <daniel@haxx.se>2006-09-16 21:50:29 +0000
commit2d5fc39d3573c10a460cdeb2139631da62b8e391 (patch)
tree7a10af6d214a8b45860080bf357969f4223e040c
parentc001ed53fa89f203e3d6aa402e9a9126dc34f5b1 (diff)
Resize the connection cache upwards when adding more handles than what
currently fits in the cache, to make the cache work better especially for pipelining cases but also for "mere" (persistent) connection re-use.
-rw-r--r--lib/multi.c12
-rw-r--r--lib/url.c85
-rw-r--r--lib/url.h4
-rw-r--r--lib/urldata.h2
4 files changed, 62 insertions, 41 deletions
diff --git a/lib/multi.c b/lib/multi.c
index 77c6a9fb4..2f7f32870 100644
--- a/lib/multi.c
+++ b/lib/multi.c
@@ -423,6 +423,18 @@ CURLMcode curl_multi_add_handle(CURLM *multi_handle,
/* increase the node-counter */
multi->num_easy++;
+
+ if((multi->num_easy+5) > multi->connc->num) {
+ /* we want the connection cache to have room for all easy transfers, and
+ some more so we have a margin of 5 for now, but we add the new amount
+ plus 10 to not have to do it for every new handle added */
+ CURLcode res = Curl_ch_connc(easy_handle, multi->connc,
+ multi->num_easy + 10);
+ if(res)
+ /* TODO: we need to do some cleaning up here! */
+ return res;
+ }
+
/* increase the alive-counter */
multi->num_alive++;
diff --git a/lib/url.c b/lib/url.c
index f3d21e869..3f59299be 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -346,6 +346,49 @@ struct conncache *Curl_mk_connc(int type)
return c;
}
+/* Change number of entries of a connection cache */
+CURLcode Curl_ch_connc(struct SessionHandle *data,
+ struct conncache *c,
+ long newamount)
+{
+ int i;
+ struct connectdata **newptr;
+
+ 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
+ are being removed!
+
+ NOTE: for conncache_multi cases we must make sure that we only
+ close handles not in use.
+ */
+ for(i=newamount; i< c->num; i++)
+ Curl_disconnect(c->connects[i]);
+
+ /* If the most recent connection is no longer valid, mark it
+ invalid. */
+ if(data->state.lastconnect <= newamount)
+ data->state.lastconnect = -1;
+ }
+ if(newamount > 0) {
+ newptr= (struct connectdata **)
+ realloc(c->connects, sizeof(struct connectdata *) * newamount);
+ if(!newptr)
+ /* we closed a few connections in vain, but so what? */
+ return CURLE_OUT_OF_MEMORY;
+
+ /* nullify the newly added pointers */
+ for(i=c->num; i<newamount; i++)
+ newptr[i] = NULL;
+
+ c->connects = newptr;
+ c->num = newamount;
+ }
+ /* we no longer support less than 1 as size for the connection cache, and
+ I'm not sure it ever worked to set it to zero */
+ return CURLE_OK;
+}
+
/* Free a connection cache. This is called from Curl_close() and
curl_multi_cleanup(). */
void Curl_rm_connc(struct conncache *c)
@@ -521,45 +564,7 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
* Set the absolute number of maximum simultaneous alive connection that
* libcurl is allowed to have.
*/
- {
- long newconnects= va_arg(param, long);
- struct connectdata **newptr;
- long i;
-
- if(newconnects < data->state.connc->num) {
- /* Since this number is *decreased* from the existing number, we must
- close the possibly open connections that live on the indexes that
- are being removed!
-
- NOTE: for conncache_multi cases we must make sure that we only
- close handles not in use.
- */
- for(i=newconnects; i< data->state.connc->num; i++)
- Curl_disconnect(data->state.connc->connects[i]);
-
- /* If the most recent connection is no longer valid, mark it
- invalid. */
- if(data->state.lastconnect <= newconnects)
- data->state.lastconnect = -1;
- }
- if(newconnects > 0) {
- newptr= (struct connectdata **)
- realloc(data->state.connc->connects,
- sizeof(struct connectdata *) * newconnects);
- if(!newptr)
- /* we closed a few connections in vain, but so what? */
- return CURLE_OUT_OF_MEMORY;
-
- /* nullify the newly added pointers */
- for(i=data->state.connc->num; i<newconnects; i++)
- newptr[i] = NULL;
-
- data->state.connc->connects = newptr;
- data->state.connc->num = newconnects;
- }
- /* we no longer support less than 1 as size for the connection cache,
- and I'm not sure it ever worked to set it to zero */
- }
+ result = Curl_ch_connc(data, data->state.connc, va_arg(param, long));
break;
case CURLOPT_FORBID_REUSE:
/*
@@ -3115,7 +3120,7 @@ static CURLcode CreateConnection(struct SessionHandle *data,
conn->connectindex = -1; /* no index */
conn->bits.httpproxy = (bool)(data->change.proxy /* http proxy or not */
- && *data->change.proxy
+ && *data->change.proxy
&& (data->set.proxytype == CURLPROXY_HTTP));
/* Default protocol-independent behavior doesn't support persistent
diff --git a/lib/url.h b/lib/url.h
index 4b65a7ab7..e1754c333 100644
--- a/lib/url.h
+++ b/lib/url.h
@@ -50,6 +50,10 @@ void Curl_safefree(void *ptr);
struct conncache *Curl_mk_connc(int type);
/* free a connection cache */
void Curl_rm_connc(struct conncache *c);
+/* Change number of entries of a connection cache */
+CURLcode Curl_ch_connc(struct SessionHandle *data,
+ struct conncache *c,
+ long newamount);
int Curl_protocol_getsock(struct connectdata *conn,
curl_socket_t *socks,
diff --git a/lib/urldata.h b/lib/urldata.h
index 9f8e6de80..d90c6cd08 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -951,7 +951,7 @@ struct conncache {
/* 'connects' will be an allocated array with pointers. If the pointer is
set, it holds an allocated connection. */
struct connectdata **connects;
- long num; /* size of the 'connects' array */
+ long num; /* number of entries of the 'connects' array */
enum {
CONNCACHE_PRIVATE, /* used for an easy handle alone */
CONNCACHE_MULTI /* shared within a multi handle */