Skip to content

Commit 44a608c

Browse files
authored
Merge pull request #151 from boostorg/150-remove-resp3read-and-resp3async_read
Removes resp3::async_read.
2 parents d8cf431 + 1ed8e01 commit 44a608c

18 files changed

+316
-761
lines changed

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ if (BOOST_REDIS_TESTS)
162162
make_test(test_conn_exec_error 17)
163163
make_test(test_request 17)
164164
make_test(test_run 17)
165-
make_test(test_low_level_sync 17)
166165
make_test(test_low_level_sync_sans_io 17)
167166
make_test(test_conn_check_health 17)
168167

@@ -172,7 +171,6 @@ if (BOOST_REDIS_TESTS)
172171
make_test(test_conn_exec_cancel 20)
173172
make_test(test_conn_exec_cancel2 20)
174173
make_test(test_conn_echo_stress 20)
175-
make_test(test_low_level_async 20)
176174
make_test(test_conn_run_cancel 20)
177175
make_test(test_issue_50 20)
178176
endif()

examples/cpp17_intro.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <boost/asio/detached.hpp>
99
#include <iostream>
1010

11-
namespace net = boost::asio;
11+
namespace asio = boost::asio;
1212
using boost::redis::connection;
1313
using boost::redis::request;
1414
using boost::redis::response;
@@ -29,10 +29,10 @@ auto main(int argc, char * argv[]) -> int
2929

3030
response<std::string> resp;
3131

32-
net::io_context ioc;
32+
asio::io_context ioc;
3333
connection conn{ioc};
3434

35-
conn.async_run(cfg, {}, net::detached);
35+
conn.async_run(cfg, {}, asio::detached);
3636

3737
conn.async_exec(req, resp, [&](auto ec, auto) {
3838
if (!ec)

examples/cpp17_intro_sync.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <string>
1010
#include <iostream>
1111

12-
namespace net = boost::asio;
1312
using boost::redis::sync_connection;
1413
using boost::redis::request;
1514
using boost::redis::response;

examples/cpp20_chat_room.cpp

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,31 @@
1717
#if defined(BOOST_ASIO_HAS_CO_AWAIT)
1818
#if defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
1919

20-
namespace net = boost::asio;
21-
using stream_descriptor = net::deferred_t::as_default_on_t<net::posix::stream_descriptor>;
22-
using signal_set = net::deferred_t::as_default_on_t<net::signal_set>;
23-
using boost::redis::request;
24-
using boost::redis::generic_response;
20+
namespace asio = boost::asio;
21+
using stream_descriptor = asio::deferred_t::as_default_on_t<asio::posix::stream_descriptor>;
22+
using signal_set = asio::deferred_t::as_default_on_t<asio::signal_set>;
23+
using boost::asio::async_read_until;
24+
using boost::asio::awaitable;
25+
using boost::asio::co_spawn;
26+
using boost::asio::consign;
27+
using boost::asio::deferred;
28+
using boost::asio::detached;
29+
using boost::asio::dynamic_buffer;
30+
using boost::asio::redirect_error;
31+
using boost::asio::use_awaitable;
2532
using boost::redis::config;
2633
using boost::redis::connection;
34+
using boost::redis::generic_response;
2735
using boost::redis::ignore;
28-
using net::redirect_error;
29-
using net::use_awaitable;
36+
using boost::redis::request;
3037
using boost::system::error_code;
3138
using namespace std::chrono_literals;
3239

3340
// Chat over Redis pubsub. To test, run this program from multiple
3441
// terminals and type messages to stdin.
3542

3643
auto
37-
receiver(std::shared_ptr<connection> conn) -> net::awaitable<void>
44+
receiver(std::shared_ptr<connection> conn) -> awaitable<void>
3845
{
3946
request req;
4047
req.push("SUBSCRIBE", "channel");
@@ -45,7 +52,7 @@ receiver(std::shared_ptr<connection> conn) -> net::awaitable<void>
4552
while (conn->will_reconnect()) {
4653

4754
// Subscribe to channels.
48-
co_await conn->async_exec(req, ignore, net::deferred);
55+
co_await conn->async_exec(req, ignore, deferred);
4956

5057
// Loop reading Redis push messages.
5158
for (error_code ec;;) {
@@ -63,27 +70,27 @@ receiver(std::shared_ptr<connection> conn) -> net::awaitable<void>
6370
}
6471

6572
// Publishes stdin messages to a Redis channel.
66-
auto publisher(std::shared_ptr<stream_descriptor> in, std::shared_ptr<connection> conn) -> net::awaitable<void>
73+
auto publisher(std::shared_ptr<stream_descriptor> in, std::shared_ptr<connection> conn) -> awaitable<void>
6774
{
6875
for (std::string msg;;) {
69-
auto n = co_await net::async_read_until(*in, net::dynamic_buffer(msg, 1024), "\n");
76+
auto n = co_await async_read_until(*in, dynamic_buffer(msg, 1024), "\n");
7077
request req;
7178
req.push("PUBLISH", "channel", msg);
72-
co_await conn->async_exec(req, ignore, net::deferred);
79+
co_await conn->async_exec(req, ignore, deferred);
7380
msg.erase(0, n);
7481
}
7582
}
7683

7784
// Called from the main function (see main.cpp)
78-
auto co_main(config cfg) -> net::awaitable<void>
85+
auto co_main(config cfg) -> awaitable<void>
7986
{
80-
auto ex = co_await net::this_coro::executor;
87+
auto ex = co_await asio::this_coro::executor;
8188
auto conn = std::make_shared<connection>(ex);
8289
auto stream = std::make_shared<stream_descriptor>(ex, ::dup(STDIN_FILENO));
8390

84-
net::co_spawn(ex, receiver(conn), net::detached);
85-
net::co_spawn(ex, publisher(stream, conn), net::detached);
86-
conn->async_run(cfg, {}, net::consign(net::detached, conn));
91+
co_spawn(ex, receiver(conn), detached);
92+
co_spawn(ex, publisher(stream, conn), detached);
93+
conn->async_run(cfg, {}, consign(detached, conn));
8794

8895
signal_set sig_set{ex, SIGINT, SIGTERM};
8996
co_await sig_set.async_wait();
@@ -92,7 +99,7 @@ auto co_main(config cfg) -> net::awaitable<void>
9299
}
93100

94101
#else // defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
95-
auto co_main(config const&) -> net::awaitable<void>
102+
auto co_main(config const&) -> awaitable<void>
96103
{
97104
std::cout << "Requires support for posix streams." << std::endl;
98105
co_return;

examples/cpp20_containers.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@
1414

1515
#if defined(BOOST_ASIO_HAS_CO_AWAIT)
1616

17-
namespace net = boost::asio;
17+
namespace asio = boost::asio;
1818
using boost::redis::request;
1919
using boost::redis::response;
2020
using boost::redis::ignore_t;
2121
using boost::redis::ignore;
2222
using boost::redis::config;
2323
using boost::redis::connection;
24+
using boost::asio::awaitable;
25+
using boost::asio::deferred;
26+
using boost::asio::detached;
27+
using boost::asio::consign;
2428

2529
void print(std::map<std::string, std::string> const& cont)
2630
{
@@ -35,7 +39,7 @@ void print(std::vector<int> const& cont)
3539
}
3640

3741
// Stores the content of some STL containers in Redis.
38-
auto store(std::shared_ptr<connection> conn) -> net::awaitable<void>
42+
auto store(std::shared_ptr<connection> conn) -> awaitable<void>
3943
{
4044
std::vector<int> vec
4145
{1, 2, 3, 4, 5, 6};
@@ -47,10 +51,10 @@ auto store(std::shared_ptr<connection> conn) -> net::awaitable<void>
4751
req.push_range("RPUSH", "rpush-key", vec);
4852
req.push_range("HSET", "hset-key", map);
4953

50-
co_await conn->async_exec(req, ignore, net::deferred);
54+
co_await conn->async_exec(req, ignore, deferred);
5155
}
5256

53-
auto hgetall(std::shared_ptr<connection> conn) -> net::awaitable<void>
57+
auto hgetall(std::shared_ptr<connection> conn) -> awaitable<void>
5458
{
5559
// A request contains multiple commands.
5660
request req;
@@ -60,13 +64,13 @@ auto hgetall(std::shared_ptr<connection> conn) -> net::awaitable<void>
6064
response<std::map<std::string, std::string>> resp;
6165

6266
// Executes the request and reads the response.
63-
co_await conn->async_exec(req, resp, net::deferred);
67+
co_await conn->async_exec(req, resp, deferred);
6468

6569
print(std::get<0>(resp).value());
6670
}
6771

6872
// Retrieves in a transaction.
69-
auto transaction(std::shared_ptr<connection> conn) -> net::awaitable<void>
73+
auto transaction(std::shared_ptr<connection> conn) -> awaitable<void>
7074
{
7175
request req;
7276
req.push("MULTI");
@@ -81,17 +85,17 @@ auto transaction(std::shared_ptr<connection> conn) -> net::awaitable<void>
8185
response<std::optional<std::vector<int>>, std::optional<std::map<std::string, std::string>>> // exec
8286
> resp;
8387

84-
co_await conn->async_exec(req, resp, net::deferred);
88+
co_await conn->async_exec(req, resp, deferred);
8589

8690
print(std::get<0>(std::get<3>(resp).value()).value().value());
8791
print(std::get<1>(std::get<3>(resp).value()).value().value());
8892
}
8993

9094
// Called from the main function (see main.cpp)
91-
net::awaitable<void> co_main(config cfg)
95+
awaitable<void> co_main(config cfg)
9296
{
93-
auto conn = std::make_shared<connection>(co_await net::this_coro::executor);
94-
conn->async_run(cfg, {}, net::consign(net::detached, conn));
97+
auto conn = std::make_shared<connection>(co_await asio::this_coro::executor);
98+
conn->async_run(cfg, {}, consign(detached, conn));
9599

96100
co_await store(conn);
97101
co_await transaction(conn);

examples/cpp20_echo_server.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,53 +14,53 @@
1414

1515
#if defined(BOOST_ASIO_HAS_CO_AWAIT)
1616

17-
namespace net = boost::asio;
18-
using tcp_socket = net::deferred_t::as_default_on_t<net::ip::tcp::socket>;
19-
using tcp_acceptor = net::deferred_t::as_default_on_t<net::ip::tcp::acceptor>;
20-
using signal_set = net::deferred_t::as_default_on_t<net::signal_set>;
17+
namespace asio = boost::asio;
18+
using tcp_socket = asio::deferred_t::as_default_on_t<asio::ip::tcp::socket>;
19+
using tcp_acceptor = asio::deferred_t::as_default_on_t<asio::ip::tcp::acceptor>;
20+
using signal_set = asio::deferred_t::as_default_on_t<asio::signal_set>;
2121
using boost::redis::request;
2222
using boost::redis::response;
2323
using boost::redis::config;
2424
using boost::system::error_code;
2525
using boost::redis::connection;
2626
using namespace std::chrono_literals;
2727

28-
auto echo_server_session(tcp_socket socket, std::shared_ptr<connection> conn) -> net::awaitable<void>
28+
auto echo_server_session(tcp_socket socket, std::shared_ptr<connection> conn) -> asio::awaitable<void>
2929
{
3030
request req;
3131
response<std::string> resp;
3232

3333
for (std::string buffer;;) {
34-
auto n = co_await net::async_read_until(socket, net::dynamic_buffer(buffer, 1024), "\n");
34+
auto n = co_await asio::async_read_until(socket, asio::dynamic_buffer(buffer, 1024), "\n");
3535
req.push("PING", buffer);
36-
co_await conn->async_exec(req, resp, net::deferred);
37-
co_await net::async_write(socket, net::buffer(std::get<0>(resp).value()));
36+
co_await conn->async_exec(req, resp, asio::deferred);
37+
co_await asio::async_write(socket, asio::buffer(std::get<0>(resp).value()));
3838
std::get<0>(resp).value().clear();
3939
req.clear();
4040
buffer.erase(0, n);
4141
}
4242
}
4343

4444
// Listens for tcp connections.
45-
auto listener(std::shared_ptr<connection> conn) -> net::awaitable<void>
45+
auto listener(std::shared_ptr<connection> conn) -> asio::awaitable<void>
4646
{
4747
try {
48-
auto ex = co_await net::this_coro::executor;
49-
tcp_acceptor acc(ex, {net::ip::tcp::v4(), 55555});
48+
auto ex = co_await asio::this_coro::executor;
49+
tcp_acceptor acc(ex, {asio::ip::tcp::v4(), 55555});
5050
for (;;)
51-
net::co_spawn(ex, echo_server_session(co_await acc.async_accept(), conn), net::detached);
51+
asio::co_spawn(ex, echo_server_session(co_await acc.async_accept(), conn), asio::detached);
5252
} catch (std::exception const& e) {
5353
std::clog << "Listener: " << e.what() << std::endl;
5454
}
5555
}
5656

5757
// Called from the main function (see main.cpp)
58-
auto co_main(config cfg) -> net::awaitable<void>
58+
auto co_main(config cfg) -> asio::awaitable<void>
5959
{
60-
auto ex = co_await net::this_coro::executor;
60+
auto ex = co_await asio::this_coro::executor;
6161
auto conn = std::make_shared<connection>(ex);
62-
net::co_spawn(ex, listener(conn), net::detached);
63-
conn->async_run(cfg, {}, net::consign(net::detached, conn));
62+
asio::co_spawn(ex, listener(conn), asio::detached);
63+
conn->async_run(cfg, {}, asio::consign(asio::detached, conn));
6464

6565
signal_set sig_set(ex, SIGINT, SIGTERM);
6666
co_await sig_set.async_wait();

examples/cpp20_intro.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313

1414
#if defined(BOOST_ASIO_HAS_CO_AWAIT)
1515

16-
namespace net = boost::asio;
16+
namespace asio = boost::asio;
1717
using boost::redis::request;
1818
using boost::redis::response;
1919
using boost::redis::config;
2020
using boost::redis::connection;
2121

2222
// Called from the main function (see main.cpp)
23-
auto co_main(config cfg) -> net::awaitable<void>
23+
auto co_main(config cfg) -> asio::awaitable<void>
2424
{
25-
auto conn = std::make_shared<connection>(co_await net::this_coro::executor);
26-
conn->async_run(cfg, {}, net::consign(net::detached, conn));
25+
auto conn = std::make_shared<connection>(co_await asio::this_coro::executor);
26+
conn->async_run(cfg, {}, asio::consign(asio::detached, conn));
2727

2828
// A request containing only a ping command.
2929
request req;
@@ -33,7 +33,7 @@ auto co_main(config cfg) -> net::awaitable<void>
3333
response<std::string> resp;
3434

3535
// Executes the request.
36-
co_await conn->async_exec(req, resp, net::deferred);
36+
co_await conn->async_exec(req, resp, asio::deferred);
3737
conn->cancel();
3838

3939
std::cout << "PING: " << std::get<0>(resp).value() << std::endl;

examples/cpp20_intro_tls.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,39 @@
1313

1414
#if defined(BOOST_ASIO_HAS_CO_AWAIT)
1515

16-
namespace net = boost::asio;
16+
namespace asio = boost::asio;
1717
using boost::redis::request;
1818
using boost::redis::response;
1919
using boost::redis::config;
2020
using boost::redis::logger;
2121
using boost::redis::connection;
2222

23-
auto verify_certificate(bool, net::ssl::verify_context&) -> bool
23+
auto verify_certificate(bool, asio::ssl::verify_context&) -> bool
2424
{
2525
std::cout << "set_verify_callback" << std::endl;
2626
return true;
2727
}
2828

29-
auto co_main(config cfg) -> net::awaitable<void>
29+
auto co_main(config cfg) -> asio::awaitable<void>
3030
{
3131
cfg.use_ssl = true;
3232
cfg.username = "aedis";
3333
cfg.password = "aedis";
3434
cfg.addr.host = "db.occase.de";
3535
cfg.addr.port = "6380";
3636

37-
auto conn = std::make_shared<connection>(co_await net::this_coro::executor);
38-
conn->async_run(cfg, {}, net::consign(net::detached, conn));
37+
auto conn = std::make_shared<connection>(co_await asio::this_coro::executor);
38+
conn->async_run(cfg, {}, asio::consign(asio::detached, conn));
3939

4040
request req;
4141
req.push("PING");
4242

4343
response<std::string> resp;
4444

45-
conn->next_layer().set_verify_mode(net::ssl::verify_peer);
45+
conn->next_layer().set_verify_mode(asio::ssl::verify_peer);
4646
conn->next_layer().set_verify_callback(verify_certificate);
4747

48-
co_await conn->async_exec(req, resp, net::deferred);
48+
co_await conn->async_exec(req, resp, asio::deferred);
4949
conn->cancel();
5050

5151
std::cout << "Response: " << std::get<0>(resp).value() << std::endl;

examples/cpp20_json.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <boost/redis/resp3/serialization.hpp>
2424
#include <boost/json/src.hpp>
2525

26-
namespace net = boost::asio;
26+
namespace asio = boost::asio;
2727
using namespace boost::describe;
2828
using boost::redis::request;
2929
using boost::redis::response;
@@ -48,11 +48,11 @@ void boost_redis_to_bulk(std::string& to, user const& u)
4848
void boost_redis_from_bulk(user& u, std::string_view sv, boost::system::error_code&)
4949
{ u = boost::json::value_to<user>(boost::json::parse(sv)); }
5050

51-
auto co_main(config cfg) -> net::awaitable<void>
51+
auto co_main(config cfg) -> asio::awaitable<void>
5252
{
53-
auto ex = co_await net::this_coro::executor;
53+
auto ex = co_await asio::this_coro::executor;
5454
auto conn = std::make_shared<connection>(ex);
55-
conn->async_run(cfg, {}, net::consign(net::detached, conn));
55+
conn->async_run(cfg, {}, asio::consign(asio::detached, conn));
5656

5757
// user object that will be stored in Redis in json format.
5858
user const u{"Joao", "58", "Brazil"};
@@ -64,7 +64,7 @@ auto co_main(config cfg) -> net::awaitable<void>
6464

6565
response<ignore_t, user> resp;
6666

67-
co_await conn->async_exec(req, resp, net::deferred);
67+
co_await conn->async_exec(req, resp, asio::deferred);
6868
conn->cancel();
6969

7070
// Prints the first ping

0 commit comments

Comments
 (0)