mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-23 16:48:06 +02:00
added DNS::reload()
This commit is contained in:
@@ -44,7 +44,6 @@
|
|||||||
#include "Poco/Net/SocketDefs.h"
|
#include "Poco/Net/SocketDefs.h"
|
||||||
#include "Poco/Net/IPAddress.h"
|
#include "Poco/Net/IPAddress.h"
|
||||||
#include "Poco/Net/HostEntry.h"
|
#include "Poco/Net/HostEntry.h"
|
||||||
#include "Poco/Mutex.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
@@ -115,6 +114,13 @@ public:
|
|||||||
///
|
///
|
||||||
/// Throws an IOException in case of any other error.
|
/// Throws an IOException in case of any other error.
|
||||||
|
|
||||||
|
static void reload();
|
||||||
|
/// Reloads the resolver configuration.
|
||||||
|
///
|
||||||
|
/// This method will call res_init() if the Net library
|
||||||
|
/// has been compiled with -DPOCO_HAVE_LIBRESOLV. Otherwise
|
||||||
|
/// it will do nothing.
|
||||||
|
|
||||||
//@ deprecated
|
//@ deprecated
|
||||||
static void flushCache();
|
static void flushCache();
|
||||||
/// Flushes the internal DNS cache.
|
/// Flushes the internal DNS cache.
|
||||||
|
@@ -39,11 +39,15 @@
|
|||||||
#include "Poco/Net/SocketAddress.h"
|
#include "Poco/Net/SocketAddress.h"
|
||||||
#include "Poco/Environment.h"
|
#include "Poco/Environment.h"
|
||||||
#include "Poco/NumberFormatter.h"
|
#include "Poco/NumberFormatter.h"
|
||||||
#include "Poco/AtomicCounter.h"
|
#include "Poco/RWLock.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
|
||||||
using Poco::FastMutex;
|
#if defined(POCO_HAVE_LIBRESOLV)
|
||||||
|
#include <resolv.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
using Poco::Environment;
|
using Poco::Environment;
|
||||||
using Poco::NumberFormatter;
|
using Poco::NumberFormatter;
|
||||||
using Poco::IOException;
|
using Poco::IOException;
|
||||||
@@ -53,8 +57,17 @@ namespace Poco {
|
|||||||
namespace Net {
|
namespace Net {
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(POCO_HAVE_LIBRESOLV)
|
||||||
|
static Poco::RWLock resolverLock;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
HostEntry DNS::hostByName(const std::string& hostname)
|
HostEntry DNS::hostByName(const std::string& hostname)
|
||||||
{
|
{
|
||||||
|
#if defined(POCO_HAVE_LIBRESOLV)
|
||||||
|
Poco::ScopedReadRWLock readLock(resolverLock);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(POCO_HAVE_IPv6) || defined(POCO_HAVE_ADDRINFO)
|
#if defined(POCO_HAVE_IPv6) || defined(POCO_HAVE_ADDRINFO)
|
||||||
struct addrinfo* pAI;
|
struct addrinfo* pAI;
|
||||||
struct addrinfo hints;
|
struct addrinfo hints;
|
||||||
@@ -91,6 +104,10 @@ HostEntry DNS::hostByName(const std::string& hostname)
|
|||||||
|
|
||||||
HostEntry DNS::hostByAddress(const IPAddress& address)
|
HostEntry DNS::hostByAddress(const IPAddress& address)
|
||||||
{
|
{
|
||||||
|
#if defined(POCO_HAVE_LIBRESOLV)
|
||||||
|
Poco::ScopedReadRWLock readLock(resolverLock);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(POCO_HAVE_IPv6) || defined(POCO_HAVE_ADDRINFO)
|
#if defined(POCO_HAVE_IPv6) || defined(POCO_HAVE_ADDRINFO)
|
||||||
SocketAddress sa(address, 0);
|
SocketAddress sa(address, 0);
|
||||||
static char fqname[1024];
|
static char fqname[1024];
|
||||||
@@ -162,6 +179,15 @@ HostEntry DNS::thisHost()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DNS::reload()
|
||||||
|
{
|
||||||
|
#if defined(POCO_HAVE_LIBRESOLV)
|
||||||
|
Poco::ScopedWriteRWLock writeLock(resolverLock);
|
||||||
|
res_init();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void DNS::flushCache()
|
void DNS::flushCache()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -214,7 +240,7 @@ void DNS::error(int code, const std::string& arg)
|
|||||||
|
|
||||||
void DNS::aierror(int code, const std::string& arg)
|
void DNS::aierror(int code, const std::string& arg)
|
||||||
{
|
{
|
||||||
#if defined(POCO_HAVE_IPv6)
|
#if defined(POCO_HAVE_IPv6) || defined(POCO_HAVE_ADDRINFO)
|
||||||
switch (code)
|
switch (code)
|
||||||
{
|
{
|
||||||
case EAI_AGAIN:
|
case EAI_AGAIN:
|
||||||
@@ -241,7 +267,7 @@ void DNS::aierror(int code, const std::string& arg)
|
|||||||
default:
|
default:
|
||||||
throw DNSException("EAI", NumberFormatter::format(code));
|
throw DNSException("EAI", NumberFormatter::format(code));
|
||||||
}
|
}
|
||||||
#endif // POCO_HAVE_IPv6
|
#endif // POCO_HAVE_IPv6 || defined(POCO_HAVE_ADDRINFO)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user