curl / Mailing Lists / curl-library / Single Mail

curl-library

Re: imaps + CURLOPT_CONNECT_ONLY + CURLINFO_ACTIVESOCKET vs. multi interface

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Thu, 23 Mar 2017 00:05:32 +0100 (CET)

On Wed, 22 Mar 2017, Deweloper wrote:

> Unfortunately I was unable to find a description on how to use
> CURLINFO_ACTIVESOCKET with the multi interface, neither at
> https://curl.haxx.se/libcurl/c/CURLINFO_ACTIVESOCKET.html nor in the
> examples at https://curl.haxx.se/libcurl/c/example.html .
>
> I have already discovered that after getting CURLMSG_DONE the easy handle
> must remain added to the multi handle, otherwise
> curl_easy_getinfo(CURLINFO_ACTIVESOCKET) gives CURL_SOCKET_BAD.

Right, because removing the handle from the multi handle is abandoning the
connection. Everything related to that is then handed over to the multi handle
and the easy handle doesn't "own" the connection anymore.

> Later I found this information by browsing the curl source code (inside the
> body of Curl_getconnectinfo). Maybe it's worth including in the manual page
> of CURLINFO_ACTIVESOCKET ?

Sounds like a good idea. You have any wording to suggest that would've helped
you?

>> The manual also says: When you finish working with the socket, you must
>> call curl_easy_cleanup as usual on the easy handle

> What if I want to repeat the transfer?

A connection you've "taken over" from libcurl is tainted and libcurl can never
again reuse that since the status and protocol of it are totally unknown.

But I'm not sure this needs to be taken into account much. I think you can
reuse an easy handle but it won't (shouldn't!) reuse the previous connection.

> Isn't it allowed to call curl_easy_perform again on the same handle?

It should be. I wonder if it isn't also actually okay to reuse an easy handle,
contrary to what the documentation says...

> And, more importantly, what to do in the case of multi interface? Is it
> sufficient to call curl_multi_remove_handle and curl_multi_add_handle to
> repeat the transfer?

Yes, that is how to repeat the exact same transfer with the multi handle.

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