cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Limiting the number of active connections/transfers.

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Mon, 4 Apr 2011 23:37:11 +0200 (CEST)

On Mon, 4 Apr 2011, Vladimir Grishchenko wrote:

> I need to put a hard upper bound on the number of connections through
> libcurl, is there an easy way of doing it with libcurl? For example, there
> are CURLMOPT_MAXCONNECTS and CURLOPT_MAXCONNECTS options, but my
> understanding is that they only apply to cached idle connections that can be
> reused and libcurl will always attempt to open a new connection when
> requested and I need to roll out my own solution, is that correct?

As you're mentioning CURLMOPT_MAXCONNECTS I assume you're using the multi
interface? I'll assume so here.

libcurl will then not keep around more than CURLMOPT_MAXCONNECTS in its pool
of previous and current connections. However, you then add new easy handles to
the multi handle, and each such concurrent handle can have its own connection
so even if you set CURLMOPT_MAXCONNECTS to a very small number, libcurl will
use more connections than so if you add more easy handles. But when you remove
the easy handles again, libcurl will not keep more than CURLMOPT_MAXCONNECTS
in its pool.

Thus: if you set CURLMOPT_MAXCONNECTS to N and you never add more than N easy
handles to the multi handle (simultaneously, in any single given moment),
libcurl should not keep more than N connections around.

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2011-04-04