From: "David Schwartz" <davids@webmaster.com>
To: "Chris Friesen" <cfriesen@nortelnetworks.com>
Cc: "MarKol" <markol4@wp.pl>, <linux-kernel@vger.kernel.org>
Subject: RE: select for UNIX sockets?
Date: Sun, 8 Jun 2003 20:05:52 -0700 [thread overview]
Message-ID: <MDEHLPKNGKAHNMBLJOLKGEHBDIAA.davids@webmaster.com> (raw)
In-Reply-To: <3EE2B878.6050809@nortelnetworks.com>
> David Schwartz wrote:
>
> > Yu are doing something wrong. You are using 'select' along
> > with blocking
> > I/O operations. You can't make bricks without clay. If you don't want to
> > block, you must use non-blocking socket operations. End of story.
> That's funny, I was under the impression that the whole point of
> using select()
> was to enable the use of blocking I/O.
This is a very common misconception. No, the point of 'select' is to hint
to you when you should attempt a non-blocking socket operation. It has never
been the case that 'select' guaranteed that a following blocking operation
wouldn't block.
> If you are on a
> uniprocessor system, in
> a single thread, and select() says that a socket is writeable,
> then I had darn
> well better be able to write to that socket!
No. A 'write' hit from 'select' cannot guarantee that any arbitrary 'write'
won't block unless the following 'write' is non-blocking.
Consider a TCP connection. I get a 'write' hit, and then I call 'write' to
send 250Kb of data. Do you seriously want to argue that the kernel must
somehow handle that 250Kb without blocking?
> Sure, this gets more complicated when multiprocessing or
> multithreading, but the
> test program does neither of these.
No, it's more complicated in many situations. Suppose the kernel says a
connected UDP socket won't block because the network interface the packet
would go out is unused. Before you can call 'send', the interface goes down
and the packet now has to take a congested network interface. The 'write'
will block.
> > Just because 'select' indicates a write hit, you are not
> > assured that some
> > particular write at a later time will not block. Past
> > performance does not
> > guarantee future results.
> Think about the whole reason for select()'s existance. If a
> single-threaded app
> calls select() and is told a socket is writeable, then a write to
> that socket
> should either immediately succeed or immediately fail (if the
> other socket
> disappeared in between the calls, for instance).
Sure, but you can't ensure this in all cases unless you set the socket
non-blocking. The kernel can't guarantee the future and it has no way of
knowing that it's important to the application that the following operation
not block unless yuo tell it.
> Now granted I use non-blocking I/O out of paranoia, but even
> there if select()
> says it is writeable and the send call returns EAGAIN then we get
> into a nice
> little infinite loop.
Only if the application foolishly insists. For UDP, you should treat EAGAIN
as a hint that you're sending too fast. With UDP, the application is
responsible for send timing and can't foist this responsibility on the OS by
misusing 'select'.
> select() should be reliable.
It cannot be made so without other greater losses. The perfect is the enemy
of the good. Use it as a hint.
DS
next prev parent reply other threads:[~2003-06-09 2:52 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-06-06 12:20 MarKol
2003-06-07 0:14 ` David Schwartz
2003-06-08 0:04 ` Krzysztof Halasa
2003-06-09 3:11 ` David Schwartz
2003-06-09 17:18 ` Krzysztof Halasa
2003-06-09 17:55 ` David Schwartz
2003-06-09 22:24 ` Krzysztof Halasa
2003-06-10 13:34 ` Timothy Miller
2003-06-10 13:52 ` Richard B. Johnson
2003-06-10 14:21 ` Krzysztof Halasa
2003-06-10 19:04 ` Jesse Pollard
2003-06-11 21:55 ` Krzysztof Halasa
2003-06-11 22:50 ` David Schwartz
2003-06-11 12:51 ` Edgar Toernig
2003-06-10 21:40 ` David Schwartz
2003-06-11 22:04 ` Krzysztof Halasa
2003-06-09 23:45 ` James Stevenson
2003-06-08 4:15 ` Chris Friesen
2003-06-09 3:05 ` David Schwartz [this message]
2003-06-09 16:46 ` MarKol
2003-06-09 17:05 ` David Schwartz
-- strict thread matches above, loose matches on Subject: below --
2003-06-04 12:19 Petr Vandrovec
2003-06-06 0:28 ` Valdis.Kletnieks
2003-06-06 0:38 ` Petr Vandrovec
2003-06-03 0:08 Krzysztof Halasa
2003-06-03 14:51 ` Alan Cox
2003-06-04 23:27 ` Krzysztof Halasa
2003-06-05 13:17 ` Krzysztof Halasa
2003-06-04 11:55 ` Jesse Pollard
2003-06-04 12:42 ` Krzysztof Halasa
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=MDEHLPKNGKAHNMBLJOLKGEHBDIAA.davids@webmaster.com \
--to=davids@webmaster.com \
--cc=cfriesen@nortelnetworks.com \
--cc=linux-kernel@vger.kernel.org \
--cc=markol4@wp.pl \
/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®