From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Johannes Sixt <j6t@kdbg.org>, Stefan Beller <sbeller@google.com>,
"git@vger.kernel.org" <git@vger.kernel.org>,
Ramsay Jones <ramsay@ramsayjones.plus.com>,
Jacob Keller <jacob.keller@gmail.com>,
Jonathan Nieder <jrnieder@gmail.com>,
Johannes Schindelin <johannes.schindelin@gmail.com>,
Jens Lehmann <Jens.Lehmann@web.de>,
Eric Sunshine <ericsunshine@gmail.com>
Subject: Re: [PATCHv3 02/11] run-command: report failure for degraded output just once
Date: Thu, 5 Nov 2015 01:51:11 -0500 [thread overview]
Message-ID: <20151105065111.GA4725@sigill.intra.peff.net> (raw)
In-Reply-To: <xmqqvb9h8ale.fsf@gitster.mtv.corp.google.com>
On Wed, Nov 04, 2015 at 06:05:17PM -0800, Junio C Hamano wrote:
> I've always assumed that the original reason why we wanted to set
> the fd to nonblock was because poll(2) only tells us there is
> something to read (even a single byte), and the xread_nonblock()
> call strbuf_read_once() makes with the default size of 8KB is
> allowed to consume all available bytes and then get stuck waiting
> for the remainder of 8KB before returning.
>
> If the read(2) in xread_nonblock() always returns as soon as we
> receive as much as there is data available without waiting for any
> more, ignoring the size of the buffer (rather, taking the size of
> the buffer only as the upper bound), then there is no need for
> nonblock anywhere.
This latter paragraph was my impression of how pipe reading generally
worked, for blocking or non-blocking. That is, if there is data, both
cases return what we have (up to the length specified by the user), and
it is only when there is _no_ data that we might choose to block.
It's easy to verify experimentally. E.g.:
perl -e 'while(1) { syswrite(STDOUT, "a", 1); sleep(1); }' |
strace perl -e 'while(1) { sysread(STDIN, my $buf, 1024) }'
should show a series of 1-byte reads. But of course that only shows that
it works on my system[1], not everywhere.
POSIX implies it is the case in the definition of read[2] in two ways:
1. The O_NONBLOCK behavior for pipes is mentioned only when dealing
with empty pipes.
2. Later, it says:
The value returned may be less than nbyte if the number of bytes
left in the file is less than nbyte, if the read() request was
interrupted by a signal, or if the file is a pipe or FIFO or
special file and has fewer than nbyte bytes immediately available
for reading.
That is not explicit, but the "immediately" there seems to imply
it.
> So perhaps the original reasoning of doing nonblock was faulty, you
> are saying?
Exactly. And therefore a convenient way to deal with the portability
issue is to get rid of it. :)
-Peff
next prev parent reply other threads:[~2015-11-05 6:52 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-04 0:37 [PATCHv3 00/11] Expose the submodule parallelism to the user Stefan Beller
2015-11-04 0:37 ` [PATCHv3 01/11] run_processes_parallel: delimit intermixed task output Stefan Beller
2015-11-04 0:37 ` [PATCHv3 02/11] run-command: report failure for degraded output just once Stefan Beller
2015-11-04 18:14 ` Junio C Hamano
2015-11-04 20:14 ` Stefan Beller
2015-11-04 20:36 ` Johannes Sixt
2015-11-04 21:01 ` Junio C Hamano
2015-11-04 22:56 ` Jeff King
2015-11-05 2:05 ` Junio C Hamano
2015-11-05 6:51 ` Jeff King [this message]
2015-11-05 7:32 ` Junio C Hamano
2015-11-05 17:37 ` Stefan Beller
2015-11-04 20:42 ` Junio C Hamano
2015-11-04 21:04 ` Stefan Beller
2015-11-04 21:19 ` Junio C Hamano
2015-11-04 21:41 ` Stefan Beller
2015-11-04 0:37 ` [PATCHv3 03/11] run-command: omit setting file descriptors to non blocking in Windows Stefan Beller
2015-11-04 0:37 ` [PATCHv3 04/11] submodule-config: keep update strategy around Stefan Beller
2015-11-04 0:37 ` [PATCHv3 05/11] submodule-config: drop check against NULL Stefan Beller
2015-11-04 0:37 ` [PATCHv3 06/11] submodule-config: remove name_and_item_from_var Stefan Beller
2015-11-04 0:37 ` [PATCHv3 07/11] submodule-config: introduce parse_generic_submodule_config Stefan Beller
2015-11-04 0:37 ` [PATCHv3 08/11] fetching submodules: respect `submodule.jobs` config option Stefan Beller
2015-11-10 22:21 ` Jens Lehmann
2015-11-10 22:29 ` Stefan Beller
2015-11-11 19:55 ` Jens Lehmann
2015-11-11 23:34 ` Stefan Beller
2015-11-13 20:47 ` Jens Lehmann
2015-11-13 21:29 ` Stefan Beller
2015-11-04 0:37 ` [PATCHv3 09/11] git submodule update: have a dedicated helper for cloning Stefan Beller
2015-11-04 0:37 ` [PATCHv3 10/11] submodule update: expose parallelism to the user Stefan Beller
2015-11-04 0:37 ` [PATCHv3 11/11] clone: allow an explicit argument for parallel submodule clones Stefan Beller
2015-11-04 17:54 ` [PATCHv3 00/11] Expose the submodule parallelism to the user Junio C Hamano
2015-11-04 18:08 ` Stefan Beller
2015-11-04 18:17 ` Junio C Hamano
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=20151105065111.GA4725@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=Jens.Lehmann@web.de \
--cc=ericsunshine@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j6t@kdbg.org \
--cc=jacob.keller@gmail.com \
--cc=johannes.schindelin@gmail.com \
--cc=jrnieder@gmail.com \
--cc=ramsay@ramsayjones.plus.com \
--cc=sbeller@google.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;
as well as URLs for NNTP newsgroup(s).