cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: CURLM Chain of events

From: surf via curl-library <curl-library_at_cool.haxx.se>
Date: Fri, 22 Jan 2016 15:51:30 +0000 (UTC)

> (I try to manually untangle that text blob when I respond now, but please send
> plain old ordinary text mails in the future.)

I switched to basic view and I'm posting plain-text. If this happens again, I'll switch clients.

> Nope. If a socket is ready to get traffic, you'd get that signalled and you'd
> tell libcurl about that. When you tell libcurl there's a timeout, libcurl will
> only check pending handles for timeout actions. It could be to expire timeouts
> or do retries and similar.

So at what point does transfer kick-in exactly?

curl_multi_init();
curl_multi_setopt(curl_m_handle, CURLMOPT_SOCKETFUNCTION, on_socket_callback);
curl_multi_setopt(curl_m_handle, CURLMOPT_TIMERFUNCTION, on_timer_callback);
curl_easy_init();
curl_easy_setopt(curl_e_handle, CURLOPT_WRITEDATA, (void *)file);
curl_easy_setopt(curl_e_handle, CURLOPT_URL, url);
curl_multi_add_handle(curl_m_handle, curl_e_handle);
curl_multi_socket_action(curl_m_handle, CURL_SOCKET_TIMEOUT, 0, &pending_handles);

This is what I understood according to the docs:

"6. Call curl_multi_socket_action(..., CURL_SOCKET_TIMEOUT, 0, ...) to kickstart everything. To get one or more callbacks called. "

What if I decide to add a new easy handle (do another transfer) after kick starting everything will the new transfer be initiated automatically or do I need to call call curl_multi_socket_action(..., CURL_SOCKET_TIMEOUT, 0, ...) again. I really don't see how I can call curl_multi_socket_action since I don't have the socketfd for that easy_handle until socket_callback…

BTW I assume "easy handle" == transfer or can an "easy handle" represent multiple active transfers? (if so how would I distinguish among them in curl_multi_info_read())
 
>You will find out that libcurl can very well use more than one socket per
>transfer, so you most probably get several created and several removed before
>the transfer is complete.

In what scenario/protocol?

>So you either check the counter the curl_multi_socket_action() returns or you call curl_multi_info_read()
>to figure out if something completed.

Hmm.. Just to make sure.

According to the docs

"At return, the integer running_handles points to will contain the number of running easy handles within the multi handle. When this number reaches zero, all transfers are complete/done"

If I understand you correctly, what you're saying is that "running_handles" actually amounts to the total number of "sockets" associated with *this* transfer (e.g the "overall sockets transfer" associated with the socketfd that was passed to curl_multi_socket_action() before it retuned)

>Quite simply: the timeout is necessary for when libcurl needs to act without
>any detected socket acitivity. Like when someone cuts off your internet
>connection somewhere in the middle and no more socket activities happen.

So the timeout is on receiving/sending bytes? Like libcurl expects to get 100 bytes within 10ms. If they don't arrive within that time it aborts the transfer (regardless of any particular socket state).

>No you shouldn't. If libcurl determines that the timeout isn't necessary
>anymore (like after socket activity), it will call the timer callback and say
>so.

How does it say so? Didn't see any parameter for that ..

>If a transfer is done, successful or not, libcurl will tell you to CURL_POLL_REMOVE it.

But CURL_POLL_REMOVE is only per socketfd isn't it? I mean as you pointed out transfer can be associated with several sockets. I might need to wait for several CURL_POLL_REMOVE and test if the entire transfer completed by calling curl_multi_info_read() after each CURL_POLL_REMOVE …

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2016-01-22