[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gnulib] poll(2) emulation doesn't work well on a file descripto
From: |
Bruno Haible |
Subject: |
Re: [bug-gnulib] poll(2) emulation doesn't work well on a file descriptor |
Date: |
Fri, 11 Aug 2006 20:42:44 +0200 |
User-agent: |
KMail/1.9.1 |
Daiki Ueno wrote:
> When I tried a tiny program which uses gnulib's poll(2) emulation on
> MacOS X 10.4, I found a bug. gnulib's poll(2) uses recv(2) with
> MSG_PEEK to support POLLHUP. However, recv(2) is only applicable to a
> socket, not to a file descriptor.
Thanks for reporting this.
> Though I don't know how to fix it, I think it can be by-passed if
> (pfd[i].events & POLLHUP) == 0? Here is the patch
>
> Index: poll.c
> ===================================================================
> RCS file: /sources/gnulib/gnulib/lib/poll.c,v
> retrieving revision 1.4
> diff -u -r1.4 poll.c
> --- poll.c 19 Sep 2005 17:28:14 -0000 1.4
> +++ poll.c 11 Aug 2006 07:32:03 -0000
> @@ -155,7 +155,8 @@
> {
> /* support for POLLHUP. An hung up descriptor does not
> increase the return value! */
> - if (recv (pfd[i].fd, data, 64, MSG_PEEK) == -1)
> + if (pfd[i].events & POLLHUP &&
> + recv (pfd[i].fd, data, 64, MSG_PEEK) == -1)
> {
> if (errno == ESHUTDOWN || errno == ECONNRESET
> || errno == ECONNABORTED || errno == ENETRESET)
This is not right: it tests for POLLHUP in the 'events' bit mask.
POSIX says "This flag is only valid in the revents bitmask; it shall be
ignored in the events member.".
Paolo, is the appended patch ok to commit? (Includes a move from K&R C
to ANSI C. gnulib assumes ANSI C now for a year or two.)
Bruno
*** poll.c 19 Sep 2005 17:28:14 -0000 1.4
--- poll.c 11 Aug 2006 18:44:33 -0000
***************
*** 1,7 ****
/* Emulation for poll(2)
Contributed by Paolo Bonzini.
! Copyright 2001, 2002, 2003 Free Software Foundation, Inc.
This file is part of gnulib.
--- 1,7 ----
/* Emulation for poll(2)
Contributed by Paolo Bonzini.
! Copyright 2001-2003, 2006 Free Software Foundation, Inc.
This file is part of gnulib.
***************
*** 51,60 ****
#endif
int
! poll (pfd, nfd, timeout)
! struct pollfd *pfd;
! nfds_t nfd;
! int timeout;
{
fd_set rfds, wfds, efds;
struct timeval tv, *ptv;
--- 51,57 ----
#endif
int
! poll (struct pollfd *pfd, nfds_t nfd, int timeout)
{
fd_set rfds, wfds, efds;
struct timeval tv, *ptv;
***************
*** 155,161 ****
{
/* support for POLLHUP. An hung up descriptor does not
increase the return value! */
! if (recv (pfd[i].fd, data, 64, MSG_PEEK) == -1)
{
if (errno == ESHUTDOWN || errno == ECONNRESET
|| errno == ECONNABORTED || errno == ENETRESET)
--- 152,159 ----
{
/* support for POLLHUP. An hung up descriptor does not
increase the return value! */
! if (recv (pfd[i].fd, data, 64, MSG_PEEK) == -1
! && errno != ENOTSOCK)
{
if (errno == ESHUTDOWN || errno == ECONNRESET
|| errno == ECONNABORTED || errno == ENETRESET)