cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: [curl] curl_multi_fdvec (#38)

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Fri, 24 Aug 2012 22:04:04 +0200 (CEST)

On Mon, 16 Jul 2012, Sara Golemon wrote:

(I'd like to take this discussion to the libcurl mailing list, so this
response is sent to that list as well as github)

Sorry for the massive delay in my response.

> Here's an alternative to curl_multi_select() which addresses your desire for
> being able to add arbitrary file descriptors. Workflow here is:
>
> long read_fds, write_fds;
>
> curl_multi_getinfo(multi, CURLMINFO_NUM_READ_FDS, &read_fds);
> curl_multi_getinfo(multi, CURLMINFO_NUM_WRITE_FDS, &write_fds);
>
> int *rfds = calloc(read_fds, sizeof(int));
> int *wfds = calloc(write_fds, sizeof(int));
>
> curl_multi_fdvec(multi, rfds, wfds, NULL);
>
> Then the caller can put into fd_set or struct pollfd as desired, allocating
> extra space for external fds if desired.

I like the general spirit of this. The first curl_multi_select() suggestion
from you had the drawback that it couldn't wait for application-specific
descriptors and this can.

When I saw the first curl_multi_select() version
(https://github.com/bagder/curl/pull/36), I wanted to see a version of the
function that would allow all applications (that want to) to switch to this
new function instead of using curl_multi_fdset() + select(). The only way to
allow applications to do that is to allow custome file descriptors.

This said, the API explained above is pretty awkward and complicated. I would
prefer something more straigh-forward and poll-like.

What about this?

    int curl_multi_wait(CURLM *multi_handle,
                        struct curl_waitfd fds[],
                        int nfds,
                        int timeout_ms);

This is meant to be very similar to poll() although it uses a curl-specific
struct.

A downside with this API is the amount of copying that needs to be done
between the custom struct and the "real" underlying polldfd struct - or select
provided internals - and back again after the real underlying function has
returned.

This function would return some info about the stuff it waits for, like poll()
does.

Any other particular reasons why it can't be made like this?

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2012-08-24