From 5f7c105b6d8998bc4aac460e47241bbdfdb1d066 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Thu, 10 Dec 2020 15:03:26 +0100 Subject: [PATCH] Use boost::asio::transfer_exactly Instead of doing assertions. --- src/common/communication.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/common/communication.h b/src/common/communication.h index de8c2e97..3addf61d 100644 --- a/src/common/communication.h +++ b/src/common/communication.h @@ -106,7 +106,8 @@ template inline T read_object(Socket& socket, std::vector& buffer) { // See the note above on the use of `uint64_t` instead of `size_t` std::array message_length; - boost::asio::read(socket, boost::asio::buffer(message_length)); + boost::asio::read(socket, boost::asio::buffer(message_length), + boost::asio::transfer_exactly(sizeof(message_length))); // Make sure the buffer is large enough const size_t size = message_length[0]; @@ -116,8 +117,8 @@ inline T read_object(Socket& socket, std::vector& buffer) { // merging for us, since local domain sockets have packet limits somewhere // in the hundreds of kilobytes const auto actual_size = - boost::asio::read(socket, boost::asio::buffer(buffer)); - assert(size == actual_size); + boost::asio::read(socket, boost::asio::buffer(buffer), + boost::asio::transfer_exactly(size)); T object; auto [_, success] =