summaryrefslogtreecommitdiff
path: root/cpp/examples
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2025-09-16 20:49:49 -0400
committerpommicket <pommicket@gmail.com>2025-09-16 20:52:22 -0400
commitea7b73aac55177d1d556d0c9dba04b0870d3aaf6 (patch)
tree98862ab518680573c4d1d77542bc88b5ec9ceb2a /cpp/examples
parent62bb1ffdee060819657161e260e75e3e1df017ac (diff)
Allow short reads from read_func
Diffstat (limited to 'cpp/examples')
-rw-r--r--cpp/examples/all_functions.cpp23
1 files changed, 6 insertions, 17 deletions
diff --git a/cpp/examples/all_functions.cpp b/cpp/examples/all_functions.cpp
index 326ae39..5081e83 100644
--- a/cpp/examples/all_functions.cpp
+++ b/cpp/examples/all_functions.cpp
@@ -15,24 +15,13 @@ public:
}
~FdReader() { close(m_fd); }
size_t read(char *buf, size_t size) {
- size_t total_read = 0;
- while (true) {
- // must call read in a loop to fill buf up as much as possible!
- // (read isn't guaranteed to read len bytes even if it could)
- ssize_t ret = ::read(m_fd, buf, size);
- if (ret < 0) {
- // read error
- throw "read error";
- } else if (ret == 0) {
- // end-of-file
- break;
- } else {
- total_read += ret;
- buf += ret;
- size -= ret;
- }
+ ssize_t ret = ::read(m_fd, buf, size);
+ if (ret < 0) {
+ // read error
+ throw "read error";
+ } else {
+ return ret;
}
- return total_read;
}
private:
int m_fd;