cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: is curl_multi_socket_all() deprecated?

From: Ragnar Lonn <ragnar_at_gatorhole.com>
Date: Thu, 23 Oct 2008 00:07:16 +0200

Daniel Stenberg wrote:
> On Wed, 22 Oct 2008, ragnar_at_gatorhole.com wrote:
>
>> // set socket callback
>> curl_multi_setopt(multi_handle, CURLMOPT_SOCKETFUNCTION,
>> curl_socket_cb);
>
> Allow me to underscore the importance of mr Drexler's comment
> regarding the lack of a timout callback here.
>
> Using the curl_multi_socket() API without the timeout callback set is
> not recommended.
>

Understood, thanks :-)

I may be intellectually challenged, or something, but it is still a bit
unclear to me what actually happens initially. How can I be sure that I
will receive a call to the timeout callback before I have to use the
timeout value in e.g. my epoll_wait() call? Isn't it better to call
curl_multi_timeout() to retrieve the timeout value every time just
before I wait on the sockets?

Also, Josef Drexler wrote that adding an easy handle to a multi handle
will cause "the callbacks to be called" (timeout callback?). I thought
that CURL would only actually do stuff, call callbacks etc. when you
invoked one of its perform-functions?

 From what you tell me it seems what I should do is:

1) create a multi handle
2) set a timeout callback
3) add easy handles, which will cause my timeout callback to get called
(will it?), letting me know what timeout to use
4) immediately call curl_multi_socket_action() with sockfd argument set
to CURL_SOCKET_TIMEOUT (because I don't yet know about any sockets, and
curl has not performed any work yet, which should mean there are no
active sockets, so waiting for nothing seems rather pointless, or...?)
5) enter main loop, properly wait on sockets, using the timeout value,
and call curl_multi_socket_action() when things happen (or when I get a
timeout)

The above would basically mean that the encouraged way to get things
started is to trigger a timeout - call curl_multi_socket_action() with
sockfd set to CURL_SOCKET_TIMEOUT. This is something I never understood
when I read the docs.

Or am I completely out in the blue here? If I get the hang of this I
could perhaps write a code example for the next person who has trouble
with this - an updated hiperfifo.c maybe.

cheers,

  /Ragnar
Received on 2008-10-23