From: Yingxin Date: Wed, 24 Oct 2018 14:49:30 +0000 (+0800) Subject: crimson/net: check short reads in `read_exactly()` X-Git-Tag: v14.1.0~862^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c014f702d9b59fde29c9fc2027fe60c113e605ff;p=ceph.git crimson/net: check short reads in `read_exactly()` Signed-off-by: Yingxin --- diff --git a/src/crimson/net/Socket.cc b/src/crimson/net/Socket.cc index 3c12c61d8cde..a22e9b2eac66 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 07ab18954d1a..3c0411355088 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));