I have been experiencing several problem with the poll module, especially under MacOS X.
I was about to submit a patch for poll to fix some of these issues, but I prefer yours much more if it works. In fact, the FIONREAD ioctl is a hack and my patch added yet another hack instead of using the trick of having a length of zero.
The module make the following assumption (quoting from the source): "An hung up descriptor does not increase the return value".
The original code did not have this assumption, and in fact I had to write my code around this behavior of gnulib's poll, when I ported GNU Smalltalk to Mac OS X.
I don't remember if it was Paul or Bruno who suggested that POLLHUP does not increase the return value. What do you think? If this was a previous mistake, I think that we should apply Yoann's patch, though with some cosmetic (coding standards) fixes.
Paolo