summaryrefslogtreecommitdiffstats
path: root/src/OSSupport/NetworkSingleton.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2016-06-17 16:25:31 +0200
committerMattes D <github@xoft.cz>2016-06-18 13:12:12 +0200
commit8610083a8e8ad66806c66d0199d0d8a900ceb358 (patch)
tree083bbf9029b971dbf7b74353c9c62c22de9c78c7 /src/OSSupport/NetworkSingleton.cpp
parentSelfTests: More logging for EnumInterfaces. (diff)
downloadcuberite-8610083a8e8ad66806c66d0199d0d8a900ceb358.tar
cuberite-8610083a8e8ad66806c66d0199d0d8a900ceb358.tar.gz
cuberite-8610083a8e8ad66806c66d0199d0d8a900ceb358.tar.bz2
cuberite-8610083a8e8ad66806c66d0199d0d8a900ceb358.tar.lz
cuberite-8610083a8e8ad66806c66d0199d0d8a900ceb358.tar.xz
cuberite-8610083a8e8ad66806c66d0199d0d8a900ceb358.tar.zst
cuberite-8610083a8e8ad66806c66d0199d0d8a900ceb358.zip
Diffstat (limited to '')
-rw-r--r--src/OSSupport/NetworkSingleton.cpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/OSSupport/NetworkSingleton.cpp b/src/OSSupport/NetworkSingleton.cpp
index c16f92c5a..d0abafcbd 100644
--- a/src/OSSupport/NetworkSingleton.cpp
+++ b/src/OSSupport/NetworkSingleton.cpp
@@ -6,7 +6,6 @@
#include "Globals.h"
#include "NetworkSingleton.h"
-#include <event2/event.h>
#include <event2/thread.h>
#include <event2/bufferevent.h>
#include <event2/dns.h>
@@ -91,8 +90,11 @@ void cNetworkSingleton::Initialise(void)
}
// Create the event loop thread:
- m_EventLoopThread = std::thread(RunEventLoop, this);
m_HasTerminated = false;
+ m_StartupEvent.reset(new cEvent);
+ m_EventLoopThread = std::thread(RunEventLoop, this);
+ m_StartupEvent->Wait(); // Wait for the LibEvent loop to actually start running (otherwise calling Terminate too soon would hang, see #3228)
+ m_StartupEvent.reset(); // Don't need the cEvent any more, release all its resources
}
@@ -153,6 +155,9 @@ void cNetworkSingleton::LogCallback(int a_Severity, const char * a_Msg)
void cNetworkSingleton::RunEventLoop(cNetworkSingleton * a_Self)
{
+ auto timer = evtimer_new(a_Self->m_EventBase, SignalizeStartup, a_Self);
+ timeval timeout{}; // Zero timeout - execute immediately
+ evtimer_add(timer, &timeout);
event_base_loop(a_Self->m_EventBase, EVLOOP_NO_EXIT_ON_EMPTY);
}
@@ -160,6 +165,18 @@ void cNetworkSingleton::RunEventLoop(cNetworkSingleton * a_Self)
+void cNetworkSingleton::SignalizeStartup(evutil_socket_t a_Socket, short a_Events, void * a_Self)
+{
+ auto self = reinterpret_cast<cNetworkSingleton *>(a_Self);
+ ASSERT(self != nullptr);
+ ASSERT(self->m_StartupEvent != nullptr);
+ self->m_StartupEvent->Set();
+}
+
+
+
+
+
void cNetworkSingleton::AddHostnameLookup(cHostnameLookupPtr a_HostnameLookup)
{
ASSERT(!m_HasTerminated);