From c0cb787c101725a649d26de68fca2632c82830ba Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 18 Jan 2015 11:57:16 +0100 Subject: cNetwork: Split the main cpp file into several files. --- src/OSSupport/NetworkSingleton.cpp | 51 +++++--------------------------------- 1 file changed, 6 insertions(+), 45 deletions(-) (limited to 'src/OSSupport/NetworkSingleton.cpp') diff --git a/src/OSSupport/NetworkSingleton.cpp b/src/OSSupport/NetworkSingleton.cpp index 552abad64..c9d9b1d81 100644 --- a/src/OSSupport/NetworkSingleton.cpp +++ b/src/OSSupport/NetworkSingleton.cpp @@ -11,51 +11,8 @@ #include #include #include - - - - - -//////////////////////////////////////////////////////////////////////////////// -// Class definitions: - -/** Holds information about an in-progress Hostname-to-IP lookup. */ -class cHostnameLookup -{ - /** The callbacks to call for resolved names / errors. */ - cNetwork::cResolveNameCallbacksPtr m_Callbacks; - - /** The hostname that was queried (needed for the callbacks). */ - AString m_Hostname; - - static void Callback(int a_ErrCode, struct evutil_addrinfo * a_Addr, void * a_Self); - -public: - cHostnameLookup(const AString & a_Hostname, cNetwork::cResolveNameCallbacksPtr a_Callbacks); -}; -typedef SharedPtr cHostnameLookupPtr; -typedef std::vector cHostnameLookupPtrs; - - - - - -/** Holds information about an in-progress IP-to-Hostname lookup. */ -class cIPLookup -{ - /** The callbacks to call for resolved names / errors. */ - cNetwork::cResolveNameCallbacksPtr m_Callbacks; - - /** The IP that was queried (needed for the callbacks). */ - AString m_IP; - - static void Callback(int a_Result, char a_Type, int a_Count, int a_Ttl, void * a_Addresses, void * a_Self); - -public: - cIPLookup(const AString & a_IP, cNetwork::cResolveNameCallbacksPtr a_Callbacks); -}; -typedef SharedPtr cIPLookupPtr; -typedef std::vector cIPLookupPtrs; +#include "IPLookup.h" +#include "HostnameLookup.h" @@ -130,6 +87,8 @@ bool cNetworkSingleton::HostnameToIP( { try { + // TODO: This has a race condition with possible memory leak: + // If a lookup finishes immediately, the constructor calls the removal before this addition cCSLock Lock(m_CS); m_HostnameLookups.push_back(std::make_shared(a_Hostname, a_Callbacks)); } @@ -150,6 +109,8 @@ bool cNetworkSingleton::IPToHostName( { try { + // TODO: This has a race condition with possible memory leak: + // If a lookup finishes immediately, the constructor calls the removal before this addition cCSLock Lock(m_CS); m_IPLookups.push_back(std::make_shared(a_IP, a_Callbacks)); } -- cgit v1.2.3