Date: Thu, 8 Jul 1999 16:10:51 -0400 (EDT) From: "John W. DeBoskey" <jwd@unx.sas.com> To: freebsd-hackers@freebsd.org Subject: Strange select/poll behaviour [EBADF inconsistancy] Message-ID: <199907082010.QAA06869@bb01f39.unx.sas.com>
index | next in thread | raw e-mail
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 <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/time.h>
#include <sys/stat.h>
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
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199907082010.QAA06869>
