public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Robert Hancock <hancockr@shaw.ca>
To: "linux-os (Dick Johnson)" <linux-os@analogic.com>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: Linux poll() <sigh> again
Date: Thu, 11 May 2006 18:08:04 -0600	[thread overview]
Message-ID: <4463D1E4.5070605@shaw.ca> (raw)
In-Reply-To: <6bkl7-56Y-11@gated-at.bofh.it>

linux-os (Dick Johnson) wrote:
> The bug relates to Linux implementation of poll()
> on a connected socket. If poll() is set to detect
> changes on a connected socket, with an infinite
> timeout (-1), and the client disconnects, it returns
> with a positive value (correct). The returned
> events (revents member), shows only POLLIN bit
> set. This, according to all known documentation
> including man pages on the web, is supposed to
> mean that there are data to be read. In fact,
> there are no data and a read will return 0.

According to the Single UNIX Specification:

http://www.opengroup.org/onlinepubs/007908799/xsh/poll.html

POLLIN means "Data other than high-priority data may be read without 
blocking. For STREAMS, this flag is set in revents even if the message 
is of zero length." The way I read it, all this is telling you is that a 
read on that file descriptor will not block at that particular moment. 
It doesn't mean there is actually any data to be read. On a device like 
a socket, read returning 0 tells you that the connection's been closed.

POLLHUP means "The device has been disconnected." This would obviously 
be appropriate for a device such as a serial line or TTY, etc. but for a 
socket it is less obvious that this return value is appropriate.

> 
> I have used the subsequent read() with a returned
> value of zero, to indicate that the client disconnected
> (as a work around). However, on recent versions of
> Linux, this is not reliable and the read() may
> wait forever instead of immediately returning.

If you want nonblocking behavior, you should set the socket to 
nonblocking. This is a bit strange though, unless the data was stolen by 
another thread or something. Are you sure you've seen this?

-- 
Robert Hancock      Saskatoon, SK, Canada
To email, remove "nospam" from hancockr@nospamshaw.ca
Home Page: http://www.roberthancock.com/


       reply	other threads:[~2006-05-12  0:09 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <6bkl7-56Y-11@gated-at.bofh.it>
2006-05-12  0:08 ` Robert Hancock [this message]
2006-05-12 11:53   ` Linux poll() <sigh> again linux-os (Dick Johnson)
2006-05-12 14:32     ` Robert Hancock
2006-05-12 14:46       ` jimmy
2006-05-12 14:57         ` linux-os (Dick Johnson)
2006-05-12 15:06           ` Eric Dumazet
2006-05-12 15:12           ` Davide Libenzi
2006-05-12 18:49         ` David Schwartz
2006-05-11 14:25 linux-os (Dick Johnson)
2006-05-11 20:47 ` Nishanth Aravamudan
2006-05-11 21:04   ` linux-os (Dick Johnson)
2006-05-11 21:16     ` Nishanth Aravamudan
2006-05-12 11:42       ` linux-os (Dick Johnson)
2006-05-12 10:37     ` Jan Engelhardt
2006-05-12  5:26 ` David Schwartz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4463D1E4.5070605@shaw.ca \
    --to=hancockr@shaw.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-os@analogic.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox