From owner-freebsd-current@FreeBSD.ORG Fri Dec 26 14:41:44 2003 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DB77C16A4CE; Fri, 26 Dec 2003 14:41:44 -0800 (PST) Received: from Princeton.EDU (postoffice02.Princeton.EDU [128.112.130.38]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9390543D2F; Fri, 26 Dec 2003 14:41:42 -0800 (PST) (envelope-from yruan@cs.princeton.edu) Received: from smtpserver2.Princeton.EDU (smtpserver2.Princeton.EDU [128.112.129.148]) by Princeton.EDU (8.12.9/8.12.9) with ESMTP id hBQMffKq012329; Fri, 26 Dec 2003 17:41:41 -0500 (EST) Received: from cs.princeton.edu (targe.CS.Princeton.EDU [128.112.139.194]) (authenticated bits=0)hBQMfbUc005069 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NOT); Fri, 26 Dec 2003 17:41:41 -0500 (EST) Message-ID: <3FECB894.54922CA6@cs.princeton.edu> Date: Fri, 26 Dec 2003 17:39:16 -0500 From: Yaoping Ruan X-Mailer: Mozilla 4.76 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 To: hackers@freebsd.org, freebsd-current@freebsd.org Content-Type: text/plain; charset=gb2312 Content-Transfer-Encoding: 7bit X-Mailman-Approved-At: Fri, 26 Dec 2003 18:49:14 -0800 Subject: select() in 5.X X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Dec 2003 22:41:45 -0000 Not sure if somebody here has already noticed this problem before. I have a small program using select() . Though it works correctly on 4.x, some problem happens on 5.1. First of all, I notice that macros about FD_xx have been moved into sys/select.h. Then FD_ZERO() seems to be failed. My program looks like follow: main( ) { ... fd_set rfdset; FD_ZERO(&rfdset); .... } Replace the macro of FD_ZERO with the definition in sys/select.h and then running GDB reveals the following information: (gdb) print rfdset $2 = {__fds_bits = {1874, 635, 0, 0, 1327, 2173, 288, 2299, 0, 1923, 95, 1980, 1844, 1510, 2063, 2327, 1371, 0, 317, 227, 957, 0, 0, 1285, 0, 2339, 1817, 2090, 1460, 341, 2306, 1298}} (gdb) print n $3 = 2047 (gdb) print (&rfdset)->__fds_bits[2047] Cannot access memory at address 0xbfc01644 So the problem is that when rfdset is defined, it only got 32 elements. But when FD_ZERO is executed, the "howmany(...)" function gives out 2048 elements. This function is defined exactly the same in the above two cases, as: ((FD_SETSIZE) + ((NFDBITS) - 1)) / (NFDBITS)) I think there's something I missed. Could someone help this out? Thanks - Yaoping