cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: a curl_multi_fdset() replacement? (TODO-RELEASE #55)

From: Jamie Lokier <jamie_at_shareable.org>
Date: Wed, 9 Feb 2005 20:35:51 +0000

Daniel Stenberg wrote:
> On Wed, 2 Feb 2005, Jamie Lokier wrote:
>
> >A simple multi-socket app's main loop looks like:
> >
> > void * fdset = curl_fdset_init();
> > if (fdset == NULL)
> > report_error (...);
> > curl_multi_init(args, fdset, curl_fdset_modify);
> > while(still_things_to_do) {
> > curl_multi_perform(args); /* do stuff and update fds */
> > curl_fdset_wait(); /* wait on 10000 connections */
> > }
> > curl_fdset_destroy (fdset);
> >
> >As you can see, this is nice and simple.
>
> >An app which uses a different event loop, e.g. Gnome's, will use
> >alternatives to those curl_fdset_* functions.
>
> This letting libcurl do the waiting is bit hard to accept for me.

Those curl_fdset_* functions are just convenience functions for an app
author who wants to use the multi interface without writing any
select() code.

They're just convenience - you can simply not provide them and require
all apps using the multi interface to call select() themselves.

> What about applications that want to wait for actions on one or more of
> their own file descriptors? You say they will use alternatives, but how
> would they do that?

This is how the app will wait without libcurl doing the waiting:

     curl_multi_init(args, app_callback_arg, app_callback);
     while(still_things_to_do) {
       curl_multi_perform(args); /* do stuff and update fds */
       set_things_up();
       select(); /* or poll() or other(). */
       tell_curl_about_ready_things();
     }

If the app is using the select() system call, then set_things_up() and
tell_curl_about_ready_things() will update and read fd_sets. If it's
using poll(), theyll update and read an array of pollfds. Etc.

If the app wants to additionally wait on its own file descriptors, it
simply adds those to the fd_sets or pollfds in its own code.

However, if you do opt to provide the curl_fdset_* convenience
functions, then the app can use those to wait for its own file
descriptors instead, by registering callbacks using curl_fdset_modify,
which might be convenient for simple apps that don't need to wait for
anything other than file descriptors.

-- Jamie
Received on 2005-02-09