On Sun, Dec 06, 2009 at 11:03:20PM +0100, Daniel Mack wrote:
> After I painfully found out that poll() is still not working on 10.5.8
> (sic!), I need to emulate this call with select(). In order to find out
> whether a file descriptor was hung up, I wanted to use recv() with
> MSG_PEEK. Even though I found postings that claim MSG_PEEK works well on
> OS X, the following minimal sniplet does block forever in the last
> read() call. Tried that on both ppc and i386, but couldn't test 10.6 yet.
> Needless to say, on Linux, it works just as expected.
>
> Can anyone tell how to get out of this?
Nevermind, I hacked my way around that using a 0-length recv() in
combination with the FIONREAD ioctl().
Really folks, this is very embarrassing. Is Apple actually _working_ on
such incompatibilites? I almost find as much dirty workaround for OS X
in the project I'm working on than for Windows.
The actual root problem is that poll() will foolishly ignore the timeout
argument given, causing it to return immediately which makes the
embedding code call it again right away - which leads to 100% CPU load.
This is a breakage of POSIX:2001 standards, btw. *sigh*
Daniel
> #include <unistd.h>
> #include <sys/socket.h>
> #include <sys/types.h>
> #include <sys/uio.h>
>
> int main(void)
> {
> int fds[2], ret;
> char x;
>
> pipe(fds);
> printf("fd[0] %d\n", fds[0]);
> printf("fd[1] %d\n", fds[1]);
>
> printf("writing ...\n");
> ret = write(fds[1], &x, 1);
> printf("ret = %d\n", ret);
>
> printf("peeking ...\n");
> ret = recv(fds[0], &x, 1, MSG_PEEK);
> printf("ret = %d\n", ret);
>
> printf("reading ...\n");
> ret = read(fds[0], &x, 1);
> printf("ret = %d\n", ret);
>
> return 0;
> }
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-userlevel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden