cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Libcurl multi handle

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Fri, 12 Jan 2007 15:51:46 +0100 (CET)

On Fri, 12 Jan 2007, stage.nexvision wrote:

> From a program I'm trying to debug, the behaviour is like this:
> Main thread calls curl_multi_init and store the multi_handle
> Then main thread create 2 threads (A, B)
> A thread receive a request to download a file from an FTP server
> B thread receive a request to list a directory on a FTP server

You're still only using the single multi handle in a single thread, right?

> The read request from Thread A, does something like
> running_handles = 0
> curl_multi_perform(multi_handle, &running_handles)
> while (running_handles)
> {
> curl_multi_fdset(...)
> select(...)
> curl_multi_perform(multi_handle, &running_handles)
> }
>
> Sometimes this loop doesn't exit, even if curl_multi_fdset set maxfd to -1.

If curl_multi_fdset sets maxfd to -1 it doesn't imply that the transfers are
done, just that you can't wait on any socket with select at that moment.

> I was wondering, if running_handles is a good stop condition for the loop.

It is in fact the only properly working stop condition.

> How can I identify the connection's handle for the read from the
> connection's handle from the Thread B ?

Your talk of different threads makes me suspect you abuse the interface.

> I've found the curl_multi_info_read function, but I don't understand how I
> can tell that read started from A is finished, while the read in B isn't.

The struct curl_multi_info_read() returns contains info, and when a easy
handle is complete you get to know which handle in that struct.

-- 
  Commercial curl and libcurl Technical Support: http://haxx.se/curl.html
Received on 2007-01-12