mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-24 17:30:44 +02:00
fixed SF# 1985180: Poco::Net::DNS multithreading issue
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// DNS.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Net/src/DNS.cpp#2 $
|
||||
// $Id: //poco/Main/Net/src/DNS.cpp#9 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: NetCore
|
||||
@@ -82,7 +82,7 @@ DNS::DNSCache DNS::_cache;
|
||||
Poco::FastMutex DNS::_mutex;
|
||||
|
||||
|
||||
const HostEntry& DNS::hostByName(const std::string& hostname)
|
||||
HostEntry DNS::hostByName(const std::string& hostname)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
@@ -118,7 +118,7 @@ const HostEntry& DNS::hostByName(const std::string& hostname)
|
||||
}
|
||||
|
||||
|
||||
const HostEntry& DNS::hostByAddress(const IPAddress& address)
|
||||
HostEntry DNS::hostByAddress(const IPAddress& address)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
@@ -158,7 +158,7 @@ const HostEntry& DNS::hostByAddress(const IPAddress& address)
|
||||
}
|
||||
|
||||
|
||||
const HostEntry& DNS::resolve(const std::string& address)
|
||||
HostEntry DNS::resolve(const std::string& address)
|
||||
{
|
||||
IPAddress ip;
|
||||
if (IPAddress::tryParse(address, ip))
|
||||
@@ -170,7 +170,7 @@ const HostEntry& DNS::resolve(const std::string& address)
|
||||
|
||||
IPAddress DNS::resolveOne(const std::string& address)
|
||||
{
|
||||
const HostEntry& entry = resolve(address);
|
||||
HostEntry entry = resolve(address);
|
||||
if (!entry.addresses().empty())
|
||||
return entry.addresses()[0];
|
||||
else
|
||||
@@ -178,7 +178,7 @@ IPAddress DNS::resolveOne(const std::string& address)
|
||||
}
|
||||
|
||||
|
||||
const HostEntry& DNS::thisHost()
|
||||
HostEntry DNS::thisHost()
|
||||
{
|
||||
return hostByName(Environment::nodeName());
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// HostEntry.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Net/src/HostEntry.cpp#2 $
|
||||
// $Id: //poco/Main/Net/src/HostEntry.cpp#8 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: NetCore
|
||||
@@ -43,12 +43,17 @@ namespace Poco {
|
||||
namespace Net {
|
||||
|
||||
|
||||
HostEntry::HostEntry()
|
||||
//
|
||||
// HostEntryImpl
|
||||
//
|
||||
|
||||
|
||||
HostEntryImpl::HostEntryImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HostEntry::HostEntry(struct hostent* entry)
|
||||
HostEntryImpl::HostEntryImpl(struct hostent* entry)
|
||||
{
|
||||
poco_check_ptr (entry);
|
||||
|
||||
@@ -77,7 +82,7 @@ HostEntry::HostEntry(struct hostent* entry)
|
||||
#if defined(_WIN32) && defined(POCO_HAVE_IPv6)
|
||||
|
||||
|
||||
HostEntry::HostEntry(struct addrinfo* ainfo)
|
||||
HostEntryImpl::HostEntryImpl(struct addrinfo* ainfo)
|
||||
{
|
||||
poco_check_ptr (ainfo);
|
||||
|
||||
@@ -94,32 +99,34 @@ HostEntry::HostEntry(struct addrinfo* ainfo)
|
||||
#endif
|
||||
|
||||
|
||||
HostEntry::HostEntry(const HostEntry& entry):
|
||||
_name(entry._name),
|
||||
_aliases(entry._aliases),
|
||||
_addresses(entry._addresses)
|
||||
HostEntryImpl::~HostEntryImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HostEntry& HostEntry::operator = (const HostEntry& entry)
|
||||
//
|
||||
// HostEntry
|
||||
//
|
||||
|
||||
|
||||
HostEntry::HostEntry():
|
||||
_pImpl(new HostEntryImpl)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HostEntry::HostEntry(struct hostent* entry):
|
||||
_pImpl(new HostEntryImpl(entry))
|
||||
{
|
||||
if (&entry != this)
|
||||
{
|
||||
_name = entry._name;
|
||||
_aliases = entry._aliases;
|
||||
_addresses = entry._addresses;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void HostEntry::swap(HostEntry& hostEntry)
|
||||
#if defined(_WIN32) && defined(POCO_HAVE_IPv6)
|
||||
HostEntry::HostEntry(struct addrinfo* info):
|
||||
_pImpl(new HostEntryImpl(info))
|
||||
{
|
||||
std::swap(_name, hostEntry._name);
|
||||
std::swap(_aliases, hostEntry._aliases);
|
||||
std::swap(_addresses, hostEntry._addresses);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
HostEntry::~HostEntry()
|
||||
@@ -127,4 +134,18 @@ HostEntry::~HostEntry()
|
||||
}
|
||||
|
||||
|
||||
HostEntry::HostEntry(const HostEntry& entry):
|
||||
_pImpl(entry._pImpl)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HostEntry& HostEntry::operator = (const HostEntry& entry)
|
||||
{
|
||||
HostEntry tmp(entry);
|
||||
tmp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
||||
Reference in New Issue
Block a user