archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <>
To: Yordan Karadzhov <>
Cc: ""  <>
Subject: Re: [PATCH v5] libtracefs: Add APIs for data streaming
Date: Mon, 28 Jun 2021 18:06:20 -0400	[thread overview]
Message-ID: <20210628180620.676a3af1@oasis.local.home> (raw)
In-Reply-To: <>

On Mon, 28 Jun 2021 11:58:10 +0300
Yordan Karadzhov <> wrote:

> Nit: When looping you check the value of 'ret' 3 times.
>       The same can be done with only 2 checks.
> 	while (*(volatile bool *)keep_going) {
> 		ret = read(in_fd, buf, BUFSIZ);
> 		if (ret <= 0)
> 			break;
> 		ret = write(out_fd, buf, ret);
> 		if (ret <= 0)
> 			break;
> 		bread += ret;
> 	}

I ended up doing it this way:

	while (*(volatile bool *)keep_going) {
		int r;
		ret = read(in_fd, buf, BUFSIZ);
		if (ret <= 0)
		r = ret;
		ret = write(out_fd, buf, r);
		if (ret < 0)
		bread += ret;
		/* Stop if we can't write what was read */
		if (ret < r)

Because if it can't write the amount that was read, it shouldn't
continue any more. And since the documentation states, it returns what
was transferred, we should only return the amount that was written. Of
course, then we get stuck with a case that the buffer was read, and
lost. But if the write fails to write everything given to it, there's
probably other issues with the system (target ran out of disk space?).
(Hmm, I may state the above in a comment there).

Anyway, I'll be posting the v6 soon.

-- Steve

      parent reply	other threads:[~2021-06-28 22:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-25 18:27 Steven Rostedt
2021-06-28  8:58 ` Yordan Karadzhov
2021-06-28 13:13   ` Steven Rostedt
2021-06-28 13:21     ` Yordan Karadzhov
2021-06-28 22:06   ` Steven Rostedt [this message]

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210628180620.676a3af1@oasis.local.home \ \ \ \
    --subject='Re: [PATCH v5] libtracefs: Add APIs for data streaming' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox