git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Torsten Bögershausen" <tboegi@web.de>
To: Stefan Beller <sbeller@google.com>
Cc: tboegi@web.de, j6t@kdbg.org, gitster@pobox.com,
	git@vger.kernel.org, johannes.schindelin@gmx.de
Subject: Re: [PATCH 1/2] run-parallel: rename set_nonblocking to set_nonblocking_or_die
Date: Thu, 5 Nov 2015 07:07:37 +0100	[thread overview]
Message-ID: <563AF229.1060302@web.de> (raw)
In-Reply-To: <1446677029-10745-2-git-send-email-sbeller@google.com>

On 11/04/2015 11:43 PM, Stefan Beller wrote:
> Discussion turned out a warning is not enough, but we need to die in case
> of blocking output as we can lockup the child processes.
>
> Junio wrote:
>> Imagine that we are running two things A and B at the same time.  We
>> ask poll(2) and it says both A and B have some data ready to be
>> read, and we try to read from A.  strbuf_read_once() would try to
>> read up to 8K, relying on the fact that you earlier set the IO to be
>> nonblock.
(Jumping into an old discussion, I may be off topic)

When we want to make really sure, not to get stucked, we can do like this:

ssize_t xread_nonblock(int fd, void *buf, size_t len)
{
     ssize_t nr;
     if (len > MAX_IO_SIZE)
         len = MAX_IO_SIZE;
     nr = read(fd, buf, len);
     if (nr < 0) {
        if (errno == EWOULDBLOCK)
             errno = EAGAIN;
      return nr;
}

Once poll() returns POLLIN as set on a fd, we can safely call read() once 
without getting stucked.
"Data can be read without blocking".

And this work regardless if the fd blocking or not, so from that point of view,
the set_nonblocking() is not needed at all.


The major question is, if the poll() works under Windows, (and I haven't found 
time to dig further)

  reply	other threads:[~2015-11-05  6:07 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-02  2:58 git.git as of tonight Junio C Hamano
2015-11-02 21:15 ` Johannes Sixt
2015-11-02 22:16   ` Junio C Hamano
2015-11-02 23:06   ` Stefan Beller
2015-11-03  6:34     ` Johannes Sixt
2015-11-03 17:05       ` Junio C Hamano
2015-11-03 18:18         ` Stefan Beller
2015-11-03 21:03           ` Johannes Sixt
2015-11-03 23:00             ` Stefan Beller
2015-11-04 19:59               ` O_NONBLOCK under Windows (was: git.git as of tonight) Torsten Bögershausen
2015-11-04 20:07                 ` Stefan Beller
2015-11-04 22:43                 ` [PATCH 0/2] Missing " Stefan Beller
2015-11-04 22:43                   ` [PATCH 1/2] run-parallel: rename set_nonblocking to set_nonblocking_or_die Stefan Beller
2015-11-05  6:07                     ` Torsten Bögershausen [this message]
2015-11-05  6:14                       ` Junio C Hamano
2015-11-05  6:19                         ` Junio C Hamano
2015-11-05  6:58                           ` Jeff King
2015-11-04 22:43                   ` [PATCH 2/2] run-parallel: Run sequential if nonblocking I/O is unavailable Stefan Beller

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=563AF229.1060302@web.de \
    --to=tboegi@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=johannes.schindelin@gmx.de \
    --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).