diff --git a/contrib/epee/include/net/abstract_tcp_server2.h b/contrib/epee/include/net/abstract_tcp_server2.h index 33e50cd35..925a465a7 100644 --- a/contrib/epee/include/net/abstract_tcp_server2.h +++ b/contrib/epee/include/net/abstract_tcp_server2.h @@ -404,7 +404,7 @@ namespace net_utils try_connect_result_t try_connect(connection_ptr new_connection_l, const std::string& adr, const std::string& port, boost::asio::ip::tcp::socket &sock_, const boost::asio::ip::tcp::endpoint &remote_endpoint, const std::string &bind_ip, uint32_t conn_timeout, epee::net_utils::ssl_support_t ssl_support); bool connect(const std::string& adr, const std::string& port, uint32_t conn_timeot, t_connection_context& cn, const std::string& bind_ip = "0.0.0.0", epee::net_utils::ssl_support_t ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_autodetect); template - bool connect_async(const std::string& adr, const std::string& port, uint32_t conn_timeot, const t_callback &cb, const std::string& bind_ip = "0.0.0.0", epee::net_utils::ssl_support_t ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_autodetect, t_connection_context&& initial = t_connection_context{}); + bool connect_async(const std::string& adr, const std::string& port, std::chrono::milliseconds conn_timeout, const t_callback &cb, const std::string& bind_ip = "0.0.0.0", epee::net_utils::ssl_support_t ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_autodetect, t_connection_context&& initial = t_connection_context{}); boost::asio::ssl::context& get_ssl_context() noexcept { @@ -445,42 +445,43 @@ namespace net_utils idle_callback_conext_base(boost::asio::io_context& io_serice): m_timer(io_serice) {} - boost::asio::deadline_timer m_timer; + boost::asio::steady_timer m_timer; }; template struct idle_callback_conext: public idle_callback_conext_base { - idle_callback_conext(boost::asio::io_context& io_serice, t_handler& h, uint64_t period): + idle_callback_conext(boost::asio::io_context& io_serice, t_handler& h, std::chrono::milliseconds period): idle_callback_conext_base(io_serice), - m_handler(h) - {this->m_period = period;} + m_handler(h), + m_period(period) + {} t_handler m_handler; virtual bool call_handler() { return m_handler(); } - uint64_t m_period; + const std::chrono::milliseconds m_period; }; template - bool add_idle_handler(t_handler t_callback, uint64_t timeout_ms) + bool add_idle_handler(t_handler t_callback, const std::chrono::milliseconds timeout) { - boost::shared_ptr> ptr(new idle_callback_conext(io_context_, t_callback, timeout_ms)); + std::shared_ptr> ptr(std::make_shared>(io_context_, t_callback, timeout)); //needed call handler here ?... - ptr->m_timer.expires_from_now(boost::posix_time::milliseconds(ptr->m_period)); + ptr->m_timer.expires_after(ptr->m_period); ptr->m_timer.async_wait(boost::bind(&boosted_tcp_server::global_timer_handler, this, ptr)); return true; } template - bool global_timer_handler(/*const boost::system::error_code& err, */boost::shared_ptr> ptr) + bool global_timer_handler(/*const boost::system::error_code& err, */std::shared_ptr> ptr) { //if handler return false - he don't want to be called anymore if(!ptr->call_handler()) return true; - ptr->m_timer.expires_from_now(boost::posix_time::milliseconds(ptr->m_period)); + ptr->m_timer.expires_after(ptr->m_period); ptr->m_timer.async_wait(boost::bind(&boosted_tcp_server::global_timer_handler, this, ptr)); return true; } diff --git a/contrib/epee/include/net/abstract_tcp_server2.inl b/contrib/epee/include/net/abstract_tcp_server2.inl index 83f0c08ab..d344119f4 100644 --- a/contrib/epee/include/net/abstract_tcp_server2.inl +++ b/contrib/epee/include/net/abstract_tcp_server2.inl @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include // TODO #include // TODO #include @@ -1894,7 +1894,7 @@ namespace net_utils } //--------------------------------------------------------------------------------- template template - bool boosted_tcp_server::connect_async(const std::string& adr, const std::string& port, uint32_t conn_timeout, const t_callback &cb, const std::string& bind_ip, epee::net_utils::ssl_support_t ssl_support, t_connection_context&& initial) + bool boosted_tcp_server::connect_async(const std::string& adr, const std::string& port, const std::chrono::milliseconds conn_timeout, const t_callback &cb, const std::string& bind_ip, epee::net_utils::ssl_support_t ssl_support, t_connection_context&& initial) { TRY_ENTRY(); connection_ptr new_connection_l(new connection(io_context_, m_state, m_connection_type, ssl_support, std::move(initial)) ); @@ -1975,14 +1975,14 @@ namespace net_utils } } - boost::shared_ptr sh_deadline(new boost::asio::deadline_timer(io_context_)); + std::shared_ptr sh_deadline(std::make_shared(io_context_)); //start deadline - sh_deadline->expires_from_now(boost::posix_time::milliseconds(conn_timeout)); + sh_deadline->expires_after(conn_timeout); sh_deadline->async_wait([=](const boost::system::error_code& error) { if(error != boost::asio::error::operation_aborted) { - _dbg3("Failed to connect to " << adr << ':' << port << ", because of timeout (" << conn_timeout << ")"); + _dbg3("Failed to connect to " << adr << ':' << port << ", because of timeout (" << conn_timeout.count() << ")"); new_connection_l->socket().close(); } }); diff --git a/contrib/epee/include/net/levin_base.h b/contrib/epee/include/net/levin_base.h index b680691ad..9dc1035af 100644 --- a/contrib/epee/include/net/levin_base.h +++ b/contrib/epee/include/net/levin_base.h @@ -29,6 +29,7 @@ #ifndef _LEVIN_BASE_H_ #define _LEVIN_BASE_H_ +#include #include #include "byte_stream.h" @@ -72,7 +73,7 @@ namespace levin #pragma pack(pop) -#define LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED 0 +constexpr const std::chrono::milliseconds LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED{0}; #define LEVIN_INITIAL_MAX_PACKET_SIZE 256*1024 // 256 KiB before handshake #define LEVIN_DEFAULT_MAX_PACKET_SIZE 100000000 //100MB by default after handshake diff --git a/contrib/epee/include/net/levin_protocol_handler_async.h b/contrib/epee/include/net/levin_protocol_handler_async.h index 341522bdc..9d80cb2d8 100644 --- a/contrib/epee/include/net/levin_protocol_handler_async.h +++ b/contrib/epee/include/net/levin_protocol_handler_async.h @@ -25,7 +25,7 @@ // #pragma once -#include +#include #include #include #include @@ -100,10 +100,10 @@ public: typedef t_connection_context connection_context; uint64_t m_initial_max_packet_size; uint64_t m_max_packet_size; - uint64_t m_invoke_timeout; + std::chrono::milliseconds m_invoke_timeout; template - int invoke_async(int command, message_writer in_msg, boost::uuids::uuid connection_id, const callback_t &cb, size_t timeout = LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED); + int invoke_async(int command, message_writer in_msg, boost::uuids::uuid connection_id, const callback_t &cb, std::chrono::milliseconds timeout = LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED); int send(epee::byte_slice message, const boost::uuids::uuid& connection_id); bool close(boost::uuids::uuid connection_id); @@ -190,19 +190,19 @@ public: template struct anvoke_handler: invoke_response_handler_base { - anvoke_handler(const callback_t& cb, uint64_t timeout, async_protocol_handler& con, int command) + anvoke_handler(const callback_t& cb, const std::chrono::milliseconds timeout, async_protocol_handler& con, int command) :m_cb(cb), m_timeout(timeout), m_con(con), m_timer(con.m_pservice_endpoint->get_io_context()), m_timer_started(false), m_cancel_timer_called(false), m_timer_cancelled(false), m_command(command) { if(m_con.start_outer_call()) { - MDEBUG(con.get_context_ref() << "anvoke_handler, timeout: " << timeout); - m_timer.expires_from_now(boost::posix_time::milliseconds(timeout)); + MDEBUG(con.get_context_ref() << "anvoke_handler, timeout: " << timeout.count()); + m_timer.expires_after(timeout); m_timer.async_wait([&con, command, cb, timeout](const boost::system::error_code& ec) { if(ec == boost::asio::error::operation_aborted) return; - MINFO(con.get_context_ref() << "Timeout on invoke operation happened, command: " << command << " timeout: " << timeout); + MINFO(con.get_context_ref() << "Timeout on invoke operation happened, command: " << command << " timeout: " << timeout.count()); epee::span fake; cb(LEVIN_ERROR_CONNECTION_TIMEDOUT, fake, con.get_context_ref()); con.close(); @@ -215,11 +215,11 @@ public: {} callback_t m_cb; async_protocol_handler& m_con; - boost::asio::deadline_timer m_timer; + boost::asio::steady_timer m_timer; bool m_timer_started; bool m_cancel_timer_called; bool m_timer_cancelled; - uint64_t m_timeout; + const std::chrono::milliseconds m_timeout; int m_command; virtual bool handle(int res, const epee::span buff, typename async_protocol_handler::connection_context& context) { @@ -247,26 +247,24 @@ public: if(!m_cancel_timer_called) { m_cancel_timer_called = true; - boost::system::error_code ignored_ec; - m_timer_cancelled = 1 == m_timer.cancel(ignored_ec); + m_timer_cancelled = 1 == m_timer.cancel(); } return m_timer_cancelled; } virtual void reset_timer() { - boost::system::error_code ignored_ec; - if (!m_cancel_timer_called && m_timer.cancel(ignored_ec) > 0) + if (!m_cancel_timer_called && m_timer.cancel() > 0) { callback_t& cb = m_cb; - uint64_t timeout = m_timeout; + const auto timeout = m_timeout; async_protocol_handler& con = m_con; int command = m_command; - m_timer.expires_from_now(boost::posix_time::milliseconds(m_timeout)); + m_timer.expires_after(m_timeout); m_timer.async_wait([&con, cb, command, timeout](const boost::system::error_code& ec) { if(ec == boost::asio::error::operation_aborted) return; - MINFO(con.get_context_ref() << "Timeout on invoke operation happened, command: " << command << " timeout: " << timeout); + MINFO(con.get_context_ref() << "Timeout on invoke operation happened, command: " << command << " timeout: " << timeout.count()); epee::span fake; cb(LEVIN_ERROR_CONNECTION_TIMEDOUT, fake, con.get_context_ref()); con.close(); @@ -279,7 +277,7 @@ public: std::list > m_invoke_response_handlers; template - bool add_invoke_response_handler(const callback_t &cb, uint64_t timeout, async_protocol_handler& con, int command) + bool add_invoke_response_handler(const callback_t &cb, const std::chrono::milliseconds timeout, async_protocol_handler& con, int command) { CRITICAL_REGION_LOCAL(m_invoke_response_handlers_lock); if (m_protocol_released) @@ -604,7 +602,7 @@ public: } template - bool async_invoke(int command, message_writer in_msg, const callback_t &cb, size_t timeout = LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED) + bool async_invoke(int command, message_writer in_msg, const callback_t &cb, std::chrono::milliseconds timeout = LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED) { misc_utils::auto_scope_leave_caller scope_exit_handler = misc_utils::create_scope_leave_handler( boost::bind(&async_protocol_handler::finish_outer_call, this)); @@ -752,7 +750,7 @@ int async_protocol_handler_config::find_and_lock_connectio } //------------------------------------------------------------------------------------------ template template -int async_protocol_handler_config::invoke_async(int command, message_writer in_msg, boost::uuids::uuid connection_id, const callback_t &cb, size_t timeout) +int async_protocol_handler_config::invoke_async(int command, message_writer in_msg, boost::uuids::uuid connection_id, const callback_t &cb, const std::chrono::milliseconds timeout) { async_protocol_handler* aph; int r = find_and_lock_connection(connection_id, aph); diff --git a/contrib/epee/include/net/network_throttle.hpp b/contrib/epee/include/net/network_throttle.hpp index fb39f69fc..46361e5fa 100644 --- a/contrib/epee/include/net/network_throttle.hpp +++ b/contrib/epee/include/net/network_throttle.hpp @@ -56,7 +56,6 @@ #include #include #include -#include #include #include "misc_language.h" #include diff --git a/contrib/epee/include/storages/levin_abstract_invoke2.h b/contrib/epee/include/storages/levin_abstract_invoke2.h index 9d3dda0d6..0f5c35813 100644 --- a/contrib/epee/include/storages/levin_abstract_invoke2.h +++ b/contrib/epee/include/storages/levin_abstract_invoke2.h @@ -57,7 +57,7 @@ namespace epee namespace net_utils { template - bool async_invoke_remote_command2(const epee::net_utils::connection_context_base &context, int command, const t_arg& out_struct, t_transport& transport, const callback_t &cb, size_t inv_timeout = LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED) + bool async_invoke_remote_command2(const epee::net_utils::connection_context_base &context, int command, const t_arg& out_struct, t_transport& transport, const callback_t &cb, const std::chrono::milliseconds inv_timeout = levin::LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED) { const boost::uuids::uuid &conn_id = context.m_connection_id; typename serialization::portable_storage stg; diff --git a/src/debug_utilities/object_sizes.cpp b/src/debug_utilities/object_sizes.cpp index 4b5ff81db..789968b2c 100644 --- a/src/debug_utilities/object_sizes.cpp +++ b/src/debug_utilities/object_sizes.cpp @@ -72,7 +72,7 @@ int main(int argc, char* argv[]) SL(boost::thread); SL(boost::asio::io_context); SL(boost::asio::executor_work_guard); - SL(boost::asio::deadline_timer); + SL(boost::asio::steady_timer); SL(cryptonote::DB_ERROR); SL(cryptonote::mdb_txn_safe); diff --git a/src/device_trezor/trezor/transport.cpp b/src/device_trezor/trezor/transport.cpp index 48fd9c7bd..ec39dc355 100644 --- a/src/device_trezor/trezor/transport.cpp +++ b/src/device_trezor/trezor/transport.cpp @@ -571,7 +571,7 @@ namespace trezor{ return ping_int(); } - bool UdpTransport::ping_int(boost::posix_time::time_duration timeout){ + bool UdpTransport::ping_int(boost::asio::steady_timer::duration timeout){ require_socket(); try { std::string req = "PINGPING"; @@ -619,7 +619,7 @@ namespace trezor{ m_socket.reset(new udp::socket(m_io_service)); m_socket->open(udp::v4()); - m_deadline.expires_at(boost::posix_time::pos_infin); + m_deadline.expires_after(boost::asio::steady_timer::duration::max()); check_deadline(); m_proto->session_begin(*this); @@ -701,14 +701,14 @@ namespace trezor{ return static_cast(len); } - ssize_t UdpTransport::receive(void * buff, size_t size, boost::system::error_code * error_code, bool no_throw, boost::posix_time::time_duration timeout){ + ssize_t UdpTransport::receive(void * buff, size_t size, boost::system::error_code * error_code, bool no_throw, const boost::asio::steady_timer::duration timeout){ boost::system::error_code ec; boost::asio::mutable_buffer buffer = boost::asio::buffer(buff, size); require_socket(); // Set a deadline for the asynchronous operation. - m_deadline.expires_from_now(timeout); + m_deadline.expires_after(timeout); // Set up the variables that receive the result of the asynchronous // operation. The error code is set to would_block to signal that the @@ -766,7 +766,7 @@ namespace trezor{ // Check whether the deadline has passed. We compare the deadline against // the current time since a new asynchronous operation may have moved the // deadline before this actor had a chance to run. - if (m_deadline.expires_at() <= boost::asio::deadline_timer::traits_type::now()) + if (m_deadline.expiry() <= boost::asio::steady_timer::clock_type::now()) { // The deadline has passed. The outstanding asynchronous operation needs // to be cancelled so that the blocked receive() function will return. @@ -778,7 +778,7 @@ namespace trezor{ // There is no longer an active deadline. The expiry is set to positive // infinity so that the actor takes no action until a new deadline is set. - m_deadline.expires_at(boost::posix_time::pos_infin); + m_deadline.expires_after(boost::asio::steady_timer::duration::max()); } // Put the actor back to sleep. diff --git a/src/device_trezor/trezor/transport.hpp b/src/device_trezor/trezor/transport.hpp index 91cb01772..9ac95f3bb 100644 --- a/src/device_trezor/trezor/transport.hpp +++ b/src/device_trezor/trezor/transport.hpp @@ -32,7 +32,7 @@ #include -#include +#include #include #include @@ -233,11 +233,11 @@ namespace trezor { private: void require_socket(); - ssize_t receive(void * buff, size_t size, boost::system::error_code * error_code=nullptr, bool no_throw=false, boost::posix_time::time_duration timeout=boost::posix_time::seconds(10)); + ssize_t receive(void * buff, size_t size, boost::system::error_code * error_code=nullptr, bool no_throw=false, boost::asio::steady_timer::duration timeout = std::chrono::seconds(10)); void check_deadline(); static void handle_receive(const boost::system::error_code& ec, std::size_t length, boost::system::error_code* out_ec, std::size_t* out_length); - bool ping_int(boost::posix_time::time_duration timeout=boost::posix_time::milliseconds(1500)); + bool ping_int(boost::asio::steady_timer::duration = std::chrono::milliseconds(1500)); std::shared_ptr m_proto; std::string m_device_host; @@ -245,7 +245,7 @@ namespace trezor { std::unique_ptr m_socket; boost::asio::io_context m_io_service; - boost::asio::deadline_timer m_deadline; + boost::asio::steady_timer m_deadline; udp::endpoint m_endpoint; }; diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h index 08db07604..187e67185 100644 --- a/src/p2p/net_node.h +++ b/src/p2p/net_node.h @@ -230,7 +230,7 @@ namespace nodetool m_config.m_net_config.packet_max_size = P2P_DEFAULT_PACKET_MAX_SIZE; m_config.m_net_config.config_id = 0; m_config.m_net_config.connection_timeout = P2P_DEFAULT_CONNECTION_TIMEOUT; - m_config.m_net_config.ping_connection_timeout = P2P_DEFAULT_PING_CONNECTION_TIMEOUT; + m_config.m_net_config.ping_connection_timeout = std::chrono::milliseconds{P2P_DEFAULT_PING_CONNECTION_TIMEOUT}; m_config.m_net_config.send_peerlist_sz = P2P_DEFAULT_PEERS_IN_HANDSHAKE; m_config.m_support_flags = 0; // only set in public zone } diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 6f68645bd..b3925fc19 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -988,7 +988,7 @@ namespace nodetool for (auto& zone : m_network_zones) { zone.second.m_net_server.get_config_object().set_handler(this); - zone.second.m_net_server.get_config_object().m_invoke_timeout = P2P_DEFAULT_INVOKE_TIMEOUT; + zone.second.m_net_server.get_config_object().m_invoke_timeout = std::chrono::milliseconds{P2P_DEFAULT_INVOKE_TIMEOUT}; if (!zone.second.m_bind_ip.empty()) { @@ -1073,8 +1073,8 @@ namespace nodetool })); // lambda network_zone& public_zone = m_network_zones.at(epee::net_utils::zone::public_); - public_zone.m_net_server.add_idle_handler(boost::bind(&node_server::idle_worker, this), 1000); - public_zone.m_net_server.add_idle_handler(boost::bind(&t_payload_net_handler::on_idle, &m_payload_handler), 1000); + public_zone.m_net_server.add_idle_handler(boost::bind(&node_server::idle_worker, this), std::chrono::seconds{1}); + public_zone.m_net_server.add_idle_handler(boost::bind(&t_payload_net_handler::on_idle, &m_payload_handler), std::chrono::seconds{1}); //here you can set worker threads count int thrds_count = 10; @@ -1234,7 +1234,7 @@ namespace nodetool LOG_DEBUG_CC(context, " COMMAND_HANDSHAKE(AND CLOSE) INVOKED OK"); } context_ = context; - }, P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT); + }, std::chrono::milliseconds{P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT}); if(r) { @@ -2563,7 +2563,7 @@ namespace nodetool f(context_, rsp.support_flags); }, - P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT + std::chrono::milliseconds{P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT} ); return r; diff --git a/src/p2p/p2p_protocol_defs.h b/src/p2p/p2p_protocol_defs.h index 43cc6b03e..cc0c6cf5b 100644 --- a/src/p2p/p2p_protocol_defs.h +++ b/src/p2p/p2p_protocol_defs.h @@ -136,10 +136,10 @@ namespace nodetool KV_SERIALIZE(config_id) END_KV_SERIALIZE_MAP() + std::chrono::milliseconds ping_connection_timeout; uint32_t max_out_connection_count; uint32_t max_in_connection_count; uint32_t connection_timeout; - uint32_t ping_connection_timeout; uint32_t handshake_interval; uint32_t packet_max_size; uint32_t config_id; diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 5b680b523..bf4cdb4cf 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -350,7 +350,7 @@ namespace cryptonote http_login.emplace(std::move(rpc_config->login->username), std::move(rpc_config->login->password).password()); if (m_rpc_payment) - m_net_server.add_idle_handler([this](){ return m_rpc_payment->on_idle(); }, 60 * 1000); + m_net_server.add_idle_handler([this](){ return m_rpc_payment->on_idle(); }, std::chrono::minutes{1}); bool store_ssl_key = !restricted && rpc_config->ssl_options && rpc_config->ssl_options.auth.certificate_path.empty(); const auto ssl_base_path = (boost::filesystem::path{data_dir} / "rpc_ssl").string(); diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index f4a1b0d19..c64e45cdd 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -267,7 +267,7 @@ namespace tools } } return true; - }, auto_refresh_evaluation_ms.count()); + }, auto_refresh_evaluation_ms); m_net_server.add_idle_handler([this](){ if (m_stop.load(std::memory_order_relaxed)) { @@ -275,7 +275,7 @@ namespace tools return false; } return true; - }, 500); + }, std::chrono::milliseconds{500}); //DO NOT START THIS SERVER IN MORE THEN 1 THREADS WITHOUT REFACTORING return epee::http_server_impl_base::run(1, true); diff --git a/tests/net_load_tests/clt.cpp b/tests/net_load_tests/clt.cpp index ab5de976f..d10089db6 100644 --- a/tests/net_load_tests/clt.cpp +++ b/tests/net_load_tests/clt.cpp @@ -50,7 +50,7 @@ using namespace net_load_tests; namespace { const size_t CONNECTION_COUNT = 100000; - const size_t CONNECTION_TIMEOUT = 10000; + constexpr const std::chrono::seconds CONNECTION_TIMEOUT{10}; const size_t DEFAULT_OPERATION_TIMEOUT = 30000; const size_t RESERVED_CONN_CNT = 1; diff --git a/tests/net_load_tests/srv.cpp b/tests/net_load_tests/srv.cpp index dd22b1b61..844f2a3cb 100644 --- a/tests/net_load_tests/srv.cpp +++ b/tests/net_load_tests/srv.cpp @@ -28,6 +28,7 @@ // // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers +#include #include #include @@ -189,10 +190,10 @@ namespace if (0 < count) { // Perhaps not all connections were closed, try to close it after 7 seconds - boost::shared_ptr sh_deadline(new boost::asio::deadline_timer(m_tcp_server.get_io_context(), boost::posix_time::seconds(7))); + std::shared_ptr sh_deadline(std::make_shared(m_tcp_server.get_io_context(), std::chrono::seconds(7))); sh_deadline->async_wait([=](const boost::system::error_code& ec) { - boost::shared_ptr t = sh_deadline; // Capture sh_deadline + std::shared_ptr t = sh_deadline; // Capture sh_deadline if (!ec) { close_connections(cmd_conn_id); @@ -229,7 +230,7 @@ int main(int argc, char** argv) srv_levin_commands_handler *commands_handler = new srv_levin_commands_handler(tcp_server); tcp_server.get_config_object().set_handler(commands_handler, [](epee::levin::levin_commands_handler *handler) { delete handler; }); - tcp_server.get_config_object().m_invoke_timeout = 10000; + tcp_server.get_config_object().m_invoke_timeout = std::chrono::seconds{10}; //tcp_server.get_config_object().m_max_packet_size = max_packet_size; if (!tcp_server.run_server(thread_count, true)) diff --git a/tests/unit_tests/epee_boosted_tcp_server.cpp b/tests/unit_tests/epee_boosted_tcp_server.cpp index 4b0630299..d48818f8c 100644 --- a/tests/unit_tests/epee_boosted_tcp_server.cpp +++ b/tests/unit_tests/epee_boosted_tcp_server.cpp @@ -282,7 +282,7 @@ TEST(test_epee_connection, test_lifetime) while (shared_state->sock_count); ASSERT_TRUE(shared_state->get_connections_count() == 0); constexpr auto DELAY = 30; - constexpr auto TIMEOUT = 1; + constexpr std::chrono::milliseconds TIMEOUT{1}; while (server.get_connections_count()) { server.get_config_shared()->del_in_connections( server.get_config_shared()->get_in_connections_count() diff --git a/tests/unit_tests/epee_levin_protocol_handler_async.cpp b/tests/unit_tests/epee_levin_protocol_handler_async.cpp index 967708111..3e1d65d12 100644 --- a/tests/unit_tests/epee_levin_protocol_handler_async.cpp +++ b/tests/unit_tests/epee_levin_protocol_handler_async.cpp @@ -185,7 +185,7 @@ namespace class async_protocol_handler_test : public ::testing::Test { public: - const static uint64_t invoke_timeout = 5 * 1000; + constexpr const static std::chrono::seconds invoke_timeout{5}; const static size_t max_packet_size = 10 * 1024 * 1024; typedef std::unique_ptr test_connection_ptr; diff --git a/tests/unit_tests/node_server.cpp b/tests/unit_tests/node_server.cpp index 96d74e974..b5c0fa1ae 100644 --- a/tests/unit_tests/node_server.cpp +++ b/tests/unit_tests/node_server.cpp @@ -690,7 +690,7 @@ TEST(cryptonote_protocol_handler, race_condition) net_node.core_protocol->process_payload_sync_data(msg.payload_data, context, true); handshaked.raise(); }, - P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT + std::chrono::milliseconds{P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT} ); return true; } @@ -1202,7 +1202,7 @@ TEST(node_server, race_condition) EXPECT_TRUE(code >= 0); handshaked.raise(); }, - P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT + std::chrono::milliseconds{P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT} ); handshaked.wait(); boost::asio::post(conn->strand_, [conn]{