fixed SF# 1985180: Poco::Net::DNS multithreading issue

This commit is contained in:
Guenter Obiltschnig
2008-06-09 14:21:56 +00:00
parent b3d124f14a
commit 076c301460
4 changed files with 131 additions and 40 deletions

View File

@@ -1,7 +1,7 @@
//
// DNS.h
//
// $Id: //poco/svn/Net/include/Poco/Net/DNS.h#2 $
// $Id: //poco/Main/Net/include/Poco/Net/DNS.h#3 $
//
// Library: Net
// Package: NetCore
@@ -59,7 +59,7 @@ class Net_API DNS
/// An internal DNS cache is used to speed up name lookups.
{
public:
static const HostEntry& hostByName(const std::string& hostname);
static HostEntry hostByName(const std::string& hostname);
/// Returns a HostEntry object containing the DNS information
/// for the host with the given name.
///
@@ -73,7 +73,7 @@ public:
///
/// Throws an IOException in case of any other error.
static const HostEntry& hostByAddress(const IPAddress& address);
static HostEntry hostByAddress(const IPAddress& address);
/// Returns a HostEntry object containing the DNS information
/// for the host with the given IP address.
///
@@ -84,7 +84,7 @@ public:
///
/// Throws an IOException in case of any other error.
static const HostEntry& resolve(const std::string& address);
static HostEntry resolve(const std::string& address);
/// Returns a HostEntry object containing the DNS information
/// for the host with the given IP address or host name.
///
@@ -102,7 +102,7 @@ public:
/// Convenience method that calls resolve(address) and returns
/// the first address from the HostInfo.
static const HostEntry& thisHost();
static HostEntry thisHost();
/// Returns a HostEntry object containing the DNS information
/// for this host.
///

View File

@@ -1,7 +1,7 @@
//
// HostEntry.h
//
// $Id: //poco/svn/Net/include/Poco/Net/HostEntry.h#2 $
// $Id: //poco/Main/Net/include/Poco/Net/HostEntry.h#3 $
//
// Library: Net
// Package: NetCore
@@ -43,6 +43,8 @@
#include "Poco/Net/Net.h"
#include "Poco/Net/SocketDefs.h"
#include "Poco/Net/IPAddress.h"
#include "Poco/RefCountedObject.h"
#include "Poco/AutoPtr.h"
#include <vector>
@@ -50,14 +52,60 @@ namespace Poco {
namespace Net {
class Net_API HostEntryImpl: public Poco::RefCountedObject
/// This class stores information about a host
/// such as host name, alias names and a list
/// of IP addresses.
///
/// This class is used internally by HostEntry and is not
/// intended for public use.
{
protected:
typedef std::vector<std::string> AliasList;
typedef std::vector<IPAddress> AddressList;
HostEntryImpl();
/// Creates an empty HostEntry.
HostEntryImpl(struct hostent* entry);
/// Creates the HostEntry from the data in a hostent structure.
#if defined(_WIN32) && defined(POCO_HAVE_IPv6)
HostEntryImpl(struct addrinfo* info);
/// Creates the HostEntry from the data in a Windows addrinfo structure.
#endif
~HostEntryImpl();
/// Destroys the HostEntryImpl.
const std::string& name() const;
/// Returns the canonical host name.
const AliasList& aliases() const;
/// Returns a vector containing alias names for
/// the host name.
const AddressList& addresses() const;
/// Returns a vector containing the IPAddresses
/// for the host.
private:
std::string _name;
AliasList _aliases;
AddressList _addresses;
friend class HostEntry;
};
class Net_API HostEntry
/// This class stores information about a host
/// such as host name, alias names and a list
/// of IP addresses.
{
public:
typedef std::vector<std::string> AliasList;
typedef std::vector<IPAddress> AddressList;
typedef HostEntryImpl::AliasList AliasList;
typedef HostEntryImpl::AddressList AddressList;
HostEntry();
/// Creates an empty HostEntry.
@@ -94,33 +142,55 @@ public:
/// for the host.
private:
std::string _name;
AliasList _aliases;
AddressList _addresses;
Poco::AutoPtr<HostEntryImpl> _pImpl;
};
//
// inlines
//
inline const std::string& HostEntry::name() const
inline const std::string& HostEntryImpl::name() const
{
return _name;
}
inline const HostEntry::AliasList& HostEntry::aliases() const
inline const HostEntryImpl::AliasList& HostEntryImpl::aliases() const
{
return _aliases;
}
inline const HostEntry::AddressList& HostEntry::addresses() const
inline const HostEntryImpl::AddressList& HostEntryImpl::addresses() const
{
return _addresses;
}
inline const std::string& HostEntry::name() const
{
return _pImpl->name();
}
inline const HostEntry::AliasList& HostEntry::aliases() const
{
return _pImpl->aliases();
}
inline const HostEntry::AddressList& HostEntry::addresses() const
{
return _pImpl->addresses();
}
inline void HostEntry::swap(HostEntry& other)
{
_pImpl.swap(other._pImpl);
}
inline void swap(HostEntry& h1, HostEntry& h2)
{
h1.swap(h2);