cURL / Mailing Lists / curl-library / Single Mail


Re: Problem with reusing persistent connections

From: Stefan Krause <>
Date: Tue, 25 Sep 2007 20:54:14 +0200

Dan Fandrich wrote:
> On Thu, Sep 13, 2007 at 09:45:10PM +0200, Stefan Krause wrote:
>> Normally I do more than one transfer between the physical connection goes
>> down (due to segmented transfers). As always HTTPS is used I get a big
>> overhead with the SSL handshakes when CURLOPT_FORBID_REUSE is used.
>> Calling curl_easy_cleanup() seems to be the only function which closes the
>> socket connections on demand, I found nothing similar. That call will also
>> delete all the other options and data associated with the handle.
>> Unfortunately I need this information for continuing the segmented HTTP
>> transfer.
> Sounds like you want a curl_easy_close() or something to only close any
> sockets reserved by that easy handle but leave everything else unchanged.
In the recent days I did some more investigations on that topic. I just
would like to mention some details which I missed in my first post:

I have one multi handle (MH). Up to two easy handles (EH1, EH2) may be
added to the multi handle at a time.
A segmented data transfer is done via EH1. Therefore EH1 is setup and
added to the MH. After EH1 has been completed with the first segment
(using the HTTP Content-Length header to retrieve a segment from the
server), it is removed from the MH. That is repeated until all segments
have been transferred. After the last segment has been transferred, the
EH1 is destroyed by calling curl_easy_cleanup() on the handle. I
expected that the socket connection of the handle would have been closed
after. But that was not the case. The socket connection still exists.
After I setup EH2 and add it to the MH, the socket connection which has
been used by EH1 has also been used by EH2. Is the reason for that, that
the EH1 and EH2 does not have a private connection cache, but share the
connection cache from the MH?. So curl_easy_cleanup() does not have the
effect of closing open socket connections. I think I have to clean the
MH with curl_multi_cleanup() in order to close all socket connections?
Is that correct?

The sequence now to close all socket connections when using a multi
handle will be the following according to my understanding:

1) Remove all EH from the MH (Is there a possibility to determine all
currently added EH, or do I have to track them separately?)
2) Cleanup the MH
3) Cleanup all EH

Now restore the privious state but without any open socket connection:
1) Create a new MH
2) Create new EH, restore their states
3) Add all EH to the MH

Might that be an solution? Do you have any comments / recommendations
concerning that idea?


Received on 2007-09-25