login
Login
/
Register
Search
Search this site:
Forums
News
Blogs
Features
Site
Home
»
Mailing list archives
»
linux-kernel
»
2010
»
August
»
26
Re: [PATCH] tcp: select(writefds) don't hang up when a peer close connection
view
thread
Previous message: [
thread
] [
date
] [
author
]
Next message: [
thread
] [
date
] [
author
]
[view in full thread]
From: KOSAKI Motohiro
Subject:
Re: [PATCH] tcp: select(writefds) don't hang up when a peer close connection
Date: Wednesday, August 25, 2010 - 8:55 pm
> On Wed, 2010-08-25 at 15:34 -0700, David Miller wrote:
quoted text
> > From: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> > > Date: Wed, 25 Aug 2010 11:05:48 +0900 (JST) > > > > > This issue come from ruby language community. Below test program > > > hang up when only run on Linux. > > > > > > % uname -mrsv > > > Linux 2.6.26-2-486 #1 Sat Dec 26 08:37:39 UTC 2009 i686 > > > % ruby -rsocket -ve ' > > > BasicSocket.do_not_reverse_lookup = true > > > serv = TCPServer.open("127.0.0.1", 0) > > > s1 = TCPSocket.open("127.0.0.1", serv.addr[1]) > > > s2 = serv.accept > > > s2.close > > > s1.write("a") rescue p $! > > > s1.write("a") rescue p $! > > > Thread.new { > > > s1.write("a") > > > }.join' > > > ruby 1.9.3dev (2010-07-06 trunk 28554) [i686-linux] > > > #<Errno::EPIPE: Broken pipe> > > > [Hang Here] > [...] > > And in this case here, I call into question the behavior of Ruby and > > the application from two perspectives: > > > > 1) Unlike all of the other conditions signalled by poll() this is > > one the application explicitly created and therefore knows about. > > > > If the application calls close() or shutdown() with the send flag > > set, IT KNOWS what is going to happen on a write() attempt. > [...] > > This example seems to have both server (serv, s2) and client (s1) in the > same process for simplicity. The server socket (s2) is closed and the > client cannot be expected to know that. Of course the client ought to > drop the connection after the first EPIPE, but it's reasonable to expect > that this is a sticky condition just as it would be for a pipe. > > Here's a similar test case in C: > > #include <assert.h> > #include <signal.h> > #include <stdio.h> > > #include <sys/select.h> > #include <sys/socket.h> > #include <sys/types.h> > #include <unistd.h> > > int main(void) > { > struct sockaddr sa; > struct timeval tv; > int serv, s1, s2; > socklen_t len; > fd_set fds; > > signal(SIGPIPE, SIG_IGN); > > serv = socket(AF_INET, SOCK_STREAM, 0); > assert(serv >= 0); > assert(!listen(serv, 1)); > len = sizeof(sa); > assert(!getsockname(serv, &sa, &len)); > > s1 = socket(AF_INET, SOCK_STREAM, 0); > assert(s1 >= 0); > assert(!connect(s1, &sa, len)); > len = sizeof(sa); > > s2 = accept(serv, &sa, &len); > assert(s2 >= 0); > close(s2); > > for (;;) { > printf("write: %d\n", write(s1, "a", 1)); > FD_ZERO(&fds); > FD_SET(s1, &fds); > tv.tv_sec = 1; > tv.tv_usec = 0; > printf("select: %d\n", select(s1 + 1, NULL, &fds, NULL, &tv)); > } > return 0; > }
Cool! Ben, I think your code is cleaner than mine. If you allow me, I hope to include this one into my patch description. Thanks. --
unsubscribe notice
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to
majordomo@vger.kernel.org
More majordomo info at
http://vger.kernel.org/majordomo-info.html
Please read the FAQ at
http://www.tux.org/lkml/
Previous message: [
thread
] [
date
] [
author
]
Next message: [
thread
] [
date
] [
author
]
Messages in current thread:
[PATCH] tcp: select(writefds) don't hang up when a peer cl ...
, KOSAKI Motohiro
, (Tue Aug 24, 7:05 pm)
Re: [PATCH] tcp: select(writefds) don't hang up when a pee ...
, David Miller
, (Wed Aug 25, 3:34 pm)
Re: [PATCH] tcp: select(writefds) don't hang up when a pee ...
, Ben Hutchings
, (Wed Aug 25, 6:24 pm)
Re: [PATCH] tcp: select(writefds) don't hang up when a pee ...
, KOSAKI Motohiro
, (Wed Aug 25, 8:09 pm)
Re: [PATCH] tcp: select(writefds) don't hang up when a pee ...
, David Miller
, (Wed Aug 25, 8:51 pm)
Re: [PATCH] tcp: select(writefds) don't hang up when a pee ...
, KOSAKI Motohiro
, (Wed Aug 25, 8:55 pm)
Re: [PATCH] tcp: select(writefds) don't hang up when a pee ...
, KOSAKI Motohiro
, (Wed Aug 25, 9:02 pm)
Re: [PATCH] tcp: select(writefds) don't hang up when a pee ...
, Ben Hutchings
, (Thu Aug 26, 5:07 am)
Re: [PATCH] tcp: select(writefds) don't hang up when a pee ...
, David Miller
, (Thu Aug 26, 12:21 pm)
Re: [PATCH] tcp: select(writefds) don't hang up when a pee ...
, KOSAKI Motohiro
, (Sun Aug 29, 6:08 pm)
Navigation
Create content
Mailing list archives
Recent posts
Popular discussions
linux-kernel
:
Brandeburg, Jesse
RE: [regression] e1000e broke e1000 (was: Re: [ANNOUNCE] e1000 toe1000e migration ...
Robin Lee Powell
NFS hang + umount -f: better behaviour requested.
Linus Torvalds
Linux 2.6.34-rc4
Nick Piggin
Re: dealing with barriers (was Re: [PATCH] firewire: fw-core: enforce write order ...
Joe Perches
Re: [patch] checkpatch: putting the && or || on the wrong line
git
:
Fredrik Kuivinen
Re: fatal: unable to create '.git/index': File exists
Johannes Sixt
Re: How to pull remote branch with specified commit id?
Henrik Vendelbo
only accessing some git repos: Am I configuring daemon wrong?
Johannes Schindelin
Re: git and mtime
Martin Langhoff
Re: CVS -> SVN -> Git
linux-netdev
:
Jamie Lokier
Re: POHMELFS high performance network filesystem. Transactions, failover, performa...
Paulius Zaleckas
Re: [RFC] Patch to option HSO driver to the kernel
Timo Teräs
ip xfrm policy semantics
Ron Mercer
[net-next PATCH 2/2] qlge: Version change to v1.00.00.27
Maciej W. Rozycki
Re: [PATCH] flush_work_sync vs. flush_scheduled_work Re: [PATCH] PHYLIB: IRQ event...
openbsd-misc
:
Sevan / Venture37
Re: This is what Linus Torvalds calls openBSD crowd
Siju George
This is what Linus Torvalds calls openBSD crowd
new_guy
Longest Uptime?
Skylar Hawk
Re: asus eee 1201n - acpitz0 critical temperature 255C (5282K), shutting down
Nick Guenther
Re: Forum engine
git-commits-head
:
Linux Kernel Mailing List
powerpc/fsl_msi: enable msi allocation in all banks
Linux Kernel Mailing List
[ARM] mmp: avengers lite (pxa168) board bring up
Linux Kernel Mailing List
swiotlb: replace architecture-specific swiotlb.h with linux/swiotlb.h
Linux Kernel Mailing List
drivers/acpi: use kasprintf
Linux Kernel Mailing List
V4L/DVB (10925): add support for LG Electronics LGDT3305 ATSC/QAM-B Demodulator
Colocation donated by:
Syndicate