From: Mike Jagdis <jaggy@purplet.demon.co.uk>
To: David Schwartz <davids@webmaster.com>,
Linus Torvalds <torvalds@transmeta.com>,
Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] select() says closed socket readable
Date: Thu, 23 Aug 2001 11:56:03 +0100 [thread overview]
Message-ID: <3B84E143.1030806@purplet.demon.co.uk> (raw)
In-Reply-To: <NOEJJDACGOHCKNCOGFOMAECLDGAA.davids@webmaster.com>
[-- Attachment #1: Type: text/plain, Size: 822 bytes --]
Whoa! It isn't that select/poll is saying that a read wouldn't
block. It's saying that the socket has been hung up (POLLHUP
not POLLIN)! This is even worse - POLLHUP is always tested
for even of the user didn't ask for it. So if an unconnected
socket appears _anywhere_ in a select or poll we are heading
for spin city, regardless of whether we asked for read, write,
errors or even nothing (in the case of poll)!
Older Linux kernels (2.2.18 at least) blocked on unconnected
TCP sockets but returned POLLHUP on unix sockets. Current
kernels return POLLHUP in both cases. It looks like TCP was
fixed to match unix instead of vice-versa.
A quick poll (<grin>) of available machines here show that
both Sun and FreeBSD block for both TCP and unix unconnected
sockets.
The attached patch _should_ be applied :-).
Mike
[-- Attachment #2: poll.diff --]
[-- Type: text/plain, Size: 1113 bytes --]
--- linux.old/net/ipv4/tcp.c Fri Jul 6 13:50:00 2001
+++ linux/net/ipv4/tcp.c Thu Aug 23 11:29:15 2001
@@ -415,11 +415,8 @@
* then we could set it on SND_SHUTDOWN. BTW examples given
* in Stevens' books assume exactly this behaviour, it explains
* why PULLHUP is incompatible with POLLOUT. --ANK
- *
- * NOTE. Check for TCP_CLOSE is added. The goal is to prevent
- * blocking on fresh not-connected or disconnected socket. --ANK
*/
- if (sk->shutdown == SHUTDOWN_MASK || sk->state == TCP_CLOSE)
+ if (sk->shutdown == SHUTDOWN_MASK)
mask |= POLLHUP;
if (sk->shutdown & RCV_SHUTDOWN)
mask |= POLLIN | POLLRDNORM;
--- linux.old/net/unix/af_unix.c Tue Jul 24 21:32:01 2001
+++ linux/net/unix/af_unix.c Thu Aug 23 11:31:58 2001
@@ -1711,8 +1711,8 @@
if (!skb_queue_empty(&sk->receive_queue) || (sk->shutdown&RCV_SHUTDOWN))
mask |= POLLIN | POLLRDNORM;
- /* Connection-based need to check for termination and startup */
- if (sk->type == SOCK_STREAM && sk->state==TCP_CLOSE)
+ /* Connection-based need to check for termination */
+ if (sk->type == SOCK_STREAM)
mask |= POLLHUP;
/*
prev parent reply other threads:[~2001-08-23 10:56 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-08-18 3:28 PROBLEM: " Jay Rogers
2001-08-18 16:27 ` kuznet
2001-08-18 22:52 ` Ton Hospel
2001-08-20 14:34 ` Jay Rogers
2001-08-20 19:48 ` David Schwartz
2001-08-20 15:03 ` David S. Miller
2001-08-20 15:29 ` Udo A. Steinberg
2001-08-21 9:02 ` Mike Jagdis
2001-08-21 17:35 ` David Schwartz
2001-08-21 18:38 ` Alan Cox
2001-08-21 19:01 ` David Schwartz
2001-08-22 9:26 ` Mike Jagdis
2001-08-22 21:40 ` David Schwartz
2001-08-23 10:30 ` Mike Jagdis
2001-08-23 10:56 ` Mike Jagdis [this message]
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=3B84E143.1030806@purplet.demon.co.uk \
--to=jaggy@purplet.demon.co.uk \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=davids@webmaster.com \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@transmeta.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
all inboxes | Powered by JetHome®