From c014f702d9b59fde29c9fc2027fe60c113e605ff Mon Sep 17 00:00:00 2001 From: Yingxin Date: Wed, 24 Oct 2018 22:49:30 +0800 Subject: [PATCH] crimson/net: check short reads in `read_exactly()` Signed-off-by: Yingxin --- src/crimson/net/Socket.cc | 11 +++++++++++ src/crimson/net/Socket.h | 4 +--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/crimson/net/Socket.cc b/src/crimson/net/Socket.cc index 3c12c61d8cd..a22e9b2eac6 100644 --- a/src/crimson/net/Socket.cc +++ b/src/crimson/net/Socket.cc @@ -67,4 +67,15 @@ seastar::future Socket::read(size_t bytes) }); } +seastar::future> +Socket::read_exactly(size_t bytes) { + return in.read_exactly(bytes) + .then([this](auto buf) { + if (buf.empty()) { + throw std::system_error(make_error_code(error::read_eof)); + } + return seastar::make_ready_future(std::move(buf)); + }); +} + } // namespace ceph::net diff --git a/src/crimson/net/Socket.h b/src/crimson/net/Socket.h index 07ab18954d1..3c041135508 100644 --- a/src/crimson/net/Socket.h +++ b/src/crimson/net/Socket.h @@ -33,9 +33,7 @@ class Socket seastar::future read(size_t bytes); using tmp_buf = seastar::temporary_buffer; using packet = seastar::net::packet; - seastar::future read_exactly(size_t bytes) { - return in.read_exactly(bytes); - } + seastar::future read_exactly(size_t bytes); seastar::future<> write(packet&& buf) { return out.write(std::move(buf)); -- 2.39.5