Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Nov 1999 06:37:12 +0300
From:      Seva "Semenov" <seva@mtelecom.ru>
To:        freebsd-hackers@FreeBSD.ORG
Subject:   fifo's select in 3.3 RELEASE
Message-ID:  <383222DF.164E86DB@mtelecom.ru>

next in thread | raw e-mail | index | archive | help
FreeBSD 3.3 and 3.2 RELEASE.

fifo has nothing to read,
why select(2) return > 0 without timeout?

in freeBSD 2.2.X select(2) return 0
(timeout) as expected.


# mkfifo fifo
# cat readfifo.c

#include <fcntl.h>
#include <err.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

int
main()
{
        int fd;
        fprintf(stderr,"opening fifo\n");
        if((fd=open("fifo",O_RDONLY|O_NONBLOCK))<0)
                err(errno,"can't open fifo");
        fprintf(stderr,"fifo opend\n");
        for(;;){
                fd_set fds;
                int r;
                struct timeval tv;
                size_t s;
                char b[64];

                tv.tv_sec=5;
                tv.tv_usec=0;
                FD_ZERO(&fds);
                FD_SET(fd,&fds);
                r=select(FD_SETSIZE,&fds,NULL,NULL,&tv);
                if(r<0)
                        err(errno,"select return %d ",r);
                if(r==0){
                        perror("timeout");
                        continue;
                }
                fprintf(stderr,"start reading\n");
                s=read(fd,b,63);
                if(s<0)
                        err(errno,"read fifo return %d",s);
                if(!s){
                        perror("read null bites");
                        continue;
                }
                puts(b);
        }
}




To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?383222DF.164E86DB>