Skip to content

Commit c7f49c6

Browse files
committed
Adds address struct.
1 parent 90bcd62 commit c7f49c6

31 files changed

+223
-161
lines changed

CMakePresets.json

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,37 +40,37 @@
4040
}
4141
},
4242
{
43-
"name": "g++-11-cpp17",
43+
"name": "g++-11",
4444
"generator": "Unix Makefiles",
4545
"hidden": false,
4646
"inherits": ["cmake-pedantic"],
47-
"binaryDir": "${sourceDir}/build/g++-11-cpp17",
47+
"binaryDir": "${sourceDir}/build/g++-11",
4848
"cacheVariables": {
4949
"CMAKE_BUILD_TYPE": "Debug",
5050
"CMAKE_CXX_EXTENSIONS": "OFF",
5151
"CMAKE_CXX_FLAGS": "-Wall -Wextra -fsanitize=address",
5252
"CMAKE_CXX_COMPILER": "g++-11",
5353
"CMAKE_SHARED_LINKER_FLAGS": "-fsanitize=address",
5454
"CMAKE_CXX_STANDARD_REQUIRED": "ON",
55-
"PROJECT_BINARY_DIR": "${sourceDir}/build/g++-11-cpp17",
56-
"DOXYGEN_OUTPUT_DIRECTORY": "${sourceDir}/build/g++-11-cpp17/doc/"
55+
"PROJECT_BINARY_DIR": "${sourceDir}/build/g++-11",
56+
"DOXYGEN_OUTPUT_DIRECTORY": "${sourceDir}/build/g++-11/doc/"
5757
}
5858
},
5959
{
60-
"name": "g++-11-cpp20",
60+
"name": "clang++-13",
6161
"generator": "Unix Makefiles",
6262
"hidden": false,
6363
"inherits": ["cmake-pedantic"],
64-
"binaryDir": "${sourceDir}/build/g++-11-cpp20",
64+
"binaryDir": "${sourceDir}/build/clang++-13",
6565
"cacheVariables": {
6666
"CMAKE_BUILD_TYPE": "Debug",
6767
"CMAKE_CXX_EXTENSIONS": "OFF",
6868
"CMAKE_CXX_FLAGS": "-Wall -Wextra -fsanitize=address",
6969
"CMAKE_CXX_COMPILER": "g++-11",
7070
"CMAKE_SHARED_LINKER_FLAGS": "-fsanitize=address",
7171
"CMAKE_CXX_STANDARD_REQUIRED": "ON",
72-
"PROJECT_BINARY_DIR": "${sourceDir}/build/g++-11-cpp20",
73-
"DOXYGEN_OUTPUT_DIRECTORY": "${sourceDir}/build/g++-11-cpp20/doc/"
72+
"PROJECT_BINARY_DIR": "${sourceDir}/build/clang++-13",
73+
"DOXYGEN_OUTPUT_DIRECTORY": "${sourceDir}/build/clang++-13/doc/"
7474
}
7575
},
7676
{
@@ -113,7 +113,7 @@
113113
"name": "clang-tidy",
114114
"generator": "Unix Makefiles",
115115
"hidden": false,
116-
"inherits": ["g++-11-cpp17"],
116+
"inherits": ["g++-11"],
117117
"binaryDir": "${sourceDir}/build/clang-tidy",
118118
"cacheVariables": {
119119
"CMAKE_CXX_CLANG_TIDY": "clang-tidy;--header-filter=${sourceDir}/include/*",
@@ -123,8 +123,8 @@
123123
],
124124
"buildPresets": [
125125
{ "name": "coverage", "configurePreset": "coverage" },
126-
{ "name": "g++-11-cpp17", "configurePreset": "g++-11-cpp17" },
127-
{ "name": "g++-11-cpp20", "configurePreset": "g++-11-cpp20" },
126+
{ "name": "g++-11", "configurePreset": "g++-11" },
127+
{ "name": "clang++-13", "configurePreset": "clang++-13" },
128128
{ "name": "libc++-14-cpp17", "configurePreset": "libc++-14-cpp17" },
129129
{ "name": "libc++-14-cpp20", "configurePreset": "libc++-14-cpp20" },
130130
{ "name": "clang-tidy", "configurePreset": "clang-tidy" }
@@ -136,10 +136,11 @@
136136
"output": {"outputOnFailure": true},
137137
"execution": {"noTestsAction": "error", "stopOnFailure": true}
138138
},
139-
{ "name": "coverage", "configurePreset": "coverage", "inherits": ["test"] },
140-
{ "name": "g++-11-cpp17", "configurePreset": "g++-11-cpp17", "inherits": ["test"] },
141-
{ "name": "libc++-14-cpp17", "configurePreset": "libc++-14-cpp17", "inherits": ["test"] },
142-
{ "name": "libc++-14-cpp20", "configurePreset": "libc++-14-cpp20", "inherits": ["test"] },
143-
{ "name": "clang-tidy", "configurePreset": "clang-tidy", "inherits": ["test"] }
139+
{ "name": "coverage", "configurePreset": "coverage", "inherits": ["test"] },
140+
{ "name": "g++-11", "configurePreset": "g++-11", "inherits": ["test"] },
141+
{ "name": "clang++-13", "configurePreset": "clang++-13", "inherits": ["test"] },
142+
{ "name": "libc++-14-cpp17", "configurePreset": "libc++-14-cpp17", "inherits": ["test"] },
143+
{ "name": "libc++-14-cpp20", "configurePreset": "libc++-14-cpp20", "inherits": ["test"] },
144+
{ "name": "clang-tidy", "configurePreset": "clang-tidy", "inherits": ["test"] }
144145
]
145146
}

