[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: question on select & FD_ISSET



> -----Original Message-----
> From: seb@highlab.com
> Sent: Thu, 15 Mar 2007 10:31:07 -0600
> To: ejr@inbox.com
> Subject: Re: question on select & FD_ISSET
> 
> Junior <ejr@inbox.com> wrote:
>> Hi all,
>> When I do an FD_ISSET, does it clear that fd bit in the set or it leaves
>> =
>> it as it is (set or not)?
>> If it leaves it then I'll have to do an FD_CLR and an FD_SET the next
>> time =
>> around, correct? (if it is set)
>> 
>> It would seem the FD_ISSET would/should take care of this, no?
> 
> The fdsets that you pass in to select are modified by select so that only
> the fds that need attention are set.  FD_ISSET only tests the specified
> fd, it does not modify the fdset.
> 
> The usual way to use select is in a loop.  At the top you set all the
> fds in your fdsets, call select, the check which ones are still set
> using FD_ISSET(), then go back up to the top.

True, but it seems to me that if I FD_SET them at the top of the loop without FD_CLR first, I will be expanding the set unnecessarily which would waste memory (eventually run out).
Since FD_SET adds the set and FD_CLR clears it from the list, FD_SET without FD_CLR would duplicate fds in the set. Not so?

--Jr.

 
> See the select_tut(2) man page for examples.
> 
> See W. Richard Stevens' "Advanced Programming in the Unix Environment"
> for a detailed description of what's happening.
> 
> 
> --
> Sebastian Kuzminsky
> The universal acid of the true knowledge had burned away a world of
> words,
> and exposed a universe of things.  Things we could use.  -- Ken MacLeod

____________________________________________________________
FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!
Check it out at http://www.inbox.com/marineaquarium



Reply to: