19 asio::streambuf message_buf;
20 std::ostream message_stream(&message_buf);
24 std::size_t bytes_written =
25 asio::write(
GetSocket(), message_buf.data(), ec);
28 throw std::runtime_error(
"Error sending message: " + ec.message());
32 "FramedPipeTransport sent message with {} bytes", bytes_written);
33 }
catch (
const std::exception &e) {
34 spdlog::error(
"FramedPipeTransport failed to send message: {}", e.what());
40 asio::streambuf buffer;
44 asio::read_until(GetSocket(), buffer, kHeaderDelimiter, ec);
46 throw std::runtime_error(
"Failed to read message headers: " + ec.message());
49 std::istream header_stream(&buffer);
52 int content_length = ReadContentLengthFromStream(header_stream);
55 std::size_t remaining_content_length = content_length - buffer.size();
58 if (remaining_content_length > 0) {
59 asio::read(GetSocket(), buffer.prepare(remaining_content_length), ec);
60 if (ec && ec != asio::error::eof) {
61 throw std::runtime_error(
62 "Failed to read message content: " + ec.message());
64 buffer.commit(remaining_content_length);
69 asio::buffers_begin(buffer.data()), asio::buffers_end(buffer.data()));