Tony <mts.spb.suxx@mail.ru> wrote:
In the following UNIX code the “fdout_eof” flag never gets set.
What is fdout?
/* Read and buffer any available stdout data from the program. */
if (!fdout_eof && FD_ISSET(fdout, readset))
{
len = read(fdout, buf, sizeof(buf));
if (len <= 0)
fdout_eof = 1;
else
{
buffer_append(&stdout_buffer, buf, len);
fdout_bytes += len;
}
}
Does that mean that select() never marks an empty file as ready for
reading?
My little test program shows that it does.
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/time.h>
#include <sys/select.h>
void main( void )
{
int fd1;
fd_set rfd;
int n;
char buf[1000];
fd1 = open("/tmp/blah1", O_RDONLY );
if( fd1 == -1 )
{
perror( “open” );
exit( EXIT_FAILURE );
}
n = read( fd1, buf, 1000);
printf(“read %d bytes\n”);
/*
- Clear the set of read file descriptors, and
- add the two we just got from the open calls.
*/
FD_ZERO( &rfd );
FD_SET( fd1, &rfd );
switch ( n = select( 1 + fd1,
&rfd, 0, 0, 0 ) ) {
case -1:
perror( “select” );
exit( EXIT_FAILURE );
case 0:
puts( “select timed out” );
break;
default:
printf( “%d descriptors ready …\n”, n );
if( FD_ISSET( fd1, &rfd ) )
puts( " – fd1 descriptor has data pending" );
}
exit( EXIT_SUCCESS );
}
Running this prints:
read 0 bytes
1 descriptors ready …
– fd1 descriptor has data pending
As expected - operating on:
-rw-rw-r-- 1 dagibbs techies 0 Jan 12 15:32 /tmp/blah1
The “else” branch works fine. Surrounding the “len = read…” with “if
(!eof(fdout))” breaks the other logic of the UNIX program, the flag is set
immediatelly.
Is there any QNX4 specific with “select()”?
Oh, probably lots of bits – but I don’t think this is one of them, at
least not for regular files.
What does fdout point to?
-David
David Gibbs
QNX Training Services
dagibbs@qnx.com