Home > Mobile >  Libcurl - CURLMOPT_TIMERFUNCTION - what is it for?
Libcurl - CURLMOPT_TIMERFUNCTION - what is it for?

Time:12-24

Tell me please, i just can't figure out what the CURLMOPT_TIMERFUNCTION parameter is used for.

Yes, of course I read the entire description about CURLMOPT_TIMERFUNCTION:

CURLMOPT_TIMERFUNCTION

timer_callback

hiperfifo

And I still don't understand what he does and why he is wanted. For example:

Certain features, such as timeouts and retries, require you to call libcurl even when there is no activity on the file descriptors.

Your callback function timer_callback should install a non-repeating timer with an expire time of timeout_ms milliseconds. When that timer fires, call either curl_multi_socket_action or curl_multi_perform, depending on which interface you use.

I don't understand why I should call curl_multi_socket_action() from the CURLMOPT_TIMERFUNCTION callback and not from the event callback?

CodePudding user response:

This is for curl to take action when requests were not answered in time. You need to call curl back periodically so it does its own internal housekeeping.

Imagine you made a request to curl and curl took action on it but could not connect at that time. Curl cannot hang the process waiting for the connect so it returns the control to you and relies on you returning the control back to curl for checking if it can connect periodically.

  • Related