From 9e3b7b5bff6fd1f3fa62035ee06afaaa2c126dd2 Mon Sep 17 00:00:00 2001 From: Ivan Baidakou Date: Sat, 10 Aug 2019 12:36:32 +0300 Subject: [PATCH 1/4] relax requirements: use c++11 instead c++14 --- CMakeLists.txt | 3 +-- examples/multi-threads-1.cpp | 18 ++++++++----- include/bredis/Command.hpp | 6 ++--- include/bredis/MarkerHelpers.hpp | 18 +++++++------ include/bredis/impl/connection.ipp | 6 ++--- t/10-ping.cpp | 6 +++-- t/11-multi-ping.cpp | 33 ++++++++++++----------- t/12-basic-types.cpp | 16 ++++++----- t/13-protol-error.cpp | 24 ++++++++++------- t/14-uds.cpp | 18 +++++++------ t/15-cancellation.cpp | 18 ++++++++----- t/16-close-connection.cpp | 43 +++++++++++++++++------------- t/19-transaction.cpp | 24 ++++++++++------- t/22-ping_drop-policy.cpp | 31 ++++++++++----------- t/TestServer.hpp | 8 +++--- 15 files changed, 153 insertions(+), 119 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe614640..d1b2b79d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,14 +1,13 @@ cmake_minimum_required(VERSION 3.0) project (bredis) -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) include (CTest) enable_testing() - add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY) add_definitions(-DBOOST_COROUTINES_NO_DEPRECATION_WARNING) #add_definitions(-DBREDIS_DEBUG) diff --git a/examples/multi-threads-1.cpp b/examples/multi-threads-1.cpp index 8cf95141..af074cb6 100644 --- a/examples/multi-threads-1.cpp +++ b/examples/multi-threads-1.cpp @@ -35,12 +35,15 @@ namespace r = bredis; namespace asio = boost::asio; namespace po = boost::program_options; +namespace sys = boost::system; using socket_t = asio::ip::tcp::socket; using next_layer_t = socket_t; //using next_layer_t = r::test::SocketWithLogging; using Buffer = boost::asio::streambuf; using Iterator = typename r::to_iterator::iterator_t; +using Policy = r::parsing_policy::keep_result; +using result_t = r::positive_parse_result_t; using Connection = r::Connection; struct redis_accessor_t { @@ -64,8 +67,9 @@ struct producer_t { redis.conn.async_write( redis.tx_buff, cmd_ping, - asio::bind_executor(redis.strand, [self = this](const auto &error_code, size_t bytes_transferred){ - if (!error_code){ + asio::bind_executor(redis.strand, [this](const sys::error_code &ec, std::size_t bytes_transferred){ + if (!ec){ + auto self = this; self->redis.ping_count++; self->redis.tx_buff.consume(bytes_transferred); self->produce(); @@ -83,8 +87,9 @@ struct consumer_t { void consume(){ redis.conn.async_read( redis.rx_buff, - asio::bind_executor(redis.strand, [self = this](const auto &error_code, auto &&r){ - if(!error_code){ + asio::bind_executor(redis.strand, [this](const sys::error_code &ec, result_t &&r){ + if(!ec){ + auto self = this; self->redis.pong_count++; self->redis.rx_buff.consume(r.consumed); self->consume(); @@ -103,8 +108,9 @@ struct watcher_t { void watch() { timer.expires_after(asio::chrono::seconds(1)); timer.async_wait( - asio::bind_executor(redis.strand, [self = this](const auto &error_code){ - if (!error_code) { + asio::bind_executor(redis.strand, [this](const sys::error_code &ec){ + if (!ec) { + auto self = this; std::cout << "pings: " << self->redis.ping_count << ", pongs: " << self->redis.pong_count << "\n"; self->watch(); } diff --git a/include/bredis/Command.hpp b/include/bredis/Command.hpp index 66632ed7..673b043b 100644 --- a/include/bredis/Command.hpp +++ b/include/bredis/Command.hpp @@ -6,9 +6,9 @@ // #pragma once +#include #include #include -#include #include #include "Result.hpp" @@ -31,14 +31,14 @@ struct single_command_t { args_container_t arguments; template ::value>> single_command_t(Args &&... args) : arguments{std::forward(args)...} { static_assert(sizeof...(Args) >= 1, "Empty command is not allowed"); } template ::value_type>::value>> single_command_t(InputIterator first, InputIterator last) diff --git a/include/bredis/MarkerHelpers.hpp b/include/bredis/MarkerHelpers.hpp index c2f0ebfb..d425b838 100644 --- a/include/bredis/MarkerHelpers.hpp +++ b/include/bredis/MarkerHelpers.hpp @@ -8,6 +8,7 @@ #pragma once #include +#include #include #include #include @@ -81,21 +82,22 @@ class equality : public boost::static_visitor { } bool operator()(const markers::string_t &value) const { - auto helper = stringizer(); - auto str = helper(value); - return std::equal(begin_, end_, value.from, value.to); + return boost::algorithm::equal(begin_, end_, value.from, value.to); } bool operator()(const markers::int_t &value) const { - return std::equal(begin_, end_, value.string.from, value.string.to); + return boost::algorithm::equal(begin_, end_, value.string.from, + value.string.to); } bool operator()(const markers::error_t &value) const { - return std::equal(begin_, end_, value.string.from, value.string.to); + return boost::algorithm::equal(begin_, end_, value.string.from, + value.string.to); } bool operator()(const markers::nil_t &value) const { - return std::equal(begin_, end_, value.string.from, value.string.to); + return boost::algorithm::equal(begin_, end_, value.string.from, + value.string.to); } }; @@ -172,8 +174,8 @@ class check_subscription : public boost::static_visitor { } const auto &channel_ = cmd_.arguments[idx]; - return std::equal(channel_.cbegin(), channel_.cend(), channel->from, - channel->to); + return boost::algorithm::equal(channel_.cbegin(), channel_.cend(), + channel->from, channel->to); } return false; } diff --git a/include/bredis/impl/connection.ipp b/include/bredis/impl/connection.ipp index 79b641ca..e7f4dc4f 100644 --- a/include/bredis/impl/connection.ipp +++ b/include/bredis/impl/connection.ipp @@ -9,9 +9,9 @@ #include "common.ipp" #include +#include #include #include -#include #include "async_op.ipp" @@ -29,7 +29,7 @@ Connection::async_write(DynamicBuffer &tx_buff, using boost::asio::async_write; using Signature = void(boost::system::error_code, std::size_t); - using Callback = std::decay_t; + using Callback = boost::decay_t; using AsyncResult = asio::async_result; using CompletionHandler = typename AsyncResult::completion_handler_type; using serializer_t = command_serializer_visitor; @@ -58,7 +58,7 @@ Connection::async_read(DynamicBuffer &rx_buff, using Iterator = typename to_iterator::iterator_t; using ParseResult = BREDIS_PARSE_RESULT(DynamicBuffer, Policy); using Signature = void(boost::system::error_code, ParseResult); - using Callback = std::decay_t; + using Callback = boost::decay_t; using AsyncResult = asio::async_result; using CompletionHandler = typename AsyncResult::completion_handler_type; using ReadOp = diff --git a/t/10-ping.cpp b/t/10-ping.cpp index 9b27bc23..0d35d6c7 100644 --- a/t/10-ping.cpp +++ b/t/10-ping.cpp @@ -14,6 +14,7 @@ namespace r = bredis; namespace asio = boost::asio; namespace ep = empty_port; namespace ts = test_server; +namespace sys = boost::system; TEST_CASE("ping", "[connection]") { using socket_t = asio::ip::tcp::socket; @@ -48,10 +49,11 @@ TEST_CASE("ping", "[connection]") { Buffer tx_buff, rx_buff; c.async_write( - tx_buff, "ping", [&](const auto &error_code, auto bytes_transferred) { + tx_buff, "ping", + [&](const sys::error_code &error_code, std::size_t bytes_transferred) { REQUIRE(!error_code); tx_buff.consume(bytes_transferred); - c.async_read(rx_buff, [&](const auto&, auto &&r) { + c.async_read(rx_buff, [&](const sys::error_code &, result_t &&r) { completion_promise.set_value(r); rx_buff.consume(r.consumed); }); diff --git a/t/11-multi-ping.cpp b/t/11-multi-ping.cpp index 795f357b..e335091e 100644 --- a/t/11-multi-ping.cpp +++ b/t/11-multi-ping.cpp @@ -1,7 +1,7 @@ #include #include -#include #include +#include #include "EmptyPort.hpp" #include "SocketWithLogging.hpp" @@ -14,6 +14,7 @@ namespace r = bredis; namespace asio = boost::asio; namespace ep = empty_port; namespace ts = test_server; +namespace sys = boost::system; TEST_CASE("ping", "[connection]") { using socket_t = asio::ip::tcp::socket; @@ -59,23 +60,23 @@ TEST_CASE("ping", "[connection]") { std::future completion_future = completion_promise.get_future(); Buffer tx_buff, rx_buff; - read_callback_t read_callback = - [&](const boost::system::error_code &error_code, ParseResult &&r) { - if (error_code) { - BREDIS_LOG_DEBUG("error: " << error_code.message()); - REQUIRE(!error_code); - } + read_callback_t read_callback = [&](const sys::error_code &error_code, + ParseResult &&r) { + if (error_code) { + BREDIS_LOG_DEBUG("error: " << error_code.message()); REQUIRE(!error_code); - auto &replies = - boost::get>(r.result); - BREDIS_LOG_DEBUG("callback, size: " << replies.elements.size()); - REQUIRE(replies.elements.size() == count); - completion_promise.set_value(); - rx_buff.consume(r.consumed); - }; + } + REQUIRE(!error_code); + auto &replies = + boost::get>(r.result); + BREDIS_LOG_DEBUG("callback, size: " << replies.elements.size()); + REQUIRE(replies.elements.size() == count); + completion_promise.set_value(); + rx_buff.consume(r.consumed); + }; - write_callback_t write_callback = [&]( - const boost::system::error_code &error_code, auto bytes_transferred) { + write_callback_t write_callback = [&](const sys::error_code &error_code, + std::size_t bytes_transferred) { (void)bytes_transferred; BREDIS_LOG_DEBUG("write_callback"); if (error_code) { diff --git a/t/12-basic-types.cpp b/t/12-basic-types.cpp index 5eb654fc..35aeb0ee 100644 --- a/t/12-basic-types.cpp +++ b/t/12-basic-types.cpp @@ -15,6 +15,7 @@ namespace r = bredis; namespace asio = boost::asio; namespace ep = empty_port; namespace ts = test_server; +namespace sys = boost::system; TEST_CASE("ping", "[connection]") { using socket_t = asio::ip::tcp::socket; @@ -64,7 +65,7 @@ TEST_CASE("ping", "[connection]") { r::single_command_t("time"), }; std::vector callbacks{ - [&](const boost::system::error_code&error_code, ParseResult &&r) { + [&](const boost::system::error_code &error_code, ParseResult &&r) { auto extract = boost::apply_visitor(Extractor(), r.result); REQUIRE(boost::get(extract) == 0); REQUIRE(order == 0); @@ -120,12 +121,13 @@ TEST_CASE("ping", "[connection]") { c.async_read(rx_buff, generic_callback); }; - c.async_write(tx_buff, r::command_wrapper_t(cmds_container), - [&](const auto &error_code, auto bytes_transferred) { - REQUIRE(!error_code); - tx_buff.consume(bytes_transferred); - c.async_read(rx_buff, generic_callback); - }); + c.async_write( + tx_buff, r::command_wrapper_t(cmds_container), + [&](const sys::error_code &ec, std::size_t bytes_transferred) { + REQUIRE(!ec); + tx_buff.consume(bytes_transferred); + c.async_read(rx_buff, generic_callback); + }); while (completion_future.wait_for(sleep_delay) != std::future_status::ready) { diff --git a/t/13-protol-error.cpp b/t/13-protol-error.cpp index b62ffd24..30a4873b 100644 --- a/t/13-protol-error.cpp +++ b/t/13-protol-error.cpp @@ -13,6 +13,7 @@ namespace r = bredis; namespace asio = boost::asio; namespace sys = boost::system; namespace ep = empty_port; +namespace sys = boost::system; TEST_CASE("protocol-error", "[connection]") { using socket_t = asio::ip::tcp::socket; @@ -53,17 +54,18 @@ TEST_CASE("protocol-error", "[connection]") { async_read_until( peer_socket, remote_rx_buff, end_marker, [&](const sys::error_code &ec, std::size_t sz) { - (void)ec;(void)sz; + (void)ec; + (void)sz; BREDIS_LOG_DEBUG("async_read: " << sz << ", " << ec.message()); async_write(peer_socket, output_buf, [&](const sys::error_code &ec, std::size_t sz) { - (void)ec;(void)sz; + (void)ec; + (void)sz; BREDIS_LOG_DEBUG("async_write: " << sz << ", " << ec.message()); }); }); - }); socket_t socket(io_service, end_point.protocol()); @@ -75,14 +77,16 @@ TEST_CASE("protocol-error", "[connection]") { Buffer rx_buff, tx_buff; c.async_write( - tx_buff, "ping", [&](const auto &error_code, auto bytes_transferred) { - REQUIRE(!error_code); + tx_buff, "ping", + [&](const sys::error_code &ec, std::size_t bytes_transferred) { + REQUIRE(!ec); tx_buff.consume(bytes_transferred); - c.async_read(rx_buff, [&](const auto &error_code, ParseResult &&) { - REQUIRE(error_code); - REQUIRE(error_code.message() == "Wrong introduction"); - completion_promise.set_value(); - }); + c.async_read(rx_buff, + [&](const sys::error_code &ec, ParseResult &&) { + REQUIRE(ec); + REQUIRE(ec.message() == "Wrong introduction"); + completion_promise.set_value(); + }); }); while (completion_future.wait_for(sleep_delay) != std::future_status::ready) { diff --git a/t/14-uds.cpp b/t/14-uds.cpp index 0530567c..2415288d 100644 --- a/t/14-uds.cpp +++ b/t/14-uds.cpp @@ -18,6 +18,7 @@ namespace r = bredis; namespace asio = boost::asio; namespace ts = test_server; namespace ep = empty_port; +namespace sys = boost::system; struct tmpfile_holder_t { char *filename_; @@ -75,9 +76,9 @@ TEST_CASE("ping", "[connection]") { std::future completion_future = completion_promise.get_future(); Buffer rx_buff, tx_buff; - read_callback_t read_callback = [&](const auto &error_code, + read_callback_t read_callback = [&](const sys::error_code &ec, ParseResult &&r) { - REQUIRE(!error_code); + REQUIRE(!ec); rx_buff.consume(r.consumed); auto str = boost::apply_visitor( @@ -96,12 +97,13 @@ TEST_CASE("ping", "[connection]") { completion_promise.set_value(); }; - c.async_write(tx_buff, cmd, - [&](const auto &error_code, auto bytes_transferred) { - REQUIRE(!error_code); - tx_buff.consume(bytes_transferred); - c.async_read(rx_buff, read_callback, count); - }); + c.async_write( + tx_buff, cmd, + [&](const sys::error_code &ec, std::size_t bytes_transferred) { + REQUIRE(!ec); + tx_buff.consume(bytes_transferred); + c.async_read(rx_buff, read_callback, count); + }); while (completion_future.wait_for(sleep_delay) != std::future_status::ready) { diff --git a/t/15-cancellation.cpp b/t/15-cancellation.cpp index 3901d4fe..3a4be6be 100644 --- a/t/15-cancellation.cpp +++ b/t/15-cancellation.cpp @@ -15,6 +15,7 @@ namespace asio = boost::asio; namespace sys = boost::system; namespace ep = empty_port; namespace ts = test_server; +namespace sys = boost::system; TEST_CASE("cancel-on-read", "[cancellation]") { using socket_t = asio::ip::tcp::socket; @@ -69,14 +70,17 @@ TEST_CASE("cancel-on-read", "[cancellation]") { Buffer rx_buff, tx_buff; c.async_write( - tx_buff, "ping", [&](const auto &error_code, auto bytes_transferred) { - REQUIRE(!error_code); + tx_buff, "ping", + [&](const sys::error_code &ec, std::size_t bytes_transferred) { + REQUIRE(!ec); tx_buff.consume(bytes_transferred); - c.async_read(rx_buff, [&](const auto &error_code, ParseResult &&) { - REQUIRE(error_code); - // REQUIRE(error_code.message() == "Operation canceled"); - completion_promise.set_value(); - }); + c.async_read(rx_buff, + [&](const sys::error_code &ec, ParseResult &&) { + REQUIRE(ec); + // REQUIRE(error_code.message() == "Operation + // canceled"); + completion_promise.set_value(); + }); }); while (completion_future.wait_for(sleep_delay) != diff --git a/t/16-close-connection.cpp b/t/16-close-connection.cpp index fdba61e8..6a835743 100644 --- a/t/16-close-connection.cpp +++ b/t/16-close-connection.cpp @@ -13,6 +13,7 @@ namespace r = bredis; namespace asio = boost::asio; namespace sys = boost::system; namespace ep = empty_port; +namespace sys = boost::system; TEST_CASE("close-afrer-read", "[connection]") { using socket_t = asio::ip::tcp::socket; @@ -44,20 +45,19 @@ TEST_CASE("close-afrer-read", "[connection]") { std::string data = "bla-bla"; std::string end_marker = "ping\r\n"; Buffer remote_rx_buff; - acceptor.async_accept(peer_socket, [&](const sys::error_code& ec1) { + acceptor.async_accept(peer_socket, [&](const sys::error_code &ec1) { (void)ec1; BREDIS_LOG_DEBUG("async_accept: " << ec1.message() << ", " << peer_socket.local_endpoint()); async_read_until(peer_socket, remote_rx_buff, end_marker, - [&](const sys::error_code& ec2, std::size_t) { - (void)ec2; + [&](const sys::error_code &ec2, std::size_t) { + (void)ec2; BREDIS_LOG_DEBUG("async_read: " << sz << ", " << ec2.message()); peer_socket.close(); }); - }); socket_t socket(io_service, end_point.protocol()); @@ -69,14 +69,16 @@ TEST_CASE("close-afrer-read", "[connection]") { Buffer rx_buff, tx_buff; c.async_write( - tx_buff, "ping", [&](const auto &error_code, auto bytes_transferred) { - REQUIRE(!error_code); + tx_buff, "ping", + [&](const sys::error_code &ec, std::size_t bytes_transferred) { + REQUIRE(!ec); tx_buff.consume(bytes_transferred); - c.async_read(rx_buff, [&](const auto &error_code, ParseResult &&) { - REQUIRE(error_code); - REQUIRE(error_code.message() == "End of file"); - completion_promise.set_value(); - }); + c.async_read(rx_buff, + [&](const sys::error_code &ec, ParseResult &&) { + REQUIRE(ec); + REQUIRE(ec.message() == "End of file"); + completion_promise.set_value(); + }); }); while (completion_future.wait_for(sleep_delay) != @@ -130,15 +132,18 @@ TEST_CASE("close-before-write", "[connection]") { Buffer rx_buff, tx_buff; c.async_write( - tx_buff, "ping", [&](const auto &error_code, auto bytes_transferred) { - REQUIRE(!error_code); + tx_buff, "ping", + [&](const sys::error_code &ec, std::size_t bytes_transferred) { + REQUIRE(!ec); tx_buff.consume(bytes_transferred); - c.async_read(rx_buff, [&](const auto &error_code, ParseResult &&) { - REQUIRE(error_code); - // locale and os-dependent - // REQUIRE(error_code.message() == "Connection reset by peer"); - completion_promise.set_value(); - }); + c.async_read(rx_buff, + [&](const sys::error_code &ec, ParseResult &&) { + REQUIRE(ec); + // locale and os-dependent + // REQUIRE(error_code.message() == "Connection + // reset by peer"); + completion_promise.set_value(); + }); }); while (completion_future.wait_for(sleep_delay) != std::future_status::ready) { diff --git a/t/19-transaction.cpp b/t/19-transaction.cpp index 60d840d6..81c2a5ae 100644 --- a/t/19-transaction.cpp +++ b/t/19-transaction.cpp @@ -14,6 +14,7 @@ namespace r = bredis; namespace asio = boost::asio; namespace ep = empty_port; namespace ts = test_server; +namespace sys = boost::system; TEST_CASE("transaction", "[connection]") { using socket_t = asio::ip::tcp::socket; @@ -42,8 +43,10 @@ TEST_CASE("transaction", "[connection]") { asio::io_service io_service; r::command_container_t tx_commands = { - r::single_command_t("MULTI"), r::single_command_t("INCR", "foo"), - r::single_command_t("INCR", "bar"), r::single_command_t("EXEC"), + r::single_command_t("MULTI"), + r::single_command_t("INCR", "foo"), + r::single_command_t("INCR", "bar"), + r::single_command_t("EXEC"), }; r::command_wrapper_t cmd(tx_commands); @@ -57,9 +60,9 @@ TEST_CASE("transaction", "[connection]") { r::Connection c(std::move(socket)); Buffer rx_buff, tx_buff; - read_callback_t read_callback = [&]( - const boost::system::error_code &error_code, ParseResult &&r) { - REQUIRE(!error_code); + read_callback_t read_callback = [&](const sys::error_code &ec, + ParseResult &&r) { + REQUIRE(!ec); auto &replies = boost::get>(r.result); @@ -85,11 +88,12 @@ TEST_CASE("transaction", "[connection]") { }; c.async_read(rx_buff, read_callback, tx_commands.size()); - c.async_write(tx_buff, cmd, - [&](const auto &error_code, auto bytes_transferred) { - tx_buff.consume(bytes_transferred); - REQUIRE(!error_code); - }); + c.async_write( + tx_buff, cmd, + [&](const sys::error_code &ec, std::size_t bytes_transferred) { + tx_buff.consume(bytes_transferred); + REQUIRE(!ec); + }); while (completion_future.wait_for(sleep_delay) != std::future_status::ready) { diff --git a/t/22-ping_drop-policy.cpp b/t/22-ping_drop-policy.cpp index c7dfc14e..8b3d4820 100644 --- a/t/22-ping_drop-policy.cpp +++ b/t/22-ping_drop-policy.cpp @@ -13,6 +13,7 @@ namespace r = bredis; namespace asio = boost::asio; namespace ep = empty_port; namespace ts = test_server; +namespace sys = boost::system; TEST_CASE("ping/drop-policy", "[connection]") { using socket_t = asio::ip::tcp::socket; @@ -61,25 +62,25 @@ TEST_CASE("ping/drop-policy", "[connection]") { std::future completion_future = completion_promise.get_future(); Buffer tx_buff, rx_buff; - read_callback_t read_callback = - [&](const boost::system::error_code &error_code, ParseResult &&r) { - if (error_code) { - BREDIS_LOG_DEBUG("error: " << error_code.message()); - REQUIRE(!error_code); - } - REQUIRE(!error_code); - completion_promise.set_value(); - rx_buff.consume(r.consumed); - }; + read_callback_t read_callback = [&](const sys::error_code &ec, + ParseResult &&r) { + if (ec) { + BREDIS_LOG_DEBUG("error: " << error_code.message()); + REQUIRE(!ec); + } + REQUIRE(!ec); + completion_promise.set_value(); + rx_buff.consume(r.consumed); + }; - write_callback_t write_callback = [&]( - const boost::system::error_code &error_code, auto bytes_transferred) { + write_callback_t write_callback = [&](const sys::error_code &ec, + std::size_t bytes_transferred) { BREDIS_LOG_DEBUG("write_callback"); - if (error_code) { + if (ec) { BREDIS_LOG_DEBUG("error: " << error_code.message()); - REQUIRE(!error_code); + REQUIRE(!ec); } - REQUIRE(!error_code); + REQUIRE(!ec); tx_buff.consume(bytes_transferred); }; diff --git a/t/TestServer.hpp b/t/TestServer.hpp index 882fdec1..ed14424e 100644 --- a/t/TestServer.hpp +++ b/t/TestServer.hpp @@ -12,12 +12,14 @@ namespace test_server { struct TestServer { - std::unique_ptr child; + using child_t = std::unique_ptr; + child_t child; TestServer(std::initializer_list &&args) { std::string stringized = boost::algorithm::join(args, " "); std::cout << "going to fork to start: " << stringized << std::endl; - child = std::make_unique(stringized); + auto process = new boost::process::child(stringized); + child.reset(process); } ~TestServer() { std::cout << "terminating child " << child->id() << "\n"; } }; @@ -25,6 +27,6 @@ struct TestServer { using result_t = std::unique_ptr; result_t make_server(std::initializer_list &&args) { - return std::make_unique(std::move(args)); + return result_t{new TestServer(std::move(args))}; } } From 3fbb7e6c9c4e4c4d870a08f4dd35a1a1b75feb1a Mon Sep 17 00:00:00 2001 From: Ivan Baidakou Date: Sat, 10 Aug 2019 12:43:57 +0300 Subject: [PATCH 2/4] fix test --- t/24-dynbuff.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/t/24-dynbuff.cpp b/t/24-dynbuff.cpp index 9042d92a..367d3960 100644 --- a/t/24-dynbuff.cpp +++ b/t/24-dynbuff.cpp @@ -14,6 +14,7 @@ namespace r = bredis; namespace asio = boost::asio; namespace ep = empty_port; namespace ts = test_server; +namespace sys = boost::system; TEST_CASE("ping", "[connection]") { using socket_t = asio::ip::tcp::socket; @@ -67,12 +68,12 @@ TEST_CASE("ping", "[connection]") { auto rx_buff = Buffer(rx_backend); auto tx_buff = Buffer(tx_backend); read_callback_t read_callback = - [&](const boost::system::error_code &error_code, ParseResult &&r) { - if (error_code) { + [&](const sys::error_code &ec, ParseResult &&r) { + if (ec) { BREDIS_LOG_DEBUG("error: " << error_code.message()); - REQUIRE(!error_code); + REQUIRE(!ec); } - REQUIRE(!error_code); + REQUIRE(!ec); auto &replies = boost::get>(r.result); BREDIS_LOG_DEBUG("callback, size: " << replies.elements.size()); @@ -82,14 +83,14 @@ TEST_CASE("ping", "[connection]") { }; write_callback_t write_callback = [&]( - const boost::system::error_code &error_code, auto bytes_transferred) { + const sys::error_code &ec, std::size_t bytes_transferred) { (void)bytes_transferred; BREDIS_LOG_DEBUG("write_callback"); - if (error_code) { + if (ec) { BREDIS_LOG_DEBUG("error: " << error_code.message()); - REQUIRE(!error_code); + REQUIRE(!ec); } - REQUIRE(!error_code); + REQUIRE(!ec); tx_buff.consume(bytes_transferred); }; From 313abd77b43a2f6ed869c3759ce682aa6fe57877 Mon Sep 17 00:00:00 2001 From: Ivan Baidakou Date: Sat, 10 Aug 2019 12:59:52 +0300 Subject: [PATCH 3/4] example --- examples/speed_test_async_multi.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/speed_test_async_multi.cpp b/examples/speed_test_async_multi.cpp index cc7c2820..ee9842af 100644 --- a/examples/speed_test_async_multi.cpp +++ b/examples/speed_test_async_multi.cpp @@ -47,6 +47,7 @@ double time_s() { // alias namespaces namespace r = bredis; namespace asio = boost::asio; +namespace sys = boost::system; using boost::get; int main(int argc, char **argv) { @@ -62,6 +63,7 @@ int main(int argc, char **argv) { using Iterator = typename r::to_iterator::iterator_t; //using policy_t = r::parsing_policy::drop_result; using policy_t = r::parsing_policy::keep_result; + using result_t = r::positive_parse_result_t; if (argc < 2) { std::cout << "Usage : " << argv[0] << " ip:port \n"; @@ -111,7 +113,7 @@ int main(int argc, char **argv) { c.async_read( rx_buff, - [&](const boost::system::error_code &ec, auto &&r) { + [&](const sys::error_code &ec, result_t &&r) { assert(!ec); (void)ec; rx_buff.consume(r.consumed); @@ -124,8 +126,8 @@ int main(int argc, char **argv) { }, cmds_count, policy_t{}); - c.async_write(tx_buff, cmd_wpapper, [&](const boost::system::error_code &ec, - auto bytes_transferred) { + c.async_write(tx_buff, cmd_wpapper, [&](const sys::error_code &ec, + std::size_t bytes_transferred) { (void)ec; assert(!ec); tx_buff.consume(bytes_transferred); From 30aecfdddb5b7d6984983accf4c1a3443b3724a4 Mon Sep 17 00:00:00 2001 From: Ivan Baidakou Date: Sat, 10 Aug 2019 13:23:08 +0300 Subject: [PATCH 4/4] update doc --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f55f9aa7..bec9b4ac 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,9 @@ Boost::ASIO low-level redis client (connector) ## Changelog +### 0.08 +- relaxed c++ compiler requirements: c++11 can be used instead of c++14 + ### 0.07 - minor parsing speed improvements (upto 10% in synthetic tests) - fix compilation issues on boost::asio 1.70 @@ -213,6 +216,7 @@ in case you don't want the throw-exception behaviour. ... namespace r = bredis; namespace asio = boost::asio; +namespace sys = boost::system; ... using socket_t = asio::ip::tcp::socket; using Buffer = boost::asio::streambuf; @@ -229,10 +233,10 @@ socket.connect(end_point); ... Buffer tx_buff, rx_buff; c.async_write( - tx_buff, r::single_command_t{"llen", "my-queue"}, [&](const auto &error_code, auto bytes_transferred) { + tx_buff, r::single_command_t{"llen", "my-queue"}, [&](const sys::error_code &ec, std::size_t bytes_transferred) { /* tx_buff must be consumed when it is no longer needed */ tx_buff.consume(bytes_transferred); - c.async_read(rx_buff, [&](const auto &error_code, result_t &&r) { + c.async_read(rx_buff, [&](const sys::error_code &ec, result_t &&r) { /* see above how to work with the result */ auto extract = boost::apply_visitor(r::extractor(), r.result); auto &queue_size = boost::get(extract); @@ -350,7 +354,7 @@ in the transaction (i.e. results for `INCR` and `GET` above) ```cpp Buffer rx_buff; -c.async_read(rx_buff, [&](const auto& error_code, auto&& r){ +c.async_read(rx_buff, [&](const sys::error_code &ec, result_t&& r){ auto &replies = boost::get>(r.result); /* scan stream for OK, QUEUED, QUEUED */ ...