nxplayer: read file completely until 0 bytes are returned #1652
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Previously, if the read bytes were less than the requested, the file was closed immediately. This behavior, however, does not consider the fact that the read operation may be blocking when no bytes are available at the moment. That is true for a named pipe (FIFO), for instance. Thus, reading it again lets to the underlying file system the decision of 1) blocking until bytes become available or 2) return 0 immediately (the case for actual files) or 3) read available bytes.
Impact
No impact on actual files: if the file has reached its end, the second
read
operation will return0
and the file will be closed.It enables, however, using files that
read
may block to wait for new bytes to become available. That is the case for named pipes (FIFO).Testing
Tested on ESP32-LyraT board using an actual file (
romfs
), a HTTP streamed file, and a continuously fed named pipe (mkfifo
+ rtpdump).