bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH]: multiple problem with the poll module


From: Yoann Vandoorselaere
Subject: [PATCH]: multiple problem with the poll module
Date: Mon, 18 Dec 2006 21:39:44 +0100

Hi,

I have been experiencing several problem with the poll module,
especially under MacOS X.

The module make the following assumption (quoting from the source): "An
hung up descriptor does not increase the return value".

- However, POSIX state:
Upon  successful  completion,  poll() shall return a non-negative value.
A positive value indicates the total number of file descriptors that
have been selected (that is, file descriptors for which the revents
member is non-zero). A value of 0 indicates that the call timed  out
and  no  file descriptors have been selected. Upon failure, poll() shall
return -1 and set errno to indicate the error.

- More specifically, the Linux manpage state:
On  success, a positive number is returned; this is the number of
structures which have non-zero revents fields (in other words, those
descriptors with events ***or errors reported***). [...]


The attached patch fix this issue (as well as a bzero() warning, due to
string.h not being included).


There is a second problem where poll() would fail with a non connected
socket (example: server socket polled for incoming connection event).

The attached patch fix this issue in the following way:
- [ALL except OSX]: if recv() return -1 with errno set to ENOTCONN, then
trigger a POLLIN.

- [OSX]: The situation is more complicated since recv() was not used due
to a OSX bug where data would be consumed despite the MSG_PEEK flag
being set. FIONREAD was used in place of the recv() call.

However, FIONREAD does not permit to determine whether the connection
has been closed, or if we are working with a non connected socket (it
will return 0/set available data to 0 in both case). 

Instead of using FIONREAD, I modified the check to use recv() with a 0
length (which is, AFAIK, not portable, but seems to work under OSX).
This doesn't consume any data, but permit to make the distinction
between both case.

If anyone has a better idea on how to fix the above issues, any input is
welcome.

Regards, 

-- 
Yoann Vandoorselaere | Responsable R&D / CTO | PreludeIDS Technologies
Tel: +33 (0)8 70 70 21 58                  Fax: +33(0)4 78 42 21 58
http://www.prelude-ids.com

Attachment: gnulib-poll.diff
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]