examples/cpp17_intro.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
*/
66

77
#include <iostream>
8-
#include <boost/redis.hpp>
8+
#include <boost/redis/run.hpp>
9+
#include <boost/redis/address.hpp>
910
#include <boost/redis/src.hpp>
1011

1112
namespace net = boost::asio;
@@ -14,17 +15,17 @@ using boost::redis::request;
1415
using boost::redis::response;
1516
using boost::redis::ignore_t;
1617
using boost::redis::async_run;
18+
using boost::redis::address;
1719
using namespace std::chrono_literals;
1820

1921
auto main(int argc, char * argv[]) -> int
2022
{
2123
try {
22-
std::string host = "127.0.0.1";
23-
std::string port = "6379";
24+
address addr;
2425

2526
if (argc == 3) {
26-
host = argv[1];
27-
port = argv[2];
27+
addr.host = argv[1];
28+
addr.port = argv[2];
2829
}
2930

3031
// The request
@@ -38,7 +39,7 @@ auto main(int argc, char * argv[]) -> int
3839
net::io_context ioc;
3940
connection conn{ioc};
4041

41-
async_run(conn, host, port, 10s, 10s, [&](auto){
42+
async_run(conn, addr, 10s, 10s, [&](auto){
4243
conn.cancel();
4344
});
4445

examples/cpp17_intro_sync.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ using boost::redis::request;
2626
using boost::redis::response;
2727
using boost::redis::ignore_t;
2828
using boost::redis::async_run;
29+
using boost::redis::address;
2930
using boost::redis::async_check_health;
3031
using namespace std::chrono_literals;
3132

@@ -41,12 +42,11 @@ auto exec(std::shared_ptr<connection> conn, request const& req, Response& resp)
4142
auto main(int argc, char * argv[]) -> int
4243
{
4344
try {
44-
std::string host = "127.0.0.1";
45-
std::string port = "6379";
45+
address addr;
4646

4747
if (argc == 3) {
48-
host = argv[1];
49-
port = argv[2];
48+
addr.host = argv[1];
49+
addr.port = argv[2];
5050
}
5151

5252
net::io_context ioc{1};
@@ -55,8 +55,8 @@ auto main(int argc, char * argv[]) -> int
5555

5656
// Starts a thread that will can io_context::run on which the
5757
// connection will run.
58-
std::thread t{[&ioc, conn, host, port]() {
59-
async_run(*conn, host, port, 10s, 10s, [conn](auto){
58+
std::thread t{[&ioc, conn, addr]() {
59+
async_run(*conn, addr, 10s, 10s, [conn](auto){
6060
conn->cancel();
6161
});
6262

examples/cpp20_chat_room.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
#include <boost/asio/use_awaitable.hpp>
1010
#include <boost/asio/signal_set.hpp>
1111
#include <boost/asio/posix/stream_descriptor.hpp>
12-
#include <boost/asio/experimental/awaitable_operators.hpp>
1312
#include <unistd.h>
1413
#include <iostream>
14+
1515
#if defined(BOOST_ASIO_HAS_CO_AWAIT)
16+
#include <boost/asio/experimental/awaitable_operators.hpp>
1617
#if defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
1718

1819
namespace net = boost::asio;
@@ -23,6 +24,7 @@ using boost::redis::request;
2324
using boost::redis::generic_response;
2425
using boost::redis::async_check_health;
2526
using boost::redis::async_run;
27+
using boost::redis::address;
2628
using connection = net::use_awaitable_t<>::as_default_on_t<boost::redis::connection>;
2729

2830
// Chat over Redis pubsub. To test, run this program from multiple
@@ -51,7 +53,7 @@ auto publisher(std::shared_ptr<stream_descriptor> in, std::shared_ptr<connection
5153
}
5254

5355
// Called from the main function (see main.cpp)
54-
auto co_main(std::string host, std::string port) -> net::awaitable<void>
56+
auto co_main(address const& addr) -> net::awaitable<void>
5557
{
5658
auto ex = co_await net::this_coro::executor;
5759
auto conn = std::make_shared<connection>(ex);
@@ -62,13 +64,13 @@ auto co_main(std::string host, std::string port) -> net::awaitable<void>
6264
req.push("HELLO", 3);
6365
req.push("SUBSCRIBE", "chat-channel");
6466

65-
co_await ((async_run(*conn, host, port) || publisher(stream, conn) || receiver(conn) ||
67+
co_await ((async_run(*conn, addr) || publisher(stream, conn) || receiver(conn) ||
6668
async_check_health(*conn) || sig.async_wait()) &&
6769
conn->async_exec(req));
6870
}
6971

7072
#else // defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
71-
auto co_main(std::string host, std::string port) -> net::awaitable<void>
73+
auto co_main(address const&) -> net::awaitable<void>
7274
{
7375
std::cout << "Requires support for posix streams." << std::endl;
7476
co_return;

examples/cpp20_containers.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ using boost::redis::request;
2020
using boost::redis::response;
2121
using boost::redis::ignore_t;
2222
using boost::redis::async_run;
23+
using boost::redis::address;
2324
using connection = boost::asio::use_awaitable_t<>::as_default_on_t<boost::redis::connection>;
2425

2526
void print(std::map<std::string, std::string> const& cont)
@@ -34,9 +35,9 @@ void print(std::vector<int> const& cont)
3435
std::cout << "\n";
3536
}
3637

37-
auto run(std::shared_ptr<connection> conn, std::string host, std::string port) -> net::awaitable<void>
38+
auto run(std::shared_ptr<connection> conn, address const& addr) -> net::awaitable<void>
3839
{
39-
co_await async_run(*conn, host, port);
40+
co_await async_run(*conn, addr);
4041
}
4142

4243
// Stores the content of some STL containers in Redis.
@@ -105,11 +106,11 @@ auto quit(std::shared_ptr<connection> conn) -> net::awaitable<void>
105106
}
106107

107108
// Called from the main function (see main.cpp)
108-
net::awaitable<void> co_main(std::string host, std::string port)
109+
net::awaitable<void> co_main(address const& addr)
109110
{
110111
auto ex = co_await net::this_coro::executor;
111112
auto conn = std::make_shared<connection>(ex);
112-
net::co_spawn(ex, run(conn, host, port), net::detached);
113+
net::co_spawn(ex, run(conn, addr), net::detached);
113114
co_await store(conn);
114115
co_await transaction(conn);
115116
co_await hgetall(conn);

examples/cpp20_echo_server.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
#include <boost/asio/use_awaitable.hpp>
1010
#include <boost/asio/signal_set.hpp>
1111
#include <boost/asio/detached.hpp>
12-
#include <boost/asio/experimental/awaitable_operators.hpp>
1312

1413
#if defined(BOOST_ASIO_HAS_CO_AWAIT)
14+
#include <boost/asio/experimental/awaitable_operators.hpp>
1515

1616
namespace net = boost::asio;
1717
using namespace net::experimental::awaitable_operators;
@@ -22,7 +22,8 @@ using boost::redis::request;
2222
using boost::redis::response;
2323
using boost::redis::async_check_health;
2424
using boost::redis::async_run;
25-
using connection = boost::asio::use_awaitable_t<>::as_default_on_t<boost::redis::connection>;
25+
using boost::redis::address;
26+
using connection = net::use_awaitable_t<>::as_default_on_t<boost::redis::connection>;
2627

2728
auto echo_server_session(tcp_socket socket, std::shared_ptr<connection> conn) -> net::awaitable<void>
2829
{
@@ -50,7 +51,7 @@ auto listener(std::shared_ptr<connection> conn) -> net::awaitable<void>
5051
}
5152

5253
// Called from the main function (see main.cpp)
53-
auto co_main(std::string host, std::string port) -> net::awaitable<void>
54+
auto co_main(address const& addr) -> net::awaitable<void>
5455
{
5556
auto ex = co_await net::this_coro::executor;
5657
auto conn = std::make_shared<connection>(ex);
@@ -59,7 +60,7 @@ auto co_main(std::string host, std::string port) -> net::awaitable<void>
5960
request req;
6061
req.push("HELLO", 3);
6162

62-
co_await ((async_run(*conn, host, port) || listener(conn) || async_check_health(*conn) ||
63+
co_await ((async_run(*conn, addr) || listener(conn) || async_check_health(*conn) ||
6364
sig.async_wait()) && conn->async_exec(req));
6465
}
6566

examples/cpp20_intro.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,24 @@ using boost::redis::request;
1717
using boost::redis::response;
1818
using boost::redis::ignore_t;
1919
using boost::redis::async_run;
20-
using connection = boost::asio::use_awaitable_t<>::as_default_on_t<boost::redis::connection>;
20+
using boost::redis::address;
21+
using connection = net::use_awaitable_t<>::as_default_on_t<boost::redis::connection>;
2122

22-
auto run(std::shared_ptr<connection> conn, std::string host, std::string port) -> net::awaitable<void>
23+
auto run(std::shared_ptr<connection> conn, address addr) -> net::awaitable<void>
2324
{
2425
// async_run coordinate read and write operations.
25-
co_await async_run(*conn, host, port);
26+
co_await async_run(*conn, addr);
2627

2728
// Cancel pending operations, if any.
2829
conn->cancel();
2930
}
3031

3132
// Called from the main function (see main.cpp)
32-
auto co_main(std::string host, std::string port) -> net::awaitable<void>
33+
auto co_main(address const& addr) -> net::awaitable<void>
3334
{
3435
auto ex = co_await net::this_coro::executor;
3536
auto conn = std::make_shared<connection>(ex);
36-
net::co_spawn(ex, run(conn, host, port), net::detached);
37+
net::co_spawn(ex, run(conn, addr), net::detached);
3738

3839
// A request can contain multiple commands.
3940
request req;

examples/cpp20_intro_awaitable_ops.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@
66

77
#include <boost/redis/run.hpp>
88
#include <boost/asio/use_awaitable.hpp>
9-
#include <boost/asio/experimental/awaitable_operators.hpp>
109
#include <iostream>
10+
1111
#if defined(BOOST_ASIO_HAS_CO_AWAIT)
12+
#include <boost/asio/experimental/awaitable_operators.hpp>
1213

1314
namespace net = boost::asio;
1415
using namespace net::experimental::awaitable_operators;
1516
using boost::redis::request;
1617
using boost::redis::response;
1718
using boost::redis::ignore_t;
1819
using boost::redis::async_run;
20+
using boost::redis::address;
1921
using connection = boost::asio::use_awaitable_t<>::as_default_on_t<boost::redis::connection>;
2022

2123
// Called from the main function (see main.cpp)
22-
auto co_main(std::string host, std::string port) -> net::awaitable<void>
24+
auto co_main(address const& addr) -> net::awaitable<void>
2325
{
2426
try {
2527
request req;
@@ -30,7 +32,7 @@ auto co_main(std::string host, std::string port) -> net::awaitable<void>
3032
response<ignore_t, std::string, ignore_t> resp;
3133

3234
connection conn{co_await net::this_coro::executor};
33-
co_await (async_run(conn, host, port) || conn.async_exec(req, resp));
35+
co_await (async_run(conn, addr) || conn.async_exec(req, resp));
3436

3537
std::cout << "PING: " << std::get<1>(resp).value() << std::endl;
3638
} catch (std::exception const& e) {

examples/cpp20_intro_tls.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66

77
#include <boost/redis/ssl/connection.hpp>
88
#include <boost/redis/ssl/connection.hpp>
9+
#include <boost/redis/address.hpp>
910
#include <boost/asio/use_awaitable.hpp>
10-
#include <boost/asio/experimental/awaitable_operators.hpp>
1111
#include <boost/asio/ssl.hpp>
1212
#include <boost/asio/connect.hpp>
1313
#include <tuple>
1414
#include <string>
1515
#include <iostream>
1616

1717
#if defined(BOOST_ASIO_HAS_CO_AWAIT)
18+
#include <boost/asio/experimental/awaitable_operators.hpp>
1819

1920
namespace net = boost::asio;
2021
namespace redis = boost::redis;
@@ -24,14 +25,15 @@ using connection = net::use_awaitable_t<>::as_default_on_t<redis::ssl::connectio
2425
using boost::redis::request;
2526
using boost::redis::response;
2627
using boost::redis::ignore_t;
28+
using boost::redis::address;
2729

2830
auto verify_certificate(bool, net::ssl::verify_context&) -> bool
2931
{
3032
std::cout << "set_verify_callback" << std::endl;
3133
return true;
3234
}
3335

34-
net::awaitable<void> co_main(std::string, std::string)
36+
net::awaitable<void> co_main(address const&)
3537
{
3638
request req;
3739
req.push("HELLO", 3, "AUTH", "aedis", "aedis");

0 commit comments

Comments
 (0)