aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2015-12-22 14:42:34 +0200
committerRiccardo Spagni <ric@spagni.net>2015-12-22 14:42:37 +0200
commite6dbea094c79058a3272b5d713b69095eb15aac7 (patch)
treebd220d60d507b28e54f217f2eb950520f70220b9
parentMerge pull request #552 (diff)
parentepee: fix hang on exit (diff)
downloadmonero-e6dbea094c79058a3272b5d713b69095eb15aac7.tar.xz
Merge pull request #553
1e2f2d7 epee: fix hang on exit (moneromooo-monero) 17ff6f2 net_node: fix a hang on exit (moneromooo-monero)
-rw-r--r--contrib/epee/include/net/abstract_tcp_server2.h5
-rw-r--r--contrib/epee/include/net/abstract_tcp_server2.inl21
-rw-r--r--src/p2p/net_node.inl2
3 files changed, 26 insertions, 2 deletions
diff --git a/contrib/epee/include/net/abstract_tcp_server2.h b/contrib/epee/include/net/abstract_tcp_server2.h
index 8043c0876..77396ade4 100644
--- a/contrib/epee/include/net/abstract_tcp_server2.h
+++ b/contrib/epee/include/net/abstract_tcp_server2.h
@@ -110,6 +110,8 @@ namespace net_utils
bool speed_limit_is_enabled() const; ///< tells us should we be sleeping here (e.g. do not sleep on RPC connections)
+
+ bool cancel();
private:
//----------------- i_service_endpoint ---------------------
@@ -303,6 +305,9 @@ namespace net_utils
/// The next connection to be accepted
connection_ptr new_connection_;
+ std::mutex connections_mutex;
+ std::deque<connection_ptr> connections_;
+
}; // class <>boosted_tcp_server
diff --git a/contrib/epee/include/net/abstract_tcp_server2.inl b/contrib/epee/include/net/abstract_tcp_server2.inl
index b75a9ecaa..cb8bdc6ee 100644
--- a/contrib/epee/include/net/abstract_tcp_server2.inl
+++ b/contrib/epee/include/net/abstract_tcp_server2.inl
@@ -565,7 +565,12 @@ PRAGMA_WARNING_DISABLE_VS(4355)
return true;
CATCH_ENTRY_L0("connection<t_protocol_handler>::close", false);
}
-
+ //---------------------------------------------------------------------------------
+ template<class t_protocol_handler>
+ bool connection<t_protocol_handler>::cancel()
+ {
+ return close();
+ }
//---------------------------------------------------------------------------------
template<class t_protocol_handler>
void connection<t_protocol_handler>::handle_write(const boost::system::error_code& e, size_t cb)
@@ -871,6 +876,12 @@ POP_WARNINGS
}
m_stop_signal_sent = true;
TRY_ENTRY();
+ connections_mutex.lock();
+ for (auto &c: connections_)
+ {
+ c->cancel();
+ }
+ connections_mutex.unlock();
io_service_.stop();
CATCH_ENTRY_L0("boosted_tcp_server<t_protocol_handler>::send_stop_signal()", void());
}
@@ -914,6 +925,10 @@ POP_WARNINGS
TRY_ENTRY();
connection_ptr new_connection_l(new connection<t_protocol_handler>(io_service_, m_config, m_sock_count, m_sock_number, m_pfilter, m_connection_type) );
+ connections_mutex.lock();
+ connections_.push_back(new_connection_l);
+ LOG_PRINT_L2("connections_ size now " << connections_.size());
+ connections_mutex.unlock();
boost::asio::ip::tcp::socket& sock_ = new_connection_l->socket();
//////////////////////////////////////////////////////////////////////////
@@ -1006,6 +1021,10 @@ POP_WARNINGS
{
TRY_ENTRY();
connection_ptr new_connection_l(new connection<t_protocol_handler>(io_service_, m_config, m_sock_count, m_sock_number, m_pfilter, m_connection_type) );
+ connections_mutex.lock();
+ connections_.push_back(new_connection_l);
+ LOG_PRINT_L2("connections_ size now " << connections_.size());
+ connections_mutex.unlock();
boost::asio::ip::tcp::socket& sock_ = new_connection_l->socket();
//////////////////////////////////////////////////////////////////////////
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl
index 254c9ae72..917f18266 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -570,7 +570,7 @@ namespace nodetool
mPeersLoggerThread.reset(new std::thread([&]()
{
_note("Thread monitor number of peers - start");
- while (!is_closing)
+ while (!is_closing && !m_net_server.is_stop_signal_sent())
{ // main loop of thread
//number_of_peers = m_net_server.get_config_object().get_connections_count();
unsigned int number_of_peers = 0;