| 128 | /// Handle a completed read of message data. |
| 129 | template <typename T, typename Handler> |
| 130 | void handle_read_data(const boost::system::error_code& e, |
| 131 | T& t, std::tuple<Handler> handler) |
| 132 | { |
| 133 | if (e) |
| 134 | { |
| 135 | std::get<0>(handler)(e); |
| 136 | } |
| 137 | else |
| 138 | { |
| 139 | // Extract the data structure from the data just received. |
| 140 | try |
| 141 | { |
| 142 | std::string archive_data(&inbound_data_[0], inbound_data_.size()); |
| 143 | std::istringstream archive_stream(archive_data); |
| 144 | boost::archive::text_iarchive archive(archive_stream); |
| 145 | archive >> t; |
| 146 | } |
| 147 | catch (std::exception& e) |
| 148 | { |
| 149 | // Unable to decode data. |
| 150 | boost::system::error_code error(boost::asio::error::invalid_argument); |
| 151 | std::get<0>(handler)(error); |
| 152 | return; |
| 153 | } |
| 154 | |
| 155 | // Inform caller that data has been received ok. |
| 156 | std::get<0>(handler)(e); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | private: |
| 161 | /// The underlying socket. |