Date: Tue, 31 Jul 2001 16:14:59 -0500 From: Lucas Bergman <lucas@slb.to> To: Gabriel Ambuehl <gabriel_ambuehl@buz.ch> Cc: questions@freebsd.org Subject: Re: select() on a named pipe blocks indefinitely Message-ID: <20010731161459.A38416@comp04.prc.uic.edu> In-Reply-To: <115350818950.20010731212448@buz.ch>; from gabriel_ambuehl@buz.ch on Tue, Jul 31, 2001 at 09:24:48PM %2B0200 References: <115350818950.20010731212448@buz.ch>
next in thread | previous in thread | raw e-mail | index | archive | help
> I've there got a strange problem with select on a named pipe (FIFO):
> If I call select() on it without supplying a timeout, the program
> won't ever return from the select until it's killed...
Regarding your code: Please, in the future, include a small example
like this that *compiles*. It is obnoxious to give something like
this and rely on someone else to add the #include lines, the #define
FIFO_PATH, the main() routine, etc.
In this case, the error was blatant enough that I didn't have to
compile your code.
> {
> char result[512];
> int fifo_des;
> fd_set rset;
> mkfifo(FIFO_PATH, (mode_t) (S_IRUSR | S_IWUSR | S_IWGRP));
> fifo_des=open((const char *) FIFO_PATH, O_RDONLY|O_NONBLOCK);
> FD_ZERO(&rset);
> while(1)
> {
> FD_SET(fifo_des, &rset);
> select(1, &rset, (fd_set *) NULL, (fd_set *) NULL, (struct
> timeval *) NULL);
I think you mean
select(fifo_des + 1, &rset, 0, 0, 0);
Your first argument to select() is wrong; what you have will block
forever even when data are available on fifo_des, provided fifo_des >
0. See select(2) for details.
Lucas
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010731161459.A38416>
