summaryrefslogtreecommitdiffstats
path: root/src/OSSupport/NetworkSingleton.cpp
diff options
context:
space:
mode:
authorpeterbell10 <peterbell10@live.co.uk>2018-02-20 18:08:46 +0100
committerGitHub <noreply@github.com>2018-02-20 18:08:46 +0100
commit1ea36298d2677733f36bae1cc6f72196c6395a4e (patch)
treebc07ed3758b8b3ec834b8d557cd710ea1e7ba270 /src/OSSupport/NetworkSingleton.cpp
parentcBlockInfo: Deprecate direct access to variables. (#4184) (diff)
downloadcuberite-1ea36298d2677733f36bae1cc6f72196c6395a4e.tar
cuberite-1ea36298d2677733f36bae1cc6f72196c6395a4e.tar.gz
cuberite-1ea36298d2677733f36bae1cc6f72196c6395a4e.tar.bz2
cuberite-1ea36298d2677733f36bae1cc6f72196c6395a4e.tar.lz
cuberite-1ea36298d2677733f36bae1cc6f72196c6395a4e.tar.xz
cuberite-1ea36298d2677733f36bae1cc6f72196c6395a4e.tar.zst
cuberite-1ea36298d2677733f36bae1cc6f72196c6395a4e.zip
Diffstat (limited to 'src/OSSupport/NetworkSingleton.cpp')
-rw-r--r--src/OSSupport/NetworkSingleton.cpp29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/OSSupport/NetworkSingleton.cpp b/src/OSSupport/NetworkSingleton.cpp
index af3a701a8..2f7ed3802 100644
--- a/src/OSSupport/NetworkSingleton.cpp
+++ b/src/OSSupport/NetworkSingleton.cpp
@@ -6,6 +6,7 @@
#include "Globals.h"
#include "NetworkSingleton.h"
+#include "OSSupport/Network.h"
#include <event2/thread.h>
#include <event2/bufferevent.h>
#include <event2/listener.h>
@@ -102,11 +103,25 @@ void cNetworkSingleton::Terminate(void)
event_base_loopbreak(m_EventBase);
m_EventLoopThread.join();
- // Remove all objects:
+ // Close all open connections:
{
cCSLock Lock(m_CS);
- m_Connections.clear();
- m_Servers.clear();
+ // Must take copies because Close will modify lists
+ auto Conns = m_Connections;
+ for (auto & Conn : Conns)
+ {
+ Conn->Close();
+ }
+
+ auto Servers = m_Servers;
+ for (auto & Server : Servers)
+ {
+ Server->Close();
+ }
+
+ // Closed handles should have removed themself
+ ASSERT(m_Connections.empty());
+ ASSERT(m_Servers.empty());
}
// Free the underlying LibEvent objects:
@@ -167,7 +182,7 @@ void cNetworkSingleton::SignalizeStartup(evutil_socket_t a_Socket, short a_Event
-void cNetworkSingleton::AddLink(cTCPLinkImplPtr a_Link)
+void cNetworkSingleton::AddLink(cTCPLinkPtr a_Link)
{
ASSERT(!m_HasTerminated);
cCSLock Lock(m_CS);
@@ -178,7 +193,7 @@ void cNetworkSingleton::AddLink(cTCPLinkImplPtr a_Link)
-void cNetworkSingleton::RemoveLink(const cTCPLinkImpl * a_Link)
+void cNetworkSingleton::RemoveLink(const cTCPLink * a_Link)
{
ASSERT(!m_HasTerminated);
cCSLock Lock(m_CS);
@@ -196,7 +211,7 @@ void cNetworkSingleton::RemoveLink(const cTCPLinkImpl * a_Link)
-void cNetworkSingleton::AddServer(cServerHandleImplPtr a_Server)
+void cNetworkSingleton::AddServer(cServerHandlePtr a_Server)
{
ASSERT(!m_HasTerminated);
cCSLock Lock(m_CS);
@@ -207,7 +222,7 @@ void cNetworkSingleton::AddServer(cServerHandleImplPtr a_Server)
-void cNetworkSingleton::RemoveServer(const cServerHandleImpl * a_Server)
+void cNetworkSingleton::RemoveServer(const cServerHandle * a_Server)
{
ASSERT(!m_HasTerminated);
cCSLock Lock(m_CS);