Skip site navigation (1) Skip section navigation (2)

Re: Proper use of select() parameter nfds?

From: Matthew Hagerty <mhagerty(at)voyager(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Proper use of select() parameter nfds?
Date: 2001-07-06 14:18:50
Message-ID: (view raw, whole thread or download thread mbox)
Lists: 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.


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
> > 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
>Reason being: kernel has to know how large is the mask passed to it, and
>how far does it need to look.

In response to


pgsql-hackers by date

Next:From: Tom LaneDate: 2001-07-06 14:20:48
Subject: Re: AW: AW: Re: Backup and Recovery
Previous:From: Peter EisentrautDate: 2001-07-06 14:17:04
Subject: Re: Database Users Management and Privileges

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group