summaryrefslogtreecommitdiffstats
path: root/src/OSSupport/NetworkSingleton.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2015-01-18 11:57:16 +0100
committerMattes D <github@xoft.cz>2015-01-22 20:13:02 +0100
commitc0cb787c101725a649d26de68fca2632c82830ba (patch)
treec5efafa98e7ccfa628f5873e5611b49ff0b44d21 /src/OSSupport/NetworkSingleton.cpp
parentcNetwork: Fixed WinXP dualstack listening. (diff)
downloadcuberite-c0cb787c101725a649d26de68fca2632c82830ba.tar
cuberite-c0cb787c101725a649d26de68fca2632c82830ba.tar.gz
cuberite-c0cb787c101725a649d26de68fca2632c82830ba.tar.bz2
cuberite-c0cb787c101725a649d26de68fca2632c82830ba.tar.lz
cuberite-c0cb787c101725a649d26de68fca2632c82830ba.tar.xz
cuberite-c0cb787c101725a649d26de68fca2632c82830ba.tar.zst
cuberite-c0cb787c101725a649d26de68fca2632c82830ba.zip
Diffstat (limited to '')
-rw-r--r--src/OSSupport/NetworkSingleton.cpp51
1 files changed, 6 insertions, 45 deletions
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 <event2/bufferevent.h>
#include <event2/dns.h>
#include <event2/listener.h>
-
-
-
-
-
-////////////////////////////////////////////////////////////////////////////////
-// 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<cHostnameLookup> cHostnameLookupPtr;
-typedef std::vector<cHostnameLookupPtr> 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<cIPLookup> cIPLookupPtr;
-typedef std::vector<cIPLookupPtr> 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<cHostnameLookup>(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<cIPLookup>(a_IP, a_Callbacks));
}