Hi there,
I'm trying to use a select in order to switch between
different input descriptor, but, even if no data is present
in the files, select call always return with all the descriptor
set as ready for read.
Here the sample code running on Linux RedHat 6.0.
#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
main()
{
int iFDa, iFDb, iFDc, iMax;
int iRet;
char c;
char acBuf[80];
fd_set fdsR;
iFDa = open( "./sa", O_RDONLY | O_NDELAY );
iFDb = open( "./sb", O_RDONLY | O_NDELAY );
iMax = iFDc = open( "./sc", O_RDONLY | O_NDELAY );
if ( iMax < iFDa ) iMax = iFDa;
if ( iMax < iFDb ) iMax = iFDb;
FD_ZERO( &fdsR );
FD_SET( iFDa, &fdsR );
FD_SET( iFDb, &fdsR );
FD_SET( iFDc, &fdsR );
while( 1 )
{
iRet = select( iMax + 1, &fdsR, NULL, NULL, NULL );
printf( "Select return %d (%d)- ", iRet, errno );
if ( FD_ISSET( iFDa, &fdsR ) )
{
while( read( iFDa, &c, 1 ) == 1 )
{
printf( "%c", c );
}
printf( "EOF on a\n" );
}
if ( FD_ISSET( iFDb, &fdsR ) )
{
while( read( iFDb, &c, 1 ) == 1 )
{
printf( "%c", c );
}
printf( "EOF on b\n" );
}
if ( FD_ISSET( iFDc, &fdsR ) )
{
while( read( iFDc, &c, 1 ) == 1 )
{
printf( "%c", c );
}
printf( "EOF on c\n" );
}
}
Running this code, select return immediately withQuote:}
value 3 and FD_ISSET is true for all the iFD.
Reading from them will immediately catch an EOF.
Do I mistake something?
Must I include something I don't?
Must I use some special library?
Any help will be appreciated.
Osvaldo
Sent via Deja.com http://www.deja.com/
Before you buy.