From 907aea748a8200bd7ae520e2bd6ac04c27fa62ee Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sat, 20 Feb 2021 16:49:19 +0800 Subject: [PATCH] crimson/net: throw read_eof if short read 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 --- src/crimson/net/Socket.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/crimson/net/Socket.cc b/src/crimson/net/Socket.cc index 8ad106dbdd7e2..990c191a250db 100644 --- a/src/crimson/net/Socket.cc +++ b/src/crimson/net/Socket.cc @@ -92,8 +92,8 @@ Socket::read_exactly(size_t bytes) { if (bytes == 0) { return seastar::make_ready_future>(); } - 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(std::move(buf)); -- 2.47.3