From: Jeff King <peff@peff.net>
To: "Torsten Bögershausen" <tboegi@web.de>
Cc: Stefan Beller <sbeller@google.com>,
"git@vger.kernel.org" <git@vger.kernel.org>,
Junio C Hamano <gitster@pobox.com>,
Jonathan Nieder <jrnieder@gmail.com>,
Johannes Schindelin <johannes.schindelin@gmail.com>,
Jens Lehmann <Jens.Lehmann@web.de>,
Eric Sunshine <ericsunshine@gmail.com>,
Johannes Sixt <j6t@kdbg.org>
Subject: Re: [PATCHv2 2/7] xread: poll on non blocking fds
Date: Fri, 18 Dec 2015 13:12:33 -0500 [thread overview]
Message-ID: <20151218181233.GA29057@sigill.intra.peff.net> (raw)
In-Reply-To: <5673C8E6.8010001@web.de>
On Fri, Dec 18, 2015 at 09:50:46AM +0100, Torsten Bögershausen wrote:
> >> So the code would look like this:
> >>
> >> if (!poll(&pfd, 1, -1))
> >> return -1;
> >
> > That changes the semantics of the function. The poll() is just a
> > convenience to avoid spinning. If it fails, with Stefan's patch[1] the
> > worst case is that we would spin on read() and poll(), instead of
> > actually blocking in the poll().
> >
> > But if we return on poll() failure, now the caller will see errors from
> > poll() even though they don't know or care that we called poll() in the
> > first place. Consider what would happen with your code if read got
> > EAGAIN and then poll got EINTR. We would report an error, even though
> > the whole point of xread() is to loop on these conditions.
> [...]
>
> /* So the code v2 would look like this: */
>
> if (!poll(&pfd, 1, -1)) {
> if (errno == EINTR)
> continue;
> return -1; /* poll() failed, this is serious. */
> }
That solves the EINTR problem, but I still don't see why we want to
return -1. The caller asked us to read(). We know that read() did not
fail with an actual error. Yet we are going to return an error to the
user, with errno set to something related only to poll(). I think we are
better off to keep the same semantics from the caller's point of view:
we loop until read() returns forward progress or a real error, and
anything else we do is a behind-the-scenes optimization.
BTW, I am assuming you mean:
if (poll(&pfd, 1, -1) < 0)
...
in your examples. Returning "0" means that poll timed out, but of course
we are not providing a timeout.
-Peff
next prev parent reply other threads:[~2015-12-18 18:12 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-16 0:04 [PATCHv2 0/7] Rerolling sb/submodule-parallel-fetch for the time after 2.7 Stefan Beller
2015-12-16 0:04 ` [PATCHv2 1/7] submodule.c: write "Fetching submodule <foo>" to stderr Stefan Beller
2015-12-16 0:04 ` [PATCHv2 2/7] xread: poll on non blocking fds Stefan Beller
2015-12-17 20:12 ` Torsten Bögershausen
2015-12-17 20:22 ` Stefan Beller
2015-12-17 20:42 ` Torsten Bögershausen
2015-12-17 20:51 ` Stefan Beller
2015-12-18 3:14 ` Jeff King
2015-12-18 3:13 ` Jeff King
2015-12-18 8:50 ` Torsten Bögershausen
2015-12-18 18:12 ` Jeff King [this message]
2015-12-18 3:07 ` Jeff King
2015-12-16 0:04 ` [PATCHv2 3/7] strbuf: add strbuf_read_once to read without blocking Stefan Beller
2015-12-16 0:04 ` [PATCHv2 4/7] sigchain: add command to pop all common signals Stefan Beller
2015-12-16 0:04 ` [PATCHv2 5/7] run-command: add an asynchronous parallel child processor Stefan Beller
2015-12-16 0:04 ` [PATCHv2 6/7] fetch_populated_submodules: use new parallel job processing Stefan Beller
2015-12-16 0:04 ` [PATCHv2 7/7] submodules: allow parallel fetching, add tests and documentation Stefan Beller
2015-12-16 0:19 ` [PATCHv2 0/7] Rerolling sb/submodule-parallel-fetch for the time after 2.7 Stefan Beller
2015-12-16 20:20 ` 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=20151218181233.GA29057@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=johannes.schindelin@gmail.com \
--cc=jrnieder@gmail.com \
--cc=sbeller@google.com \
--cc=tboegi@web.de \
/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).