21 asio::streambuf message_buf;
22 std::ostream message_stream(&message_buf);
26 std::size_t bytes_written =
27 asio::write(
GetSocket(), message_buf.data(), ec);
30 throw std::runtime_error(
"Error sending message: " + ec.message());
34 "FramedSocketTransport sent message with {} bytes", bytes_written);
35 }
catch (
const std::exception &e) {
36 spdlog::error(
"FramedSocketTransport failed to send message: {}", e.what());
42 asio::streambuf buffer;
46 asio::read_until(GetSocket(), buffer, kHeaderDelimiter, ec);
48 throw std::runtime_error(
"Failed to read message headers: " + ec.message());
51 std::istream header_stream(&buffer);
54 int content_length = ReadContentLengthFromStream(header_stream);
57 std::size_t remaining_content_length = content_length - buffer.size();
60 if (remaining_content_length > 0) {
61 asio::read(GetSocket(), buffer.prepare(remaining_content_length), ec);
62 if (ec && ec != asio::error::eof) {
63 throw std::runtime_error(
64 "Failed to read message content: " + ec.message());
66 buffer.commit(remaining_content_length);
71 asio::buffers_begin(buffer.data()), asio::buffers_end(buffer.data()));