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

Re: [PATCH] stream_to_pack: xread does not guarantee to read all requested bytes

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 20, 2013, 18:27 UTC
Message-ID
<xmqq8uzw6wuw.fsf@gitster.dls.corp.google.com>
In-Reply-To
<CALWbr2yaQaCte6+Y3GEa8Hxyhq6GPS64aTNzkGo8pdpcd9ZVUg@mail.gmail.com>
Antoine Pelisse <apelisse@gmail.com> writes:
> I was actually wondering when it's better to use xread() over
> read_in_full()?

When the caller wants to do more control over a read that may have to loop. For example, this loop in builtin/index-pack.c::fill()

	do {
		ssize_t ret = xread(input_fd, input_buffer + input_len,
				sizeof(input_buffer) - input_len);
		if (ret <= 0) {
			if (!ret)
				die(_("early EOF"));
			die_errno(_("read error on input"));
		}
		input_len += ret;
		if (from_stdin)
			display_throughput(progress, consumed_bytes + input_len);
	} while (input_len < min);

cannot be replaced blindly with read_in_full() because (1) the caller wants to do the "display_throughput()" part in the loop, and (2) the caller wants to fill at least "min" bytes but can happily accept to read more up to the size of the input_buffer.

Previous: Antoine PelisseNext: Johannes Sixt
Message 4 of 8 in “stream_to_pack: xread does not guarantee to read all requested bytes”
  1. stream_to_pack: xread does not guarantee to read all requested bytesJohannes Sixt, Aug 20, 2013
  2. Junio C HamanoAug 20, 2013
  3. Antoine PelisseAug 20, 2013
  4. Junio C HamanoAug 20, 2013
  5. Johannes SixtAug 20, 2013
  6. Johannes SixtAug 20, 2013
  7. Junio C HamanoAug 20, 2013
  8. Johannes SixtAug 20, 2013

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.