cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: multi API q

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Wed, 28 Nov 2001 09:19:46 +0100 (MET)

On Tue, 27 Nov 2001, Ben Greear wrote:

> Ahh, ok. I think I was a bit confused. So, in this API the main-loop
> (and FD-SETs) are in the user's code?

They are, yes.

> If not, how does the app know when it *can* write (it needs to have
> access to an fd_set and select() somehow.)

Please check the example application code again:
http://curl.haxx.se/dev/multi-app.c

The application does the select() and calls the library whenever it feels it
is appropriate. It could do it after a select()/poll(), or it could do it
unconditionally every now and then.

> > But, you do address one question of mine. So you think completed handles
> > should be removed from the multi collection, to get added again if you want
> > to make more transfers?
>
> Yes. They should be returned to the app through a callback so the app
> can make the appropriate decision. Otherwise I think you'll be leaking
> file descriptors very easily!

You're still into callbacks I see. :-)

I have a different way of solving this issue, and I can't see how this is
going to leak file descriptors:

curl_multi_perform() returns the amount of handles that still have transfers
going on (with the approach that completed handles are removed, the handles
don't only have transfers going on, it also specifies the amount of handles
still being kept in the multi handle). It means that we can easily detect
when one or more transfers have been completed.

To get more information about exactly which handles that are done, the
application will need to ask libcurl (as opposed to get called by a
callback). This ask-for-status system is done with curl_multi_info_open()
first, and then repeated calls to curl_multi_info_read() to get information.
When the application has read the info it cares about (or emptied the info
queue) it calls curl_multi_info_close().

(Optionally, we skip the info_open and info_close functions and have only one
curl_multi_info_read() read function.)

One of the messages that this can return is "HANDLE COMPLETE" which informs
that the specific handle has been removed from the multi handle. It would
also include the return code for that particular transfer, which allows the
application to know if specific transfers did good or bad.

If you don't care about reading the info messages, you can just keep on
calling curl_multi_perform() until it says there are no transfers left in
progress, as we then know that all handles have been removed from the multi
stack.

-- 
    Daniel Stenberg -- curl groks URLs -- http://curl.haxx.se/
Received on 2001-11-28