1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

Added CURLMOPT_MAXCONNECTS which is a curl_multi_setopt() option for setting

the maximum size of the connection cache maximum size of the multi handle.
This commit is contained in:
Daniel Stenberg 2007-05-30 20:04:44 +00:00
parent 9583b51d80
commit a49e78d9b7
6 changed files with 50 additions and 9 deletions

View File

@ -5,6 +5,10 @@
\___|\___/|_| \_\_____| \___|\___/|_| \_\_____|
Changelog Changelog
Daniel S (30 May 2007)
- Added CURLMOPT_MAXCONNECTS which is a curl_multi_setopt() option for setting
the maximum size of the connection cache maximum size of the multi handle.
Daniel S (27 May 2007) Daniel S (27 May 2007)
- When working with a problem Stefan Becker had, I found an off-by-one buffer - When working with a problem Stefan Becker had, I found an off-by-one buffer
overwrite in Curl_select(). While fixing it, I also improved its performance overwrite in Curl_select(). While fixing it, I also improved its performance

View File

@ -17,6 +17,7 @@ This release includes the following changes:
o CURLOPT_HTTP200ALIASES matched transfers assume HTTP 1.0 compliance o CURLOPT_HTTP200ALIASES matched transfers assume HTTP 1.0 compliance
o more than one test harness can run at the same time without conflict o more than one test harness can run at the same time without conflict
o SFTP now supports quote commands before a transfer o SFTP now supports quote commands before a transfer
o CURLMOPT_MAXCONNECTS added to curl_multi_setopt()
This release includes the following bugfixes: This release includes the following bugfixes:

View File

@ -1129,10 +1129,10 @@ speed. (Added in 7.15.5)
.IP CURLOPT_MAXCONNECTS .IP CURLOPT_MAXCONNECTS
Pass a long. The set number will be the persistent connection cache size. The Pass a long. The set number will be the persistent connection cache size. The
set amount will be the maximum amount of simultaneously open connections that set amount will be the maximum amount of simultaneously open connections that
libcurl may cache. Default is 5, and there isn't much point in changing this libcurl may cache in this easy handle. Default is 5, and there isn't much
value unless you are perfectly aware of how this work and changes libcurl's point in changing this value unless you are perfectly aware of how this work
behaviour. This concerns connection using any of the protocols that support and changes libcurl's behaviour. This concerns connection using any of the
persistent connections. protocols that support persistent connections.
When reaching the maximum limit, curl closes the oldest one in the cache to When reaching the maximum limit, curl closes the oldest one in the cache to
prevent the number of open connections to increase. prevent the number of open connections to increase.
@ -1140,6 +1140,10 @@ prevent the number of open connections to increase.
If you already have performed transfers with this curl handle, setting a If you already have performed transfers with this curl handle, setting a
smaller MAXCONNECTS than before may cause open connections to get closed smaller MAXCONNECTS than before may cause open connections to get closed
unnecessarily. unnecessarily.
Note that if you add this easy handle to a multi handle, this setting is not
being acknowledged, but you must instead use \fIcurl_multi_setopt(3)\fP and
the \fICURLMOPT_MAXCONNECTS\fP option.
.IP CURLOPT_CLOSEPOLICY .IP CURLOPT_CLOSEPOLICY
(Obsolete) This option does nothing. (Obsolete) This option does nothing.
.IP CURLOPT_FRESH_CONNECT .IP CURLOPT_FRESH_CONNECT

View File

@ -56,6 +56,22 @@ Pass a pointer to whatever you want passed to the
\fBcurl_multi_timer_callback\fP's third argument, the userp pointer. This is \fBcurl_multi_timer_callback\fP's third argument, the userp pointer. This is
not used by libcurl but only passed-thru as-is. Set the callback pointer with not used by libcurl but only passed-thru as-is. Set the callback pointer with
\fICURLMOPT_TIMERFUNCTION\fP. (Added in 7.16.0) \fICURLMOPT_TIMERFUNCTION\fP. (Added in 7.16.0)
.IP CURLMOPT_MAXCONNECTS
Pass a long. The set number will be used as the maximum amount of
simultaneously open connections that libcurl may cache. Default is 10, and
libcurl will enlarge the size for each added easy handle to make it fit 4
times the number of added easy handles.
By setting this option, you can prevent the cache size to grow beyond the
limit set by you.
When the cache is full, curl closes the oldest one in the cache to prevent the
number of open connections to increase.
This option is for the multi handle's use only, when using the easy interface
you should instead use the \fICURLOPT_MAXCONNECTS\fP option.
(Added in 7.16.3)
.SH RETURNS .SH RETURNS
The standard CURLMcode for multi interface error codes. Note that it returns a The standard CURLMcode for multi interface error codes. Note that it returns a
CURLM_UNKNOWN_OPTION if you try setting an option that this version of libcurl CURLM_UNKNOWN_OPTION if you try setting an option that this version of libcurl

View File

@ -309,6 +309,9 @@ typedef enum {
/* This is the argument passed to the timer callback */ /* This is the argument passed to the timer callback */
CINIT(TIMERDATA, OBJECTPOINT, 5), CINIT(TIMERDATA, OBJECTPOINT, 5),
/* maximum number of entries in the connection cache */
CINIT(MAXCONNECTS, LONG, 6),
CURLMOPT_LASTENTRY /* the last unused */ CURLMOPT_LASTENTRY /* the last unused */
} CURLMoption; } CURLMoption;

View File

@ -160,6 +160,8 @@ struct Curl_multi {
/* shared connection cache */ /* shared connection cache */
struct conncache *connc; struct conncache *connc;
long maxconnects; /* if >0, a fixed limit of the maximum number of entries
we're allowed to grow the connection cache to */
/* list of easy handles kept around for doing nice connection closures */ /* list of easy handles kept around for doing nice connection closures */
struct closure *closure; struct closure *closure;
@ -484,12 +486,20 @@ CURLMcode curl_multi_add_handle(CURLM *multi_handle,
/* We want the connection cache to have plenty room. Before we supported /* We want the connection cache to have plenty room. Before we supported
the shared cache every single easy handle had 5 entries in their cache the shared cache every single easy handle had 5 entries in their cache
by default. */ by default. */
CURLcode res = Curl_ch_connc(easy_handle, multi->connc, int newmax = multi->num_easy * 4;
multi->num_easy * 4);
if(multi->maxconnects && (multi->maxconnects < newmax))
/* don't grow beyond the allowed size */
newmax = multi->maxconnects;
if(newmax > multi->connc->num) {
/* we only do this is we can in fact grow the cache */
CURLcode res = Curl_ch_connc(easy_handle, multi->connc, newmax);
if(res != CURLE_OK) if(res != CURLE_OK)
/* TODO: we need to do some cleaning up here! */ /* TODO: we need to do some cleaning up here! */
return CURLM_OUT_OF_MEMORY; return CURLM_OUT_OF_MEMORY;
} }
}
/* increase the alive-counter */ /* increase the alive-counter */
multi->num_alive++; multi->num_alive++;
@ -1810,6 +1820,9 @@ CURLMcode curl_multi_setopt(CURLM *multi_handle,
case CURLMOPT_TIMERDATA: case CURLMOPT_TIMERDATA:
multi->timer_userp = va_arg(param, void *); multi->timer_userp = va_arg(param, void *);
break; break;
case CURLMOPT_MAXCONNECTS:
multi->maxconnects = va_arg(param, long);
break;
default: default:
res = CURLM_UNKNOWN_OPTION; res = CURLM_UNKNOWN_OPTION;
break; break;