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

Proper use of select() parameter nfds?

From: Matthew Hagerty <mhagerty(at)voyager(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Proper use of select() parameter nfds?
Date: 2001-07-06 05:23:06
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers

I am going over the use of select() for a server I'm writing and I 
*thought* I understood the man page's description for the use of the first 
parameter, nfds.

 From MAN:

The first nfds descriptors are checked in each set; i.e., the descriptors 
from 0 through nfds-1 in the descriptor sets are examined.

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 
descriptor you want checked.  Here is the select() from the questionable 
code (I can provide the whole function if necessary, it's not very big):

if (select(conn->sock + 1, &input_mask, &output_mask, &except_mask,
     (struct timeval *) NULL) < 0)

Is this improper use?  conn->sock is set like this:

/* Open a socket */
if ((conn->sock = socket(family, SOCK_STREAM, 0)) < 0)

Any clarification on how nfds should be set would be greatly appreciated.



pgsql-hackers by date

Next:From: Zeugswetter Andreas SBDate: 2001-07-06 08:22:24
Subject: AW: Re: Backup and Recovery
Previous:From: Nathan MyersDate: 2001-07-06 02:54:43
Subject: Re: Re: Backup and Recovery

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