From owner-freebsd-hackers Fri Jul 6 6:56:59 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from mail1.mx.voyager.net (mail1.mx.voyager.net [216.93.66.200]) by hub.freebsd.org (Postfix) with ESMTP id 1787537B401 for ; Fri, 6 Jul 2001 06:56:55 -0700 (PDT) (envelope-from mhagerty@voyager.net) Received: from thunderbird.voyager.net (216-93-124-123.mdmmi.voyager.net [216.93.124.123]) by mail1.mx.voyager.net (8.10.2/8.10.2) with ESMTP id f66Dutm15529 for ; Fri, 6 Jul 2001 09:56:55 -0400 (EDT) Message-Id: <5.0.2.1.2.20010706095736.0233de30@pop.voyager.net> X-Sender: mhagerty@pop.voyager.net X-Mailer: QUALCOMM Windows Eudora Version 5.0.2 Date: Fri, 06 Jul 2001 09:58:00 -0400 To: freebsd-hackers@FreeBSD.ORG From: Matthew Hagerty Subject: Proper use of select() parameter nfds? Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Greetings, 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. Thanks, Matthew To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message