From 035ecdc9e285ad2fd9ccf51e4ed2ac01b53dc3d1 Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Thu, 15 Jun 2017 10:03:49 +0100 Subject: Replace evdns with getaddrinfo and getnameinfo (#3766) --- src/OSSupport/NetworkSingleton.h | 43 ++++++++-------------------------------- 1 file changed, 8 insertions(+), 35 deletions(-) (limited to 'src/OSSupport/NetworkSingleton.h') diff --git a/src/OSSupport/NetworkSingleton.h b/src/OSSupport/NetworkSingleton.h index 3c8f5f660..0b815af43 100644 --- a/src/OSSupport/NetworkSingleton.h +++ b/src/OSSupport/NetworkSingleton.h @@ -13,8 +13,10 @@ #pragma once +#include #include #include "Network.h" +#include "NetworkLookup.h" #include "CriticalSection.h" #include "Event.h" @@ -24,19 +26,12 @@ // fwd: struct event_base; -struct evdns_base; class cTCPLinkImpl; typedef SharedPtr cTCPLinkImplPtr; typedef std::vector cTCPLinkImplPtrs; class cServerHandleImpl; typedef SharedPtr cServerHandleImplPtr; typedef std::vector cServerHandleImplPtrs; -class cHostnameLookup; -typedef SharedPtr cHostnameLookupPtr; -typedef std::vector cHostnameLookupPtrs; -class cIPLookup; -typedef SharedPtr cIPLookupPtr; -typedef std::vector cIPLookupPtrs; @@ -63,24 +58,8 @@ public: /** Returns the main LibEvent handle for event registering. */ event_base * GetEventBase(void) { return m_EventBase; } - /** Returns the LibEvent handle for DNS lookups. */ - evdns_base * GetDNSBase(void) { return m_DNSBase; } - - /** Adds the specified hostname lookup to m_HostnameLookups. - Used by the underlying lookup implementation when a new lookup is initiated. */ - void AddHostnameLookup(cHostnameLookupPtr a_HostnameLookup); - - /** Removes the specified hostname lookup from m_HostnameLookups. - Used by the underlying lookup implementation when the lookup is finished. */ - void RemoveHostnameLookup(const cHostnameLookup * a_HostnameLookup); - - /** Adds the specified IP lookup to M_IPLookups. - Used by the underlying lookup implementation when a new lookup is initiated. */ - void AddIPLookup(cIPLookupPtr a_IPLookup); - - /** Removes the specified IP lookup from m_IPLookups. - Used by the underlying lookup implementation when the lookup is finished. */ - void RemoveIPLookup(const cIPLookup * a_IPLookup); + /** Returns the thread used to perform hostname and IP lookups */ + cNetworkLookup & GetLookupThread() { return m_LookupThread; } /** Adds the specified link to m_Connections. Used by the underlying link implementation when a new link is created. */ @@ -104,26 +83,17 @@ protected: /** The main LibEvent container for driving the event loop. */ event_base * m_EventBase; - /** The LibEvent handle for doing DNS lookups. */ - evdns_base * m_DNSBase; - /** Container for all client connections, including ones with pending-connect. */ cTCPLinkImplPtrs m_Connections; /** Container for all servers that are currently active. */ cServerHandleImplPtrs m_Servers; - /** Container for all pending hostname lookups. */ - cHostnameLookupPtrs m_HostnameLookups; - - /** Container for all pending IP lookups. */ - cIPLookupPtrs m_IPLookups; - /** Mutex protecting all containers against multithreaded access. */ cCriticalSection m_CS; /** Set to true if Terminate has been called. */ - volatile bool m_HasTerminated; + std::atomic m_HasTerminated; /** The thread in which the main LibEvent loop runs. */ std::thread m_EventLoopThread; @@ -131,6 +101,9 @@ protected: /** Event that is signalled once the startup is finished and the LibEvent loop is running. */ cEvent m_StartupEvent; + /** The thread on which hostname and ip address lookup is performed. */ + cNetworkLookup m_LookupThread; + /** Converts LibEvent-generated log events into log messages in MCS log. */ static void LogCallback(int a_Severity, const char * a_Msg); -- cgit v1.2.3