diff options
| author | Lee *!* Clagett <code@leeclagett.com> | 2024-12-17 16:40:15 -0500 |
|---|---|---|
| committer | Lee *!* Clagett <code@leeclagett.com> | 2025-02-14 13:29:57 -0500 |
| commit | 01bcd52924244ec8d2a24c10fcef8959289d09ff (patch) | |
| tree | 7aa82581901a978c3c7ba3b0f50ac8c84f753945 /tests/unit_tests/epee_boosted_tcp_server.cpp | |
| parent | 23a11d851adef30aea1888da0a7dd23936c81ec1 (diff) | |
| download | monzero-core-01bcd52924244ec8d2a24c10fcef8959289d09ff.tar.gz monzero-core-01bcd52924244ec8d2a24c10fcef8959289d09ff.tar.xz monzero-core-01bcd52924244ec8d2a24c10fcef8959289d09ff.zip | |
Fix build with boost ASIO 0.87. Support boost 1.66+
Diffstat (limited to 'tests/unit_tests/epee_boosted_tcp_server.cpp')
| -rw-r--r-- | tests/unit_tests/epee_boosted_tcp_server.cpp | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/tests/unit_tests/epee_boosted_tcp_server.cpp b/tests/unit_tests/epee_boosted_tcp_server.cpp index c08a86a5e..c56174109 100644 --- a/tests/unit_tests/epee_boosted_tcp_server.cpp +++ b/tests/unit_tests/epee_boosted_tcp_server.cpp @@ -28,6 +28,7 @@ // // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers +#include <boost/asio/post.hpp> #include <boost/chrono/chrono.hpp> #include <boost/thread/condition_variable.hpp> #include <boost/thread/mutex.hpp> @@ -173,9 +174,9 @@ TEST(test_epee_connection, test_lifetime) using shared_states_t = std::vector<shared_state_ptr>; using tag_t = boost::uuids::uuid; using tags_t = std::vector<tag_t>; - using io_context_t = boost::asio::io_service; + using io_context_t = boost::asio::io_context; using endpoint_t = boost::asio::ip::tcp::endpoint; - using work_t = boost::asio::io_service::work; + using work_t = boost::asio::executor_work_guard<boost::asio::io_context::executor_type>; using work_ptr = std::shared_ptr<work_t>; using workers_t = std::vector<std::thread>; using server_t = epee::net_utils::boosted_tcp_server<handler_t>; @@ -189,7 +190,7 @@ TEST(test_epee_connection, test_lifetime) using shared_conn_ptr = std::shared_ptr<shared_conn_t>; io_context_t io_context; - work_ptr work(std::make_shared<work_t>(io_context)); + work_ptr work(std::make_shared<work_t>(io_context.get_executor())); workers_t workers; while (workers.size() < 4) { @@ -198,7 +199,7 @@ TEST(test_epee_connection, test_lifetime) }); } - endpoint_t endpoint(boost::asio::ip::address::from_string("127.0.0.1"), 5262); + endpoint_t endpoint(boost::asio::ip::make_address("127.0.0.1"), 5262); server_t server(epee::net_utils::e_connection_type_P2P); server.init_server(endpoint.port(), endpoint.address().to_string(), @@ -211,7 +212,7 @@ TEST(test_epee_connection, test_lifetime) server.run_server(2, false); server.get_config_shared()->set_handler(new command_handler_t, &command_handler_t::destroy); - io_context.post([&io_context, &work, &endpoint, &server]{ + boost::asio::post(io_context, [&io_context, &work, &endpoint, &server]{ auto scope_exit_handler = epee::misc_utils::create_scope_leave_handler([&work]{ work.reset(); }); @@ -377,9 +378,7 @@ TEST(test_epee_connection, test_lifetime) connection_ptr conn(new connection_t(io_context, s, {}, {})); conn->socket().connect(endpoint); conn->start({}, {}); - io_context.post([conn]{ - conn->cancel(); - }); + boost::asio::post(io_context, [conn] { conn->cancel(); }); conn.reset(); s->del_out_connections(1); while (s->sock_count); @@ -449,9 +448,7 @@ TEST(test_epee_connection, test_lifetime) context_t context; conn->get_context(context); auto tag = context.m_connection_id; - io_context.post([conn]{ - conn->cancel(); - }); + boost::asio::post(io_context, [conn] { conn->cancel(); }); conn.reset(); s->close(tag); while (s->sock_count); @@ -494,7 +491,7 @@ TEST(test_epee_connection, ssl_shutdown) }; using handler_t = epee::levin::async_protocol_handler<context_t>; - using io_context_t = boost::asio::io_service; + using io_context_t = boost::asio::io_context; using endpoint_t = boost::asio::ip::tcp::endpoint; using server_t = epee::net_utils::boosted_tcp_server<handler_t>; using socket_t = boost::asio::ip::tcp::socket; @@ -502,7 +499,7 @@ TEST(test_epee_connection, ssl_shutdown) using ssl_context_t = boost::asio::ssl::context; using ec_t = boost::system::error_code; - endpoint_t endpoint(boost::asio::ip::address::from_string("127.0.0.1"), 5263); + endpoint_t endpoint(boost::asio::ip::make_address("127.0.0.1"), 5263); server_t server(epee::net_utils::e_connection_type_P2P); server.init_server(endpoint.port(), endpoint.address().to_string(), @@ -537,8 +534,8 @@ TEST(test_epee_connection, ssl_shutdown) TEST(test_epee_connection, ssl_handshake) { - using io_context_t = boost::asio::io_service; - using work_t = boost::asio::io_service::work; + using io_context_t = boost::asio::io_context; + using work_t = boost::asio::executor_work_guard<boost::asio::io_context::executor_type>; using work_ptr = std::shared_ptr<work_t>; using workers_t = std::vector<std::thread>; using socket_t = boost::asio::ip::tcp::socket; @@ -546,7 +543,7 @@ TEST(test_epee_connection, ssl_handshake) using ssl_socket_ptr = std::unique_ptr<ssl_socket_t>; using ssl_options_t = epee::net_utils::ssl_options_t; io_context_t io_context; - work_ptr work(std::make_shared<work_t>(io_context)); + work_ptr work(std::make_shared<work_t>(io_context.get_executor())); workers_t workers; auto constexpr N = 2; while (workers.size() < N) { @@ -560,12 +557,14 @@ TEST(test_epee_connection, ssl_handshake) ssl_socket_ptr ssl_socket(new ssl_socket_t(io_context, ssl_context)); ssl_socket->next_layer().open(boost::asio::ip::tcp::v4()); for (size_t i = 0; i < N; ++i) { - io_context.post([]{ - std::this_thread::sleep_for(std::chrono::milliseconds(50)); - }); + boost::asio::post( + io_context, + [] { std::this_thread::sleep_for(std::chrono::milliseconds(50)); } + ); } EXPECT_EQ( ssl_options.handshake( + io_context, *ssl_socket, ssl_socket_t::server, {}, @@ -670,7 +669,7 @@ TEST(boosted_tcp_server, strand_deadlock) using server_t = epee::net_utils::boosted_tcp_server<handler_t>; using endpoint_t = boost::asio::ip::tcp::endpoint; - endpoint_t endpoint(boost::asio::ip::address::from_string("127.0.0.1"), 5262); + endpoint_t endpoint(boost::asio::ip::make_address("127.0.0.1"), 5262); server_t server(epee::net_utils::e_connection_type_P2P); server.init_server( endpoint.port(), |
