cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Mac OS X and poll()

From: Daniel Johnson <daniel_at_daniel-johnson.org>
Date: Fri, 09 Feb 2007 14:40:11 -0500

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Feb 9, 2007, at 12:09 PM, Jamie Lokier wrote:

> Daniel Stenberg wrote:
>>> I've been using curl 7.16.1 modified to use poll() instead of
>>> select() on
>>> Mac OS X for the last week. I haven't been able to trigger any
>>> problems
>>> with it and all tests pass. My research indicates two things:
>>> poll doesn't
>>> work when called on anything in /dev (actually a limitation of
>>> kqueue(),
>>> which is used internally by poll), and the bug discussed at
>>> http://curl.haxx.se/mail/lib-2005-05/0122.html seems to be fixed
>>> as of Mac
>>> OS X 10.4.4 (Darwin 8.4.0).
>>
>> Nice. Can you come up with a way to detect a "good" Mac OS X
>> version in
>> which we should use poll() instead of select() ? To have the
>> configure
>> script do right automatically.
>
> As far as I can tell, the bug discussed at
> http://curl.haxx.se/mail/lib-2005-05/0122.html
> is that POLLHUP is set without setting POLLIN.
> (The whole thread isn't too clear on what the bug is).

Yeah, that appears to be the issue. As of darwin 8.4.0, it sets
POLLIN|POLLHUP. I've confirmed this by looking at the kernel source
code. All versions of 10.4 set POLLHUP, but 10.4.4 and later also set
POLLIN.

>
> That's not unique to Mac OS X. According to the table at
> http://www.greenend.org.uk/rjk/2001/06/poll.html
> some other systems set POLLHUP without POLLIN sometimes.

That's an interesting page. I ran his test program and got this:

Darwin mentalis.local 8.9.1 Darwin Kernel Version 8.9.1: Tue Jan 23
23:00:25 PST 2007; root:xnu-792.18.12~1/RELEASE_I386 i386 i386
pipe: POLLIN|POLLHUP
socketpair: POLLIN|POLLHUP
SHUT_WR socketpair: POLLIN|POLLHUP
SHUT_RD socketpair: POLLIN|POLLHUP
regular: POLLIN

>
> If that's right, it makes sense to either: (a) add an autoconf test
> which creates a TCP socket pair, shutdown(SHUT_WR) one end, and polls
> the other end to see if POLLIN is set or just POLLHUP; or (b) change
> libcurl to treat POLLHUP as being equivalent to POLLIN.
>

Either of these should work on any version of 10.4. (b) would be the
safest choice since curl built this way would work on any version.

> The other Mac OS X poll() bug is that the emulation in 10.3 requires a
> non-NULL poll table argument, but you're already testing for that. Of
> course it would be easy enough to just use a non-NULL poll table
> argument in libcurl, but no point as it's calling select() anyway.
>
> Are there any other Mac OS X poll() bugs?

Other than the aforementioned brokenness on anything in /dev, I'm not
aware of anything.

Daniel

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (Darwin)
Comment: http://homepage.mac.com/danielj7/publickey.txt

iD8DBQFFzM4b4sDFGYouOqARAkURAJ4luNZHJy9S5q6uwPvR/Sce/NUXXwCfeQhe
bUT72l4BL6Q6whOQOmAzKM8=
=etki
-----END PGP SIGNATURE-----
Received on 2007-02-09