summaryrefslogtreecommitdiff
path: root/src/resolver.cpp
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2009-03-22 17:50:10 +0000
committerChristian Pointner <equinox@anytun.org>2009-03-22 17:50:10 +0000
commitfd419ce4f2bcadae313f4f368361c733c1249ae9 (patch)
treeba244a9428e8b9cd5e40ceaa3857ab15a7a1a93e /src/resolver.cpp
parentupdated config (new option auth-tag-length) (diff)
added error callback to resolver for better handling
of resolvCallback exceptions
Diffstat (limited to 'src/resolver.cpp')
-rw-r--r--src/resolver.cpp29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/resolver.cpp b/src/resolver.cpp
index 5e2d862..06db1b4 100644
--- a/src/resolver.cpp
+++ b/src/resolver.cpp
@@ -34,34 +34,33 @@
#include "resolver.h"
#include "log.h"
-#include "signalController.h"
using ::boost::asio::ip::udp;
using ::boost::asio::ip::tcp;
template<class Proto>
-void waitAndEnqueue(u_int32_t s, const std::string& addr, const std::string& port, boost::function<void(boost::asio::ip::basic_endpoint<Proto>)> const& onResolve, ResolvAddrType r)
+void waitAndEnqueue(u_int32_t s, const std::string& addr, const std::string& port, boost::function<void(boost::asio::ip::basic_endpoint<Proto>)> const& onResolve, ErrorCallback const& onError, ResolvAddrType r)
{
cLog.msg(Log::PRIO_ERROR) << "the resolver only supports udp and tcp";
}
template<>
-void waitAndEnqueue(u_int32_t s, const std::string& addr, const std::string& port, boost::function<void(boost::asio::ip::basic_endpoint<udp>)> const& onResolve, ResolvAddrType r)
+void waitAndEnqueue(u_int32_t s, const std::string& addr, const std::string& port, boost::function<void(boost::asio::ip::basic_endpoint<udp>)> const& onResolve, ErrorCallback const& onError, ResolvAddrType r)
{
boost::this_thread::sleep(boost::posix_time::milliseconds(s * 1000));
- gResolver.resolveUdp(addr, port, onResolve, r);
+ gResolver.resolveUdp(addr, port, onResolve, onError, r);
}
template<>
-void waitAndEnqueue(u_int32_t s, const std::string& addr, const std::string& port, boost::function<void(boost::asio::ip::basic_endpoint<tcp>)> const& onResolve, ResolvAddrType r)
+void waitAndEnqueue(u_int32_t s, const std::string& addr, const std::string& port, boost::function<void(boost::asio::ip::basic_endpoint<tcp>)> const& onResolve, ErrorCallback const& onError, ResolvAddrType r)
{
boost::this_thread::sleep(boost::posix_time::milliseconds(s * 1000));
- gResolver.resolveTcp(addr, port, onResolve, r);
+ gResolver.resolveTcp(addr, port, onResolve, onError, r);
}
template<class Proto>
-ResolveHandler<Proto>::ResolveHandler(const std::string& addr, const std::string& port, boost::function<void(boost::asio::ip::basic_endpoint<Proto>)> const& onResolve, ResolvAddrType r) : addr_(addr), port_(port), callback_(onResolve), resolv_addr_type_(r)
+ResolveHandler<Proto>::ResolveHandler(const std::string& addr, const std::string& port, boost::function<void(boost::asio::ip::basic_endpoint<Proto>)> const& onResolve, ErrorCallback const& onError, ResolvAddrType r) : addr_(addr), port_(port), onResolve_(onResolve), onError_(onError), resolv_addr_type_(r)
{
}
@@ -70,15 +69,15 @@ void ResolveHandler<Proto>::operator()(const boost::system::error_code& e, const
{
if(boost::system::posix_error::success == e) {
try {
- callback_(*endpointIt);
+ onResolve_(*endpointIt);
}
catch(const std::runtime_error& e)
{
- gSignalController.inject(SIGERROR, e.what());
+ onError_(e);
}
} else {
- cLog.msg(Log::PRIO_ERROR) << "Error while resolving '" << addr_ << "' '" << port_ << "', retrying in 10 sec.";
- boost::thread(boost::bind(waitAndEnqueue<Proto>, 10, addr_, port_, callback_, resolv_addr_type_));
+ cLog.msg(Log::PRIO_ERROR) << "Error while resolving '" << addr_ << "' '" << port_ << "', retrying in 10 sec.";
+ boost::thread(boost::bind(waitAndEnqueue<Proto>, 10, addr_, port_, onResolve_, onError_, resolv_addr_type_));
}
}
@@ -134,7 +133,7 @@ void Resolver::run()
}
-void Resolver::resolveUdp(const std::string& addr, const std::string& port, boost::function<void (udp::endpoint)> const& onResolve, ResolvAddrType r)
+void Resolver::resolveUdp(const std::string& addr, const std::string& port, UdpResolveCallback const& onResolve, ErrorCallback const& onError, ResolvAddrType r)
{
cLog.msg(Log::PRIO_DEBUG) << "trying to resolv UDP: '" << addr << "' '" << port << "'";
@@ -153,11 +152,11 @@ void Resolver::resolveUdp(const std::string& addr, const std::string& port, boos
default: query = std::auto_ptr<udp::resolver::query>(new udp::resolver::query(port)); break;
}
}
- UdpResolveHandler handler(addr, port, onResolve, r);
+ UdpResolveHandler handler(addr, port, onResolve, onError, r);
udp_resolver_.async_resolve(*query, handler);
}
-void Resolver::resolveTcp(const std::string& addr, const std::string& port, boost::function<void (tcp::endpoint)> const& onResolve, ResolvAddrType r)
+void Resolver::resolveTcp(const std::string& addr, const std::string& port, TcpResolveCallback const& onResolve, ErrorCallback const& onError, ResolvAddrType r)
{
cLog.msg(Log::PRIO_DEBUG) << "trying to resolv TCP: '" << addr << "' '" << port << "'";
@@ -176,6 +175,6 @@ void Resolver::resolveTcp(const std::string& addr, const std::string& port, boos
default: query = std::auto_ptr<tcp::resolver::query>(new tcp::resolver::query(port)); break;
}
}
- TcpResolveHandler handler(addr, port, onResolve, r);
+ TcpResolveHandler handler(addr, port, onResolve, onError, r);
tcp_resolver_.async_resolve(*query, handler);
}