From 4d3b61a31bf8b3ccb9ec78cf695e926964d8d82a Mon Sep 17 00:00:00 2001 From: Lee Clagett Date: Sun, 10 Feb 2019 13:40:32 -0500 Subject: [PATCH] Use io_service::work in epee tcp server --- contrib/epee/include/net/abstract_tcp_server2.h | 11 ++++++++++- contrib/epee/include/net/abstract_tcp_server2.inl | 9 ++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/contrib/epee/include/net/abstract_tcp_server2.h b/contrib/epee/include/net/abstract_tcp_server2.h index 37f4c782d..6f9e4db5b 100644 --- a/contrib/epee/include/net/abstract_tcp_server2.h +++ b/contrib/epee/include/net/abstract_tcp_server2.h @@ -330,7 +330,16 @@ namespace net_utils const boost::shared_ptr::shared_state> m_state; /// The io_service used to perform asynchronous operations. - std::unique_ptr m_io_service_local_instance; + struct worker + { + worker() + : io_service(), work(io_service) + {} + + boost::asio::io_service io_service; + boost::asio::io_service::work work; + }; + std::unique_ptr m_io_service_local_instance; boost::asio::io_service& io_service_; /// Acceptor used to listen for incoming connections. diff --git a/contrib/epee/include/net/abstract_tcp_server2.inl b/contrib/epee/include/net/abstract_tcp_server2.inl index 9c89a18cf..eda4d7f7b 100644 --- a/contrib/epee/include/net/abstract_tcp_server2.inl +++ b/contrib/epee/include/net/abstract_tcp_server2.inl @@ -809,8 +809,8 @@ PRAGMA_WARNING_DISABLE_VS(4355) template boosted_tcp_server::boosted_tcp_server( t_connection_type connection_type ) : m_state(boost::make_shared::shared_state>()), - m_io_service_local_instance(new boost::asio::io_service()), - io_service_(*m_io_service_local_instance.get()), + m_io_service_local_instance(new worker()), + io_service_(m_io_service_local_instance->io_service), acceptor_(io_service_), default_remote(), m_stop_signal_sent(false), m_port(0), @@ -919,9 +919,8 @@ POP_WARNINGS { try { - size_t cnt = io_service_.run(); - if (cnt == 0) - misc_utils::sleep_no_w(1); + io_service_.run(); + return true; } catch(const std::exception& ex) {