Skip to content

Commit 15b0202

Browse files
authored
Merge pull request #33 from basiliscos/ivan/issue-32
relax requirements: use c++11 instead c++14
2 parents 9efae77 + 30aecfd commit 15b0202

18 files changed

+174
-133
lines changed

CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
cmake_minimum_required(VERSION 3.0)
22
project (bredis)
33

4-
set(CMAKE_CXX_STANDARD 14)
4+
set(CMAKE_CXX_STANDARD 11)
55
set(CMAKE_CXX_STANDARD_REQUIRED ON)
66

77
include (CTest)
88
enable_testing()
99

1010

11-
1211
add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY)
1312
add_definitions(-DBOOST_COROUTINES_NO_DEPRECATION_WARNING)
1413
#add_definitions(-DBREDIS_DEBUG)

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Boost::ASIO low-level redis client (connector)
1818

1919
## Changelog
2020

21+
### 0.08
22+
- relaxed c++ compiler requirements: c++11 can be used instead of c++14
23+
2124
### 0.07
2225
- minor parsing speed improvements (upto 10% in synthetic tests)
2326
- fix compilation issues on boost::asio 1.70
@@ -213,6 +216,7 @@ in case you don't want the throw-exception behaviour.
213216
...
214217
namespace r = bredis;
215218
namespace asio = boost::asio;
219+
namespace sys = boost::system;
216220
...
217221
using socket_t = asio::ip::tcp::socket;
218222
using Buffer = boost::asio::streambuf;
@@ -229,10 +233,10 @@ socket.connect(end_point);
229233
...
230234
Buffer tx_buff, rx_buff;
231235
c.async_write(
232-
tx_buff, r::single_command_t{"llen", "my-queue"}, [&](const auto &error_code, auto bytes_transferred) {
236+
tx_buff, r::single_command_t{"llen", "my-queue"}, [&](const sys::error_code &ec, std::size_t bytes_transferred) {
233237
/* tx_buff must be consumed when it is no longer needed */
234238
tx_buff.consume(bytes_transferred);
235-
c.async_read(rx_buff, [&](const auto &error_code, result_t &&r) {
239+
c.async_read(rx_buff, [&](const sys::error_code &ec, result_t &&r) {
236240
/* see above how to work with the result */
237241
auto extract = boost::apply_visitor(r::extractor<Iterator>(), r.result);
238242
auto &queue_size = boost::get<r::extracts::int_t>(extract);
@@ -350,7 +354,7 @@ in the transaction (i.e. results for `INCR` and `GET` above)
350354
351355
```cpp
352356
Buffer rx_buff;
353-
c.async_read(rx_buff, [&](const auto& error_code, auto&& r){
357+
c.async_read(rx_buff, [&](const sys::error_code &ec, result_t&& r){
354358
auto &replies = boost::get<r::markers::array_holder_t<Iterator>>(r.result);
355359
/* scan stream for OK, QUEUED, QUEUED */
356360
...

examples/multi-threads-1.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,15 @@
3535
namespace r = bredis;
3636
namespace asio = boost::asio;
3737
namespace po = boost::program_options;
38+
namespace sys = boost::system;
3839

3940
using socket_t = asio::ip::tcp::socket;
4041
using next_layer_t = socket_t;
4142
//using next_layer_t = r::test::SocketWithLogging<asio::ip::tcp::socket>;
4243
using Buffer = boost::asio::streambuf;
4344
using Iterator = typename r::to_iterator<Buffer>::iterator_t;
45+
using Policy = r::parsing_policy::keep_result;
46+
using result_t = r::positive_parse_result_t<Iterator, Policy>;
4447
using Connection = r::Connection<next_layer_t>;
4548

4649
struct redis_accessor_t {
@@ -64,8 +67,9 @@ struct producer_t {
6467
redis.conn.async_write(
6568
redis.tx_buff,
6669
cmd_ping,
67-
asio::bind_executor(redis.strand, [self = this](const auto &error_code, size_t bytes_transferred){
68-
if (!error_code){
70+
asio::bind_executor(redis.strand, [this](const sys::error_code &ec, std::size_t bytes_transferred){
71+
if (!ec){
72+
auto self = this;
6973
self->redis.ping_count++;
7074
self->redis.tx_buff.consume(bytes_transferred);
7175
self->produce();
@@ -83,8 +87,9 @@ struct consumer_t {
8387
void consume(){
8488
redis.conn.async_read(
8589
redis.rx_buff,
86-
asio::bind_executor(redis.strand, [self = this](const auto &error_code, auto &&r){
87-
if(!error_code){
90+
asio::bind_executor(redis.strand, [this](const sys::error_code &ec, result_t &&r){
91+
if(!ec){
92+
auto self = this;
8893
self->redis.pong_count++;
8994
self->redis.rx_buff.consume(r.consumed);
9095
self->consume();
@@ -103,8 +108,9 @@ struct watcher_t {
103108
void watch() {
104109
timer.expires_after(asio::chrono::seconds(1));
105110
timer.async_wait(
106-
asio::bind_executor(redis.strand, [self = this](const auto &error_code){
107-
if (!error_code) {
111+
asio::bind_executor(redis.strand, [this](const sys::error_code &ec){
112+
if (!ec) {
113+
auto self = this;
108114
std::cout << "pings: " << self->redis.ping_count << ", pongs: " << self->redis.pong_count << "\n";
109115
self->watch();
110116
}

examples/speed_test_async_multi.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ double time_s() {
4747
// alias namespaces
4848
namespace r = bredis;
4949
namespace asio = boost::asio;
50+
namespace sys = boost::system;
5051
using boost::get;
5152

5253
int main(int argc, char **argv) {
@@ -62,6 +63,7 @@ int main(int argc, char **argv) {
6263
using Iterator = typename r::to_iterator<Buffer>::iterator_t;
6364
//using policy_t = r::parsing_policy::drop_result;
6465
using policy_t = r::parsing_policy::keep_result;
66+
using result_t = r::positive_parse_result_t<Iterator, policy_t>;
6567

6668
if (argc < 2) {
6769
std::cout << "Usage : " << argv[0] << " ip:port \n";
@@ -111,7 +113,7 @@ int main(int argc, char **argv) {
111113

112114
c.async_read(
113115
rx_buff,
114-
[&](const boost::system::error_code &ec, auto &&r) {
116+
[&](const sys::error_code &ec, result_t &&r) {
115117
assert(!ec);
116118
(void)ec;
117119
rx_buff.consume(r.consumed);
@@ -124,8 +126,8 @@ int main(int argc, char **argv) {
124126
},
125127
cmds_count, policy_t{});
126128

127-
c.async_write(tx_buff, cmd_wpapper, [&](const boost::system::error_code &ec,
128-
auto bytes_transferred) {
129+
c.async_write(tx_buff, cmd_wpapper, [&](const sys::error_code &ec,
130+
std::size_t bytes_transferred) {
129131
(void)ec;
130132
assert(!ec);
131133
tx_buff.consume(bytes_transferred);

include/bredis/Command.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
//
77
#pragma once
88

9+
#include <boost/core/enable_if.hpp>
910
#include <boost/utility/string_ref.hpp>
1011
#include <boost/variant.hpp>
11-
#include <type_traits>
1212
#include <vector>
1313

1414
#include "Result.hpp"
@@ -31,14 +31,14 @@ struct single_command_t {
3131
args_container_t arguments;
3232

3333
template <typename... Args,
34-
typename = std::enable_if_t<detail::are_all_constructible<
34+
typename = boost::enable_if_t<detail::are_all_constructible<
3535
boost::string_ref, Args...>::value>>
3636
single_command_t(Args &&... args) : arguments{std::forward<Args>(args)...} {
3737
static_assert(sizeof...(Args) >= 1, "Empty command is not allowed");
3838
}
3939

4040
template <typename InputIterator,
41-
typename = std::enable_if_t<std::is_constructible<
41+
typename = boost::enable_if_t<std::is_constructible<
4242
boost::string_ref, typename std::iterator_traits<
4343
InputIterator>::value_type>::value>>
4444
single_command_t(InputIterator first, InputIterator last)

include/bredis/MarkerHelpers.hpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#pragma once
99

1010
#include <algorithm>
11+
#include <boost/algorithm/cxx14/equal.hpp>
1112
#include <boost/convert.hpp>
1213
#include <boost/convert/lexical_cast.hpp>
1314
#include <cctype>
@@ -81,21 +82,22 @@ class equality : public boost::static_visitor<bool> {
8182
}
8283

8384
bool operator()(const markers::string_t<Iterator> &value) const {
84-
auto helper = stringizer<Iterator>();
85-
auto str = helper(value);
86-
return std::equal(begin_, end_, value.from, value.to);
85+
return boost::algorithm::equal(begin_, end_, value.from, value.to);
8786
}
8887

8988
bool operator()(const markers::int_t<Iterator> &value) const {
90-
return std::equal(begin_, end_, value.string.from, value.string.to);
89+
return boost::algorithm::equal(begin_, end_, value.string.from,
90+
value.string.to);
9191
}
9292

9393
bool operator()(const markers::error_t<Iterator> &value) const {
94-
return std::equal(begin_, end_, value.string.from, value.string.to);
94+
return boost::algorithm::equal(begin_, end_, value.string.from,
95+
value.string.to);
9596
}
9697

9798
bool operator()(const markers::nil_t<Iterator> &value) const {
98-
return std::equal(begin_, end_, value.string.from, value.string.to);
99+
return boost::algorithm::equal(begin_, end_, value.string.from,
100+
value.string.to);
99101
}
100102
};
101103

@@ -172,8 +174,8 @@ class check_subscription : public boost::static_visitor<bool> {
172174
}
173175

174176
const auto &channel_ = cmd_.arguments[idx];
175-
return std::equal(channel_.cbegin(), channel_.cend(), channel->from,
176-
channel->to);
177+
return boost::algorithm::equal(channel_.cbegin(), channel_.cend(),
178+
channel->from, channel->to);
177179
}
178180
return false;
179181
}

include/bredis/impl/connection.ipp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
#include "common.ipp"
1111
#include <algorithm>
12+
#include <boost/type_traits/decay.hpp>
1213
#include <cassert>
1314
#include <ostream>
14-
#include <type_traits>
1515

1616
#include "async_op.ipp"
1717

@@ -29,7 +29,7 @@ Connection<NextLayer>::async_write(DynamicBuffer &tx_buff,
2929

3030
using boost::asio::async_write;
3131
using Signature = void(boost::system::error_code, std::size_t);
32-
using Callback = std::decay_t<WriteCallback>;
32+
using Callback = boost::decay_t<WriteCallback>;
3333
using AsyncResult = asio::async_result<Callback, Signature>;
3434
using CompletionHandler = typename AsyncResult::completion_handler_type;
3535
using serializer_t = command_serializer_visitor<DynamicBuffer>;
@@ -58,7 +58,7 @@ Connection<NextLayer>::async_read(DynamicBuffer &rx_buff,
5858
using Iterator = typename to_iterator<DynamicBuffer>::iterator_t;
5959
using ParseResult = BREDIS_PARSE_RESULT(DynamicBuffer, Policy);
6060
using Signature = void(boost::system::error_code, ParseResult);
61-
using Callback = std::decay_t<ReadCallback>;
61+
using Callback = boost::decay_t<ReadCallback>;
6262
using AsyncResult = asio::async_result<Callback, Signature>;
6363
using CompletionHandler = typename AsyncResult::completion_handler_type;
6464
using ReadOp =

t/10-ping.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace r = bredis;
1414
namespace asio = boost::asio;
1515
namespace ep = empty_port;
1616
namespace ts = test_server;
17+
namespace sys = boost::system;
1718

1819
TEST_CASE("ping", "[connection]") {
1920
using socket_t = asio::ip::tcp::socket;
@@ -48,10 +49,11 @@ TEST_CASE("ping", "[connection]") {
4849
Buffer tx_buff, rx_buff;
4950

5051
c.async_write(
51-
tx_buff, "ping", [&](const auto &error_code, auto bytes_transferred) {
52+
tx_buff, "ping",
53+
[&](const sys::error_code &error_code, std::size_t bytes_transferred) {
5254
REQUIRE(!error_code);
5355
tx_buff.consume(bytes_transferred);
54-
c.async_read(rx_buff, [&](const auto&, auto &&r) {
56+
c.async_read(rx_buff, [&](const sys::error_code &, result_t &&r) {
5557
completion_promise.set_value(r);
5658
rx_buff.consume(r.consumed);
5759
});

t/11-multi-ping.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <boost/asio.hpp>
22
#include <future>
3-
#include <vector>
43
#include <string>
4+
#include <vector>
55

66
#include "EmptyPort.hpp"
77
#include "SocketWithLogging.hpp"
@@ -14,6 +14,7 @@ namespace r = bredis;
1414
namespace asio = boost::asio;
1515
namespace ep = empty_port;
1616
namespace ts = test_server;
17+
namespace sys = boost::system;
1718

1819
TEST_CASE("ping", "[connection]") {
1920
using socket_t = asio::ip::tcp::socket;
@@ -59,23 +60,23 @@ TEST_CASE("ping", "[connection]") {
5960
std::future<result_t> completion_future = completion_promise.get_future();
6061

6162
Buffer tx_buff, rx_buff;
62-
read_callback_t read_callback =
63-
[&](const boost::system::error_code &error_code, ParseResult &&r) {
64-
if (error_code) {
65-
BREDIS_LOG_DEBUG("error: " << error_code.message());
66-
REQUIRE(!error_code);
67-
}
63+
read_callback_t read_callback = [&](const sys::error_code &error_code,
64+
ParseResult &&r) {
65+
if (error_code) {
66+
BREDIS_LOG_DEBUG("error: " << error_code.message());
6867
REQUIRE(!error_code);
69-
auto &replies =
70-
boost::get<r::markers::array_holder_t<Iterator>>(r.result);
71-
BREDIS_LOG_DEBUG("callback, size: " << replies.elements.size());
72-
REQUIRE(replies.elements.size() == count);
73-
completion_promise.set_value();
74-
rx_buff.consume(r.consumed);
75-
};
68+
}
69+
REQUIRE(!error_code);
70+
auto &replies =
71+
boost::get<r::markers::array_holder_t<Iterator>>(r.result);
72+
BREDIS_LOG_DEBUG("callback, size: " << replies.elements.size());
73+
REQUIRE(replies.elements.size() == count);
74+
completion_promise.set_value();
75+
rx_buff.consume(r.consumed);
76+
};
7677

77-
write_callback_t write_callback = [&](
78-
const boost::system::error_code &error_code, auto bytes_transferred) {
78+
write_callback_t write_callback = [&](const sys::error_code &error_code,
79+
std::size_t bytes_transferred) {
7980
(void)bytes_transferred;
8081
BREDIS_LOG_DEBUG("write_callback");
8182
if (error_code) {

t/12-basic-types.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace r = bredis;
1515
namespace asio = boost::asio;
1616
namespace ep = empty_port;
1717
namespace ts = test_server;
18+
namespace sys = boost::system;
1819

1920
TEST_CASE("ping", "[connection]") {
2021
using socket_t = asio::ip::tcp::socket;
@@ -64,7 +65,7 @@ TEST_CASE("ping", "[connection]") {
6465
r::single_command_t("time"),
6566
};
6667
std::vector<read_callback_t> callbacks{
67-
[&](const boost::system::error_code&error_code, ParseResult &&r) {
68+
[&](const boost::system::error_code &error_code, ParseResult &&r) {
6869
auto extract = boost::apply_visitor(Extractor(), r.result);
6970
REQUIRE(boost::get<r::extracts::int_t>(extract) == 0);
7071
REQUIRE(order == 0);
@@ -120,12 +121,13 @@ TEST_CASE("ping", "[connection]") {
120121
c.async_read(rx_buff, generic_callback);
121122
};
122123

123-
c.async_write(tx_buff, r::command_wrapper_t(cmds_container),
124-
[&](const auto &error_code, auto bytes_transferred) {
125-
REQUIRE(!error_code);
126-
tx_buff.consume(bytes_transferred);
127-
c.async_read(rx_buff, generic_callback);
128-
});
124+
c.async_write(
125+
tx_buff, r::command_wrapper_t(cmds_container),
126+
[&](const sys::error_code &ec, std::size_t bytes_transferred) {
127+
REQUIRE(!ec);
128+
tx_buff.consume(bytes_transferred);
129+
c.async_read(rx_buff, generic_callback);
130+
});
129131

130132
while (completion_future.wait_for(sleep_delay) !=
131133
std::future_status::ready) {

0 commit comments

Comments
 (0)