[lsb-discuss] help needed regarding select API

Nayyar Azam nayyar.ce at gmail.com
Wed Jun 14 03:52:14 PDT 2006


Hello ,

I am right now implementing test case for "select" API, and I have right now
come across a very typical problem. Might be I am knowing less about
select..or so..

My problem is that I have created two files as follows...

system("touch tmp1;echo absjkhsk>tmp1;chmod 400 tmp1");
system("touch tmp2;echo jhagsakjg>tmp2;chmod 200 tmp2");

Now I opened the files as follows..

fd1=open("tmp1",O_RDONLY);
fd2=open("tmp2",O_WRONLY);

Now I added both the  file descriptors in "rfds" and "wfds" (Basically
defined as "fd_set rfds,wfds; ") as follows...

FD_SET(fd1,&rfds);
n=n>fd1?n:fd1;
FD_SET(fd2,&wfds);
n=n>fd2?n:fd2;
FD_SET(fd1,&wfds);
n=n>fd1?n:fd1;
FD_SET(fd2,&rfds);
n=n>fd2?n:fd2;

Where n is an integer.
Now I call the select function as follows.....

retval=select(n+1,&rfds,&wfds,NULL,NULL);

Now to my surprise fd_set "rfds" contain both fd1 and fd2 being
set.(Moreover I can't write on to fd1 using "write" ..after select returns
!!!)
and fd_set "wfds" too contain both of the descriptors. Iam really surprised
at results. FD_ISSET is reporting +ve value for both the fds in both the
fd_sets. How this can be possible...Is this a bug in select ..or I am wrong
somewhere???


Thanks & Regards
Nayyar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.linux-foundation.org/pipermail/lsb-discuss/attachments/20060614/ba28689f/attachment.htm 


More information about the lsb-discuss mailing list