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

Re: [PATCH v9 10/14] pkt-line: add functions to read/write flush terminated packet streams

From
Lars Schneider <larsxschneider@gmail.com>
Date
Oct 5, 2016, 17:35 UTC
Message-ID
<40D4374E-3784-4AF8-B9F3-E0C117A05631@gmail.com>
In-Reply-To
<xmqq8tu3ubzl.fsf@gitster.mtv.corp.google.com>
Show 31 quoted lines
> On 04 Oct 2016, at 21:53, Junio C Hamano <gitster@pobox.com> wrote:
> 
> larsxschneider@gmail.com writes:
> 
>> From: Lars Schneider <larsxschneider@gmail.com>
>> 
> 
>> +int write_packetized_from_buf(const char *src_in, size_t len, int fd_out)
>> +{
>> +	static char buf[LARGE_PACKET_DATA_MAX];
>> +	int err = 0;
>> +	size_t bytes_written = 0;
>> +	size_t bytes_to_write;
>> +
>> +	while (!err) {
>> +		if ((len - bytes_written) > sizeof(buf))
>> +			bytes_to_write = sizeof(buf);
>> +		else
>> +			bytes_to_write = len - bytes_written;
>> +		if (bytes_to_write == 0)
>> +			break;
>> +		err = packet_write_gently(fd_out, src_in + bytes_written, bytes_to_write);
>> +		bytes_written += bytes_to_write;
>> +	}
>> +	if (!err)
>> +		err = packet_flush_gently(fd_out);
>> +	return err;
>> +}
> 
> Hmph, what is buf[] used for, other than its sizeof() taken to yield
> a constant LARGE_PACKET_DATA_MAX?
Agreed. This is stupid. I will fix it.
Show 9 quoted lines
>> 
>> +	for (;;) {
>> +		strbuf_grow(sb_out, LARGE_PACKET_DATA_MAX);
>> +		packet_len = packet_read(fd_in, NULL, NULL,
>> +			// TODO: explain + 1
> 
> No // C99 comment please.
> 
> And I agree that the +1 needs to be explained.
Oh. I did not send the very latest version :-(
Is this explanation OK?
+       strbuf_grow(sb_out, LARGE_PACKET_DATA_MAX);
+       packet_len = packet_read(fd_in, NULL, NULL,
+           /* strbuf_grow() above always allocates one extra byte to
+            * store a '\0' at the end of the string. packet_read()
+            * writes a '\0' extra byte at the end, too. Let it know
+            * that there is already room for the extra byte.
+            */
+           sb_out->buf + sb_out->len, LARGE_PACKET_DATA_MAX+1,
+           PACKET_READ_GENTLE_ON_EOF);

Thanks, Lars

Previous: Junio C HamanoNext: larsxschneider@gmail.com
Message 13 of 28 in “Git filter protocol”
  1. 00/14 Git filter protocollarsxschneider@gmail.com, Oct 4, 2016
  2. 02/14 convert: modernize testslarsxschneider@gmail.com, Oct 4, 2016
  3. 06/14 pkt-line: extract set_packet_header()larsxschneider@gmail.com, Oct 4, 2016
  4. 07/14 pkt-line: add packet_write_fmt_gently()larsxschneider@gmail.com, Oct 4, 2016
  5. 09/14 pkt-line: add packet_write_gently()larsxschneider@gmail.com, Oct 4, 2016
  6. Junio C HamanoOct 4, 2016
  7. Lars SchneiderOct 5, 2016
  8. Junio C HamanoOct 6, 2016
  9. 11/14 convert: make apply_filter() adhere to standard Git error handlinglarsxschneider@gmail.com, Oct 4, 2016
  10. 10/14 pkt-line: add functions to read/write flush terminated packet streamslarsxschneider@gmail.com, Oct 4, 2016
  11. Junio C HamanoOct 4, 2016
  12. Junio C HamanoOct 4, 2016
  13. Lars SchneiderOct 5, 2016
  14. 12/14 convert: prepare filter.<driver>.process optionlarsxschneider@gmail.com, Oct 4, 2016
  15. 13/14 convert: add filter.<driver>.process optionlarsxschneider@gmail.com, Oct 4, 2016
  16. 01/14 convert: quote filter names in error messageslarsxschneider@gmail.com, Oct 4, 2016
  17. 08/14 pkt-line: add packet_flush_gently()larsxschneider@gmail.com, Oct 4, 2016
  18. 14/14 contrib/long-running-filter: add long running filter examplelarsxschneider@gmail.com, Oct 4, 2016
  19. 04/14 run-command: add wait_on_exitlarsxschneider@gmail.com, Oct 4, 2016
  20. Junio C HamanoOct 4, 2016
  21. Lars SchneiderOct 5, 2016
  22. Junio C HamanoOct 5, 2016
  23. Johannes SchindelinOct 6, 2016
  24. Lars SchneiderOct 6, 2016
  25. Junio C HamanoOct 6, 2016
  26. 03/14 run-command: move check_pipe() from write_or_die to run_commandlarsxschneider@gmail.com, Oct 4, 2016
  27. 05/14 pkt-line: rename packet_write() to packet_write_fmt()larsxschneider@gmail.com, Oct 4, 2016
  28. Jakub NarębskiOct 5, 2016

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.