curl / Mailing Lists / curl-library / Single Mail

curl-library

Understanding sharing of state with "multi" interface

From: corey kasten <coreykasten_at_gmail.com>
Date: Wed, 25 Jan 2017 10:57:10 -0800

Hi:

In section "Persistence Is The Way to Happiness" at
https://curl.haxx.se/libcurl/c/libcurl-tutorial.html, it describes the way
state is maintained on a per-easy handle basis. If I am reading this
correctly, each easy handle has it's own "cache" of open connections, which
implies that if we have two easy handles, having the same URL (i.e.
destination server), then calling curl_easy_perform() on each sequentially
will cause two connections to be opened, one for each easy handle, since
they don't share the "cache" of open connections. Correct?

Now, I'm trying to understand the way state (such as connection "cache",
SSL sessions ID cache, etc) is shared (or not) among multiple easy handles
which have been added to a single multi handle, and I failed to gain
clarity about this from reading
https://curl.haxx.se/libcurl/c/libcurl-multi.html.

So here are my questions:
1. Does a multi handle have its own connection "cache"? And, when an easy
handle is added to a multi handle, does that easy handle cease to have its
own local connection "cache"?

2. Suppose I have two easy handles that have the same URL set, and one
multi handle to which I add both easy handles, and then do
curl_multi_perform(). Will two connections be opened, one corresponding to
each easy handle?

3. Now, suppose I have two easy handles, A and B, that have the same URL
set, and one multi handle. Then, I do the following in sequence:
* Add A
* Call multi_perform() (which successfully connections and completes
transfer)
* Wait for A's completion
* Remove A from the multi handle
* Add B
* Call multi_perform() (which successfully connections and completes
transfer)
Will two connections have been opened? And does this depend timing?

4. Which of the following two are true:
a). An open connection belonging to a multi handle will only be re-used in
a curl_multi_perform() call if the connection is not currently being used
for another one of its transfers in progress; and, if, in fact, it is
currently being used for a transfer, curl_multi_perform() will open a new
parallel connection to the same server, so as not to stall the initiation
of the new transfer.
b). An open connection belonging to a multi_handle will be re-used in a
curl_multi_perform() call even if the connection is currently being used;
in which case, curl_multi_perform will stall the new transfer until the
completion of the previous transfer, in order not to have two parallel
connections to the same server open.

Sorry for the verbosity!

Thanks in advance,
Corey

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2017-01-25