Re: Proper use of select() parameter nfds?

Поиск
Список
Период
Сортировка
От Matthew Hagerty
Тема Re: Proper use of select() parameter nfds?
Дата
Msg-id 5.0.2.1.2.20010706100719.02202730@pop.voyager.net
обсуждение исходный текст
Ответ на Proper use of select() parameter nfds?  (Matthew Hagerty <mhagerty@voyager.net>)
Список pgsql-hackers
Well, it proves that it was to late for me when I wrote this.  I apologize, 
this was supposed to go to FreeBSD hackers, not pgHackers.  It does kind of 
relate however, because the code snip-it is from the pgWait function in the 
fe-misc.c file of the pqlib interface.

I appreciate the response.  I had initially understood the correct behavior 
but the man page is a bit confusing.  I suppose digging into the kernel's 
select() would have resolved my suspicions as well, but it is more fun to 
talk to all of you! :)

What erks me about this call is that I have to know what file descriptors 
are and what the largest one I want to use is.  "Technically", for 
in/out/err your are supposed to use defines from a lib supplied with your 
OS, and for other files you make a var of type FILE and assign the return 
result from fopen() (or socket, etc.) to that.  I guess my point is that by 
having to pass a parameter like nfds, it completely removes all abstraction 
and forces me to know something about the kernel internals.  This is not a 
problem for me, but makes for possibly *very* un-portable code.  What if a 
file descriptor is a structure on anther OS?  I read somewhere once that 
the use of 0,1,2 for the in/out/err was something being frowned on since 
that could change one day, but select() is not helping things 
either.  Also, I know of no function that returns the highest file 
descriptor I have open for my process.

Thanks for the clarification.

Matthew



At 09:45 AM 7/6/2001 -0400, Alex Pilosov wrote:
>On Fri, 6 Jul 2001, Matthew Hagerty wrote:
>
> > I take this to mean that each descriptor set contains n descriptors and I
> > am interested in examining the first nfds descriptors referenced in my
> > sets.  I also understood it to mean that nfds has absolutely nothing to do
> > with the actual *value* of a descriptor, i.e. the value returned by
> > fopen(), socket(), etc..  Is this correct thinking?  What got me
> > second-guessing myself was a use of select() that seems to indicate that
> > you have to make sure nfds is larger than the value of the largest
>Correct.
><snip>
>
> > Any clarification on how nfds should be set would be greatly appreciated.
>
>Just like you said:
>"you have to make sure nfds is larger than the value of the largest
>filedescriptor".
>
>
>Reason being: kernel has to know how large is the mask passed to it, and
>how far does it need to look.
>
>-alex



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Gunnar Rønning
Дата:
Сообщение: Re: Database Users Management and Privileges
Следующее
От: Doug McNaught
Дата:
Сообщение: Re: Proper use of select() parameter nfds?