curl / Mailing Lists / curl-library / Single Mail


Re: Wait for a response using curl_multi_wait

From: Richard Copley <>
Date: Tue, 20 Mar 2018 20:44:22 +0000

On 20 March 2018 at 09:10, Erik Janssen <> wrote:

> Hi,
> > Using the "multi-single.c" example[1] as a testbed, I notice that after
> adding the easy
> > handle and calling curl_multi_perform, the curl_multi_wait call returns
> immediately
> > and sets numfds to 0, indicating there is no fd to wait on.
> What is 'immediately'

It here means "not mediated (by something happening)". A few microseconds
but no data is sent or received.

> and what happens on the wire?

By collating timestamped debug output against wireshark logs
(disclaimer: I'm not sure of all of this, my timestamps weren't accurate
and I don't know the protocol too well):

0.957 Before first curl_multi_perform
SEND: connect request (SYN, TCP length 0)
0.957 After first curl_multi_perform, still_running=1

0.957 Before curl_multi_wait
0.957 After curl_multi_wait, numfds=0

0.957 Before curl_multi_perform
0.957 After curl_multi_perform, still_running=1

0.957 Before curl_multi_wait
0.957 After curl_multi_wait, numfds=0

0.957 Before waiting 100 ms
RECV: connect accept (SYN/ACK, TCP length 0)
SEND: connect confirm (ACK, TCP length 0)
SEND: request (TCP length 54)
1.064 After waiting 100 milliseconds

1.064 Before curl_multi_perform
1.064 After curl_multi_perform, still_running=1

1.064 Before curl_multi_wait
RECV: response data (3 segments) (ACK, length 1598)
SEND: (ACK, TCP length 0)
RECV: (ACK, TCP length 0)
1.166 After curl_multi_wait, numfds=1

1.166 Before curl_multi_perform
SEND: (ACK, TCP length 0)
SEND: (FIN/ACK, TCP length 0)
1.167 After curl_multi_perform, still_running=1

1.167 Before curl_multi_wait
1.267 After curl_multi_wait, numfds=0

1.267 Before curl_multi_perform
1.267 After curl_multi_perform, still_running=1

1.267 Before curl_multi_wait
RECV: (FIN/ACK, TCP length 0)
1.271 After curl_multi_wait, numfds=1

1.271 Before curl_multi_perform
SEND: (ACK, TCP length 0)
1.271 After curl_multi_perform, still_running=0

I checked my own code, I don't
> wait inside such loop and actually use the waiting of curl_multi_wait for
> all my internal
> timing needs.

Well, the way it is done in the example is also how curl_easy_perform works
(with a
more careful choice of timeout).

> I never check numfds either and just proceed to
> curl_multi_perform/curl_multi_info_read.
> This example isn't doing that so you don't see what happens. Maybe the
> data is just there?

I might have misunderstood you. If curl_multi_wait returns with numfds=0,
then there
is no point trying to read the data.

> Disclaimer: maybe my code is flawed an happens to work because I also pass
> some extra_fds.

I don't think that would be a flaw. Passing a "dummy" extra_fd (that will
never be ready)
is mentioned in the documentation as a workaround. I can do that, but I'd
like to better
understand what's happening first.

> Erik


Received on 2018-03-20