summaryrefslogtreecommitdiff
path: root/src/uio.cc
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2025-09-22 23:38:21 +0200
committerJoel Klinghed <the_jk@spawned.biz>2025-09-22 23:38:21 +0200
commitce271f82f16ee89a18e7bfc9ed8eab7cbd6f37bc (patch)
tree3e568faf83ae750aa244cca87b55951c7401ef03 /src/uio.cc
parent50348284f5d82ccfd65b0c803ba0ba895912ceff (diff)
Change io::Reader and company to return ReadError::Eof instead of 0.
It's debatable if Eof should be considered an error or not. But it is pretty clear it generally is a special response that needs special handling, so easier to keep with the unexpected lot. Also keeps better at higher abstraction levels, such as the line reader.
Diffstat (limited to 'src/uio.cc')
-rw-r--r--src/uio.cc9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/uio.cc b/src/uio.cc
index 9fc22c1..da943a2 100644
--- a/src/uio.cc
+++ b/src/uio.cc
@@ -50,6 +50,11 @@ class UnicodeReader : public io::Reader {
return std::unexpected(io::ReadError::InvalidData);
break;
case u::ReadError::End:
+ if (in_eof_) {
+ // Only return eof if we have no bytes to output.
+ if (u_buffer_wptr_ == u_buffer_)
+ return std::unexpected(io::ReadError::Eof);
+ }
break;
case u::ReadError::Incomplete:
if (in_eof_) {
@@ -106,8 +111,8 @@ class UnicodeReader : public io::Reader {
auto got = in_->read(wptr, in_avail_);
if (got.has_value()) {
byte_buffer_->commit(got.value());
- if (got.value() == 0)
- in_eof_ = true;
+ } else if (got.error() == io::ReadError::Eof) {
+ in_eof_ = true;
} else {
return got.error();
}