Re: [PATCH v5] libtracefs: Add APIs for data streaming

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 28 Jun 2021 11:58:10 +0300
Yordan Karadzhov <y.karadz@xxxxxxxxx> 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)
			break;
		r = ret;
		ret = write(out_fd, buf, r);
		if (ret < 0)
			break;
		bread += ret;
		/* Stop if we can't write what was read */
		if (ret < r)
			break;
	}


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



[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux