cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Detecting request completion with asynchronous interface

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Mon, 9 Mar 2009 16:31:30 +0100 (CET)

On Mon, 9 Mar 2009, bp wrote:

>> The primary hint: the 'running_handles' counter decreases.

> Using that counter seemed unreliable since maybe it could have been both
> decremented and incremented since the last time checked, so perhaps always
> calling curl_multi_info_read() would be better.

Right, used that way I think the curl_multi_info_read() is most reliable. It
is a fast function anyway (in all cases).

> Or maybe create many multi handles that each service one easy request ... I
> was previously planning to keep one multi handle around forever.

It is probably better with the single multi handle as then you'll gain from
connection re-use which the multiple multi handles approach won't.

> It sounds like we need to check for completion anywhere a running_handles is
> returned:
> 1) After adding an easy handle and called curl_multi_socket_all().

You shouldn't (need to) use curl_multi_socket_all() at all actually (unless
you use an old libcurl but then you'll also be likely to suffer from various
already fixed bugs). Just make sure you have a timer callback set
(CURLMOPT_TIMERFUNCTION), and then always use curl_multi_socket_action() when
there's activity.

> 2) After detecting socket activity and called curl_multi_socket_action()
> with some fd.
> 3) After detecting a timeout and called curl_multi_socket_action() with
> CURL_SOCKET_TIMEOUT.
>
> Does this cover all possible completions?

I think you can simplify by simply always call curl_multi_info_read()
immediately after the curl_multi_socket_action() calls, no matter if the call
was due to fd activity or timeout.

-- 
  / daniel.haxx.se
Received on 2009-03-09