public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: linux-kernel@ton.iguana.be (Ton Hospel)
To: linux-kernel@vger.kernel.org
Subject: Re: PROBLEM: select() says closed socket readable
Date: Sat, 18 Aug 2001 22:52:42 +0000 (UTC)	[thread overview]
Message-ID: <9lmrjq$hbr$1@post.home.lunix> (raw)
In-Reply-To: <200108181627.UAA19351@ms2.inr.ac.ru>

In article <200108181627.UAA19351@ms2.inr.ac.ru>,
	kuznet@ms2.inr.ac.ru writes:
> Hello!
>
>> For linux 2.4.2, select() indicates socket ready for read on a
>> socket that's never been connected.
>
> Right. It does not block on read, hence it is readable.
>

mm, that's not really the rule, since e.g. you want to be able to select
on read and write on the write side of a pipe, and would expect to only
get readable on error/close:

But there's weird stuff going on here (examples need perl >= 5.6.0):

perl -wle 'use POSIX; pipe(my $rd, my $wr)||die $!; my $fd = fileno($wr); my $mask=""; vec($mask, $fd, 1)=1; select(my $r=$mask, my $w=$mask, "", undef); print "readable" if vec($r, $fd, 1); print "writable" if vec($w, $fd, 1); my $rc = POSIX::read($fd, my $buf, 4096) || die "read returns $!"; print STDERR $rc'

prints:

writable
read returns Bad file descriptor at -e line 1.

Which is in fact weird, since I still have the $rd descriptor around, so
the read should block (it does on solaris). This seems a bug.

perl -wle 'use POSIX; pipe(my $rd, my $wr)||die $!; close $rd; my $fd = fileno($wr); my $mask=""; vec($mask, $fd, 1)=1; select(my $r=$mask, my $w=$mask, "", undef); print "readable" if vec($r, $fd, 1); print "writable" if vec($w, $fd, 1); my $rc = POSIX::read($fd, my $buf, 4096) || die "read returns $!"; print STDERR $rc'

prints:

readable
writable
read returns Bad file descriptor at -e line 1.

Which is the behaviour you want (the read does not block in either case),
closing the other side causes readability. This allows you to watch a
connection for errors without being bothered by EOF (so it's good, but
contrary to your statement).
However, the reaction on read is still weird. on solaris I get in fact EOF,
not Bad file descriptor

In fact, somewhat related, i last week ran into this:

perl -wle 'use Socket; use POSIX; socketpair(my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC)||die $!; shutdown($rd, 1); shutdown($wr, 0); my $fd = fileno($wr); my $mask=""; vec($mask, $fd, 1)=1; select(my $r=$mask, my $w=$mask, "", undef); print "readable" if vec($r, $fd, 1); print "writable" if vec($w, $fd, 1); my $rc = POSIX::read($fd, my $buf, 4096) || die "read returns $!"; print STDERR $rc'

which prints:

readable
writable
0 but true

(so the read returns EOF). Which is very unfortunate, because it means a
pipe is not equivalent to a socketpair where you make one side only
readable and one only writable (the way it's supposedly implemented on
some OSes) Solaris and freebsd behaves the same as linux by the way.
On the other hand, you *do* want to know if the other side does a
shutdown, so in that sense the behaviour is good.

Damn, i wish this socket stuff would finally get completely standardized.

  reply	other threads:[~2001-08-18 22:53 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-18  3:28 PROBLEM: select() says closed socket readable Jay Rogers
2001-08-18 16:27 ` kuznet
2001-08-18 22:52   ` Ton Hospel [this message]
2001-08-20 14:34   ` Jay Rogers
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               ` [PATCH] " Mike Jagdis
2001-08-20 19:48     ` PROBLEM: " 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='9lmrjq$hbr$1@post.home.lunix' \
    --to=linux-kernel@ton.iguana.be \
    --cc=linux-kernel@vger.kernel.org \
    /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