git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/8] xread_nonblock: add functionality to read from fds without blocking

From
Jeff King <peff@peff.net>
Date
Dec 15, 2015, 01:44 UTC
Message-ID
<20151215014456.GA28768@sigill.intra.peff.net>
In-Reply-To
<CAGZ79kbLHNtxcwhZz=tHpJB2XnxMeuEJBG=PmoAbcVF4Wzno2g@mail.gmail.com>
On Mon, Dec 14, 2015 at 04:25:18PM -0800, Stefan Beller wrote:
Show 10 quoted lines
> > But yeah, I think simply using xread() as-is in strbuf_read_once (or
> > whatever it ends up being called) is OK.
> 
> I was actually thinking about using {without-x}read, just the plain system call.
> Do we have any issues with that for wrapping purposes for Windows?
> There is no technical reason to prefer xread over read in strbuf_read_once as
> * we are not nonblocking (so the EAGAIN|| EWOULDBLOCK doesn't apply)
> * we don't care about EINTR and retrying upon that signal
> * we would not care about MAX_IO_SIZE most likely (that's actually one
> of the reasons I could technically think of to prefer xread)

I think you do still need to care about EINTR, or at least not barfing if read() returns -1. If I understand correctly, you want to do something like:

  while (1) {
	poll(some_fds);
	for (i = 0; i < nr_fds; i++) {
		if (some_fds[i].revents & POLLIN) {
			int r = strbuf_read_once(buf[i], some_fds[i]);
			/* ??? what do we do with r? */
		}
	}
  }

If we get EINTR from that read, it's OK for us to loop back to the poll() and go again.

But if we get a true error in "r", we'd want to know, right? That means we must distinguish between EINTR and "real" errors (like EIO or something). We can do that here, but I think it's just as easy to do it inside of strbuf_read_once (by calling xread() there). It's OK not to jump back to the poll(), because we know the data that triggered the POLLIN is still waiting for us to read it.

And we are fine with EAGAIN, too. We don't expect the sockets to be non-blocking in the first place, but even if they were, we know we just got POLLIN, so there should be data waiting.

-Peff
Previous: Stefan BellerNext: Johannes Sixt
Message 17 of 30 in “Rerolling sb/submodule-parallel-fetch for the time after 2.7”
  1. 0/8 Rerolling sb/submodule-parallel-fetch for the time after 2.7Stefan Beller, Dec 14, 2015
  2. 1/8 submodule.c: write "Fetching submodule <foo>" to stderrStefan Beller, Dec 14, 2015
  3. 2/8 xread: poll on non blocking fdsStefan Beller, Dec 14, 2015
  4. Eric SunshineDec 14, 2015
  5. Stefan BellerDec 14, 2015
  6. Junio C HamanoDec 14, 2015
  7. Stefan BellerDec 14, 2015
  8. 3/8 xread_nonblock: add functionality to read from fds without blockingStefan Beller, Dec 14, 2015
  9. Junio C HamanoDec 14, 2015
  10. Eric SunshineDec 14, 2015
  11. Eric SunshineDec 14, 2015
  12. Junio C HamanoDec 14, 2015
  13. Jeff KingDec 14, 2015
  14. Stefan BellerDec 15, 2015
  15. Jeff KingDec 15, 2015
  16. Stefan BellerDec 15, 2015
  17. Jeff KingDec 15, 2015
  18. Johannes SixtDec 15, 2015
  19. Junio C HamanoDec 15, 2015
  20. 4/8 strbuf: add strbuf_read_once to read without blockingStefan Beller, Dec 14, 2015
  21. Eric SunshineDec 14, 2015
  22. Stefan BellerDec 14, 2015
  23. 5/8 sigchain: add command to pop all common signalsStefan Beller, Dec 14, 2015
  24. 6/8 run-command: add an asynchronous parallel child processorStefan Beller, Dec 14, 2015
  25. Johannes SixtDec 14, 2015
  26. Stefan BellerDec 14, 2015
  27. 7/8 fetch_populated_submodules: use new parallel job processingStefan Beller, Dec 14, 2015
  28. 8/8 submodules: allow parallel fetching, add tests and documentationStefan Beller, Dec 14, 2015
  29. Johannes SixtDec 14, 2015
  30. Junio C HamanoDec 14, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.