Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: select on pipe blocked



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: http://lists.apple.com/mailman/options/darwin-kernel/email@hidden

This email sent to email@hidden
References: 
 >select on pipe blocked (From: Hervé Kergourlay <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.