MCPcopy Create free account
hub / github.com/boostorg/asio / handle_read_header

Method handle_read_header

example/cpp11/serialization/connection.hpp:96–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

94 /// Handle a completed read of a message header.
95 template <typename T, typename Handler>
96 void handle_read_header(const boost::system::error_code& e,
97 T& t, std::tuple<Handler> handler)
98 {
99 if (e)
100 {
101 std::get<0>(handler)(e);
102 }
103 else
104 {
105 // Determine the length of the serialized data.
106 std::istringstream is(std::string(inbound_header_, header_length));
107 std::size_t inbound_data_size = 0;
108 if (!(is >> std::hex >> inbound_data_size))
109 {
110 // Header doesn't seem to be valid. Inform the caller.
111 boost::system::error_code error(boost::asio::error::invalid_argument);
112 std::get<0>(handler)(error);
113 return;
114 }
115
116 // Start an asynchronous call to receive the data.
117 inbound_data_.resize(inbound_data_size);
118 void (connection::*f)(
119 const boost::system::error_code&,
120 T&, std::tuple<Handler>)
121 = &connection::handle_read_data<T, Handler>;
122 boost::asio::async_read(socket_, boost::asio::buffer(inbound_data_),
123 std::bind(f, this,
124 boost::asio::placeholders::error, std::ref(t), handler));
125 }
126 }
127
128 /// Handle a completed read of message data.
129 template <typename T, typename Handler>

Callers

nothing calls this directly

Calls 6

stringFunction · 0.85
async_readFunction · 0.85
bufferFunction · 0.85
bindFunction · 0.50
refClass · 0.50
resizeMethod · 0.45

Tested by

no test coverage detected