@@ -43,13 +43,16 @@ double time_s() {
4343// alias namespaces
4444namespace r = bredis;
4545namespace asio = boost::asio;
46+ using boost::get;
4647
4748int main (int argc, char **argv) {
4849 // common setup
4950 using socket_t = asio::ip::tcp::socket;
5051 using next_layer_t = socket_t ;
5152 using Buffer = boost::asio::streambuf;
5253 using Iterator = typename r::to_iterator<Buffer>::iterator_t ;
54+ using policy_t = r::parsing_policy::drop_result;
55+ // using policy_t = r::parsing_policy::keep_result;
5356
5457 if (argc < 2 ) {
5558 std::cout << " Usage : " << argv[0 ] << " ip:port \n " ;
@@ -70,12 +73,10 @@ int main(int argc, char **argv) {
7073
7174 // write subscribe cmd
7275 r::single_command_t cmd_incr{" INCR" , " simple_loop:count" };
73- r::single_command_t cmd_get{" GET" , " simple_loop:count" };
7476 r::command_container_t cmd_container;
7577 for (size_t i = 0 ; i < cmds_count; ++i) {
7678 cmd_container.push_back (cmd_incr);
7779 }
78- cmd_container.push_back (cmd_get);
7980
8081 r::command_wrapper_t cmd_wpapper{std::move (cmd_container)};
8182
@@ -92,27 +93,23 @@ int main(int argc, char **argv) {
9293 r::Connection<next_layer_t > c (std::move (socket));
9394
9495 Buffer tx_buff, rx_buff;
95- std::promise<std::string> completion_promise;
96- std::future<std::string> completion_future =
97- completion_promise.get_future ();
96+ std::promise<void > completion_promise;
97+ auto completion_future = completion_promise.get_future ();
9898
9999 c.async_read (
100100 rx_buff,
101101 [&](const boost::system::error_code &ec, auto &&r) {
102102 assert (!ec);
103103 (void )ec;
104- auto &replies =
105- boost::get<r::markers::array_holder_t <Iterator>>(r.result );
106- auto &last_reply = replies.elements .at (replies.elements .size () - 1 );
107- auto &str_reply =
108- boost::get<r::markers::string_t <Iterator>>(last_reply);
109- std::string value{str_reply.from , str_reply.to };
110104 rx_buff.consume (r.consumed );
111- count += replies.elements .size () - 1 ;
112- completion_promise.set_value (value);
105+ // cannot be done with drop_result
106+ // auto &replies = get<r::markers::array_holder_t<Iterator>>(r.result);
107+ // count += replies.elements.size() - 1;
108+ count = cmds_count;
109+ completion_promise.set_value ();
113110 std::cout << " done reading...\n " ;
114111 },
115- cmds_count + 1 );
112+ cmds_count, policy_t {} );
116113
117114 c.async_write (tx_buff, cmd_wpapper, [&](const boost::system::error_code &ec,
118115 auto bytes_transferred) {
@@ -132,13 +129,20 @@ int main(int argc, char **argv) {
132129
133130 io_service.run ();
134131 std::cout << " done...\n " ;
132+ completion_future.get ();
133+
134+ c.write (r::single_command_t {" GET" , " simple_loop:count" });
135+ auto r = c.read (rx_buff);
136+ auto &str_reply = get<r::markers::string_t <Iterator>>(r.result );
137+
138+ std::string counter_value {str_reply.from , str_reply.to };
135139
136140 double actual_freq = (double )count / t_elapsed;
137141 std::cout << " Sent " << cmds_count << " commands in " << t_elapsed << " s, "
138142 << " that's " << actual_freq << " commands/s."
139143 << " \n " ;
140144
141- std::cout << " Final value of counter: " << completion_future. get () << " \n " ;
145+ std::cout << " Final value of counter: " << counter_value << " \n " ;
142146
143147 std::cout << " exiting...\n " ;
144148 return 0 ;
0 commit comments