cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: working on a new API

From: Ben Greear <greearb_at_candelatech.com>
Date: Mon, 29 Oct 2001 16:10:38 -0700

Daniel Stenberg wrote:
>
> On Mon, 29 Oct 2001, Ben Greear wrote:
>
> > > Thinking about it, I'm not sure it is possible/portable to merge one fd_set
> > > with another one. The functions FD_SET, FD_CLR and FD_ISSET all operate on
> > > single FDs on the fd_set type. We might need to use plain FDs to make it work
> > > everywhere.
> >
> > The method call I use for things like this looks like:
> >
> > /** Updates the file descriptors which need to be selected on
> > * for this endpoint.
> > */
> > virtual void updateFdset(fd_set & input_set, fd_set & output_set,
> > fd_set & exc_set, int& max_desc, uint64& now);
>
> Right! This has the only minor drawback that you must call this function
> first and then set your own FDs to the fd_sets, and you can't combine two
> independent curl_select handles into one single select(). Not that I can
> think of any possible situation when anyone would wanna do that! ;-)

No, you can set your own FDs at any time (the updateFdset will not
clear/modify any but it's own FDs).

You combine two handles by doing this:

while (1) {
  //Clear FDs, max_desc = 0;
  ....
  curl_update_fdset(curl1, input_set, output_set, exc_set, max_desc);
  curl_update_fdset(curl2, input_set, output_set, exc_set, max_desc);
  ...
  // Set my own FDs
  // If fd > max_desc then max_desc = fd

  select(...)

  ....
  curl_handle_io(curl1, input_set ...)
  ....

}

>
> > Later I will ask this class if it needs to read/write, and if so, I'll
> > pass in the fd_sets and that class can check to see if any of the FD's
> > it's interested in are set in the fd_sets.
> >
> > NOTES: There are exactly 3 fd_sets and one select loop in the entire
> > program, they are just passed around by reference where needed.
>
> Just curious, what's the 'now' for in this context?

I end up wanting to know the current time very often, so I just pass it
around to save a few system calls. now is used in rate-limiting calculations
for the most part, and is not really necessary for the CURL API....

Ben

-- 
Ben Greear <greearb_at_candelatech.com>       <Ben_Greear AT excite.com>
President of Candela Technologies Inc      http://www.candelatech.com
ScryMUD:  http://scry.wanfear.com     http://scry.wanfear.com/~greear
Received on 2001-10-30