Re: select on pipe blocked
Re: select on pipe blocked
- Subject: Re: select on pipe blocked
- From: Terry Lambert <email@hidden>
- Date: Mon, 19 Dec 2005 18:48:29 -0800
On Dec 19, 2005, at 9:19 AM, Hervé Kergourlay wrote:
on a clent/server schema with 2 processes, one, the producer is
writing on a pipe, the other read the pipe with recv in an
asynchronous mode so it's calling select() until the data are really
available then is calling recv(). Everything is ok if the producer
send datas.
But the select() API on a pipe handle stays blocked until the
timeout ends if the write process close the socket before sending
all the datas
if I'm using a socket instead of a pipe, the close is detected and
the select return
If I'm calling a blocking recv directly, the close is also detected
This code is a unix standard code which is working on all standard
Unix (linux, sun, hp, sgi, etc ...)
anybody knows about a bug on the select on the close detection on a
pipe ??
thanks
hervé
Works for me:
#include <stdio.h>
#include <stdlib.h>
#include <sys/select.h>
int
main(int ac, char *av[])
{
fd_set reads, excepts;
int n;
int i;
int cnt;
char buf[ 20];
FD_ZERO(&reads);
FD_ZERO(&excepts);
again:
FD_SET(0, &reads);
FD_SET(0, &excepts);
n = select(10, &reads, 0, &excepts, 0);
printf("n is %d\n", n);
if (FD_ISSET(0, &reads)) {
printf("reads\n");
if ((cnt = read(0, buf, 1)) != 1) {
switch(cnt) {
case 0:
printf("EOF!\n");
exit(0);
case -1:
perror("read");
exit(2);
default:
printf("Odd count of %d\n", cnt);
exit(3);
}
}
}
if (FD_ISSET(0, &excepts))
printf("excepts\n");
printf("\n");
goto again;
}
% echo "hello" | ./foo
n is 1
reads
n is 1
reads
n is 1
reads
n is 1
reads
n is 1
reads
n is 1
reads
n is 1
reads
EOF!
-- Terry _______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden