@@ -26,16 +26,20 @@ Connection<NextLayer>::async_write(DynamicBuffer &tx_buff,
2626 WriteCallback &&write_callback) {
2727 namespace asio = boost::asio;
2828 namespace sys = boost::system;
29+
2930 using boost::asio::async_write;
3031 using Signature = void (boost::system::error_code, std::size_t );
31- using real_handler_t =
32- typename asio::handler_type<WriteCallback, Signature>::type;
32+ using Callback = std::decay_t <WriteCallback>;
33+ using AsyncResult = asio::async_result<Callback, Signature>;
34+ using CompletionHandler = typename AsyncResult::completion_handler_type;
35+ using serializer_t = command_serializer_visitor<DynamicBuffer>;
3336
34- std::ostream os (&tx_buff);
35- boost::apply_visitor (command_serializer_visitor (os), command);
37+ boost::apply_visitor (serializer_t (tx_buff), command);
3638
37- real_handler_t handler (std::forward<WriteCallback>(write_callback));
38- return async_write (stream_, tx_buff, handler);
39+ CompletionHandler handler (std::forward<WriteCallback>(write_callback));
40+ AsyncResult result (handler);
41+ async_write (stream_, tx_buff, std::move (handler));
42+ return result.get ();
3943}
4044
4145template <typename NextLayer>
@@ -49,31 +53,35 @@ Connection<NextLayer>::async_read(DynamicBuffer &rx_buff,
4953
5054 namespace asio = boost::asio;
5155 namespace sys = boost::system;
56+
5257 using boost::asio::async_read_until;
5358 using Iterator = typename to_iterator<DynamicBuffer>::iterator_t ;
5459 using ParseResult = BREDIS_PARSE_RESULT (DynamicBuffer, Policy);
5560 using Signature = void (boost::system::error_code, ParseResult);
56- using real_handler_t =
57- typename asio::handler_type<ReadCallback, Signature>::type;
61+ using Callback = std::decay_t <ReadCallback>;
62+ using AsyncResult = asio::async_result<Callback, Signature>;
63+ using CompletionHandler = typename AsyncResult::completion_handler_type;
64+ using ReadOp =
65+ async_read_op<NextLayer, DynamicBuffer, CompletionHandler, Policy>;
5866
59- real_handler_t real_handler (std::forward<ReadCallback>(read_callback));
60- asio::async_result< real_handler_t > async_result (real_handler );
67+ CompletionHandler handler (std::forward<ReadCallback>(read_callback));
68+ AsyncResult result (handler );
6169
62- async_read_op<NextLayer, DynamicBuffer, real_handler_t , Policy> async_op (
63- std::move (real_handler), stream_, rx_buff, replies_count);
70+ ReadOp async_op (std::move (handler), stream_, rx_buff, replies_count);
6471
6572 async_read_until (stream_, rx_buff, MatchResult<Iterator>(replies_count),
6673 std::move (async_op));
67- return async_result .get ();
74+ return result .get ();
6875}
6976
7077template <typename NextLayer>
7178void Connection<NextLayer>::write(const command_wrapper_t &command,
7279 boost::system::error_code &ec) {
7380 namespace asio = boost::asio;
7481 asio::streambuf tx_buff;
75- std::ostream os (&tx_buff);
76- boost::apply_visitor (command_serializer_visitor (os), command);
82+ using serializer_t = command_serializer_visitor<asio::streambuf>;
83+
84+ boost::apply_visitor (serializer_t (tx_buff), command);
7785 asio::write (stream_, tx_buff, ec);
7886}
7987
@@ -93,6 +101,7 @@ Connection<NextLayer>::read(DynamicBuffer &rx_buff,
93101 boost::system::error_code &ec) {
94102 namespace asio = boost::asio;
95103 using boost::asio::read_until;
104+
96105 using Iterator = typename to_iterator<DynamicBuffer>::iterator_t ;
97106 using Policy = bredis::parsing_policy::keep_result;
98107 using result_t = BREDIS_PARSE_RESULT (DynamicBuffer, Policy);
0 commit comments