as per the implementation and the document of input_stream::read_exactly():
/// stream and returns them. If the end of stream is reached before n
/// bytes were read, fewer than n bytes will be returned - so despite
/// the method's name, the caller must not assume the returned buffer
/// will always contain exactly n bytes.
Signed-off-by: Kefu Chai <kchai@redhat.com>
if (bytes == 0) {
return seastar::make_ready_future<seastar::temporary_buffer<char>>();
}
- return in.read_exactly(bytes).then([](auto buf) {
- if (buf.empty()) {
+ return in.read_exactly(bytes).then([bytes](auto buf) {
+ if (buf.size() < bytes) {
throw std::system_error(make_error_code(error::read_eof));
}
return seastar::make_ready_future<tmp_buf>(std::move(buf));