From 3184433756c6014e5192bdb92df9a233c62b55e7 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 13 Mar 2016 18:12:33 +0100 Subject: Moved NetworkInterfaceEnum test to a separate test project. --- src/OSSupport/NetworkInterfaceEnum.cpp | 28 ---------------------------- 1 file changed, 28 deletions(-) (limited to 'src/OSSupport') diff --git a/src/OSSupport/NetworkInterfaceEnum.cpp b/src/OSSupport/NetworkInterfaceEnum.cpp index d74565e07..c7339c408 100644 --- a/src/OSSupport/NetworkInterfaceEnum.cpp +++ b/src/OSSupport/NetworkInterfaceEnum.cpp @@ -22,34 +22,6 @@ -#ifdef SELF_TEST - -static class cEnumIPAddressTest -{ -public: - cEnumIPAddressTest(void) - { - cSelfTests::Get().Register(std::function(&Test), "Network IP enumeration"); - } - - static void Test(void) - { - LOG("Enumerating all IP addresses..."); - auto IPs = cNetwork::EnumLocalIPAddresses(); - for (auto & ip: IPs) - { - LOG(" %s", ip.c_str()); - } - LOG("Done."); - } -} g_EnumIPAddressTest; - -#endif // SELF_TEST - - - - - #ifdef _WIN32 /** Converts the SOCKET_ADDRESS structure received from the OS into an IP address string. */ -- cgit v1.2.3 From 36eefbf0f25c93ed30bcff9d7abbb8b8696964df Mon Sep 17 00:00:00 2001 From: Mattes D Date: Fri, 10 Jun 2016 20:18:49 +0200 Subject: SelfTests: Removed the unneeded cSelfTests class. --- src/OSSupport/NetworkInterfaceEnum.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/OSSupport') diff --git a/src/OSSupport/NetworkInterfaceEnum.cpp b/src/OSSupport/NetworkInterfaceEnum.cpp index c7339c408..d3a254c23 100644 --- a/src/OSSupport/NetworkInterfaceEnum.cpp +++ b/src/OSSupport/NetworkInterfaceEnum.cpp @@ -6,7 +6,6 @@ #include "Globals.h" #include "Network.h" #include "event2/util.h" -#include "../SelfTests.h" #ifdef _WIN32 #include -- cgit v1.2.3 From 8610083a8e8ad66806c66d0199d0d8a900ceb358 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Fri, 17 Jun 2016 16:25:31 +0200 Subject: cNetwork: Fixed possible hang when terminating immediately after init. --- src/OSSupport/NetworkSingleton.cpp | 21 +++++++++++++++++++-- src/OSSupport/NetworkSingleton.h | 8 ++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) (limited to 'src/OSSupport') 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 #include #include #include @@ -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(a_Self); + ASSERT(self != nullptr); + ASSERT(self->m_StartupEvent != nullptr); + self->m_StartupEvent->Set(); +} + + + + + void cNetworkSingleton::AddHostnameLookup(cHostnameLookupPtr a_HostnameLookup) { ASSERT(!m_HasTerminated); diff --git a/src/OSSupport/NetworkSingleton.h b/src/OSSupport/NetworkSingleton.h index c72df38ec..75713d261 100644 --- a/src/OSSupport/NetworkSingleton.h +++ b/src/OSSupport/NetworkSingleton.h @@ -13,6 +13,7 @@ #pragma once +#include #include "Network.h" #include "CriticalSection.h" #include "Event.h" @@ -127,11 +128,18 @@ protected: /** The thread in which the main LibEvent loop runs. */ std::thread m_EventLoopThread; + /** Event that is signalled once the startup is finished and the LibEvent loop is running. */ + UniquePtr m_StartupEvent; + + /** Converts LibEvent-generated log events into log messages in MCS log. */ static void LogCallback(int a_Severity, const char * a_Msg); /** Implements the thread that runs LibEvent's event dispatcher loop. */ static void RunEventLoop(cNetworkSingleton * a_Self); + + /** Callback called by LibEvent when the event loop is started. */ + static void SignalizeStartup(evutil_socket_t a_Socket, short a_Events, void * a_Self); }; -- cgit v1.2.3