From owner-freebsd-hackers Thu Jul 8 13:11:51 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from lamb.sas.com (lamb.sas.com [192.35.83.8]) by hub.freebsd.org (Postfix) with ESMTP id 7367A152FD for ; Thu, 8 Jul 1999 13:11:24 -0700 (PDT) (envelope-from jwd@unx.sas.com) Received: from mozart (mozart.unx.sas.com [192.58.184.8]) by lamb.sas.com (8.9.3/8.9.1) with SMTP id QAA25395 for ; Thu, 8 Jul 1999 16:11:21 -0400 (EDT) Received: from bb01f39.unx.sas.com by mozart (5.65c/SAS/Domains/5-6-90) id AA21248; Thu, 8 Jul 1999 16:10:51 -0400 Received: (from jwd@localhost) by bb01f39.unx.sas.com (8.9.1/8.9.1) id QAA06869 for freebsd-hackers@freebsd.org; Thu, 8 Jul 1999 16:10:51 -0400 (EDT) (envelope-from jwd) From: "John W. DeBoskey" Message-Id: <199907082010.QAA06869@bb01f39.unx.sas.com> Subject: Strange select/poll behaviour [EBADF inconsistancy] To: freebsd-hackers@freebsd.org Date: Thu, 8 Jul 1999 16:10:51 -0400 (EDT) X-Mailer: ELM [version 2.4ME+ PL43 (25)] Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Hi, The following program returns an inconsistant rc/errno value. Setting a bit corresponding to filedescriptor which is not open is only found when it is less than 20. ie: Some example output follows along with the program. This is being run on a -current system. If I open a file on fd 1023 then I receive EBADF all the way through which is what I expect. Our product depends on this behaviour (no, don't ask)... The man page specfies: 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've seen that select seems to call poll, but I haven't trace all the way through poll yet. Any comments, critiques, or stupid user pointers are appreciated. Thanks! John [ 3] : Bad file descriptor [ 4] : Bad file descriptor [ 5] : Bad file descriptor [ 6] : Bad file descriptor [ 7] : Bad file descriptor [ 8] : Bad file descriptor [ 9] : Bad file descriptor [ 10] : Bad file descriptor [ 11] : Bad file descriptor [ 12] : Bad file descriptor [ 13] : Bad file descriptor [ 14] : Bad file descriptor [ 15] : Bad file descriptor [ 16] : Bad file descriptor [ 17] : Bad file descriptor [ 18] : Bad file descriptor [ 19] : Bad file descriptor [ 20] Timeout [ 21] Timeout [ 22] Timeout [ 23] Timeout [ 24] Timeout [ 25] Timeout #include #include #include #include #include #include static struct timeval nowait_s = {0, 0}; /* poll, no wait */ static struct timeval wait_s = {0, 100}; /* poll, wait 1 sec*/ fd_set local_rfd; fd_set local_wfd; main() { int n; struct timeval *tp; int max_fd = -1; int count; int bytes; int wait_time; int i; char * p; char buffer[256]; fprintf(stderr,"FD_SETSIZE = %d\n",FD_SETSIZE); for(i=3;i<40;++i) close(i); for(i=3;i<40;i++) { bzero(&local_rfd,sizeof(local_rfd)); bzero(&local_wfd,sizeof(local_wfd)); FD_SET(i,&local_rfd); tp = &wait_s; n = select (200,&local_rfd, 0, 0, tp); if (n < 0 ) { sprintf(buffer,"[%5d] ",i); perror(buffer); continue; } if (n == 0 ) { printf("[%5d] Timeout\n",i); } if (n > 0) { if ( FD_ISSET(0, &local_rfd) ) { printf("[ 0] READ\n"); } if ( FD_ISSET(i, &local_rfd) ) { printf("[%5d] READ\n",i); } } } } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message