From e808ee8668e19337773a5e2b2e35f5aabb84baf7 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 5 Mar 2009 01:21:31 +0000 Subject: added resolvAddrType to gResolver --- src/resolver.cpp | 50 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) (limited to 'src/resolver.cpp') diff --git a/src/resolver.cpp b/src/resolver.cpp index 7439f3d..e0d6fa8 100644 --- a/src/resolver.cpp +++ b/src/resolver.cpp @@ -35,7 +35,7 @@ #include "resolver.h" #include "log.h" -template ResolveHandler::ResolveHandler(const std::string& addr, const std::string& port, boost::function)> const& onResolve) : addr_(addr), port_(port), callback_(onResolve) +template ResolveHandler::ResolveHandler(const std::string& addr, const std::string& port, boost::function)> const& onResolve, ResolvAddrType r) : addr_(addr), port_(port), callback_(onResolve), resolv_addr_type_(r) { } @@ -90,20 +90,52 @@ void Resolver::run() } } -void Resolver::resolveUdp(const std::string& addr, const std::string& port, boost::function const& onResolve) +using ::boost::asio::ip::udp; + +void Resolver::resolveUdp(const std::string& addr, const std::string& port, boost::function const& onResolve, ResolvAddrType r) { cLog.msg(Log::PRIO_DEBUG) << "trying to resolv UDP: " << addr << " " << port; - boost::asio::ip::udp::resolver::query query(addr, port); - UdpResolveHandler handler(addr, port, onResolve); - udp_resolver_.async_resolve(query, handler); + std::auto_ptr query; + if(addr != "") { + switch(r) { + case IPV4_ONLY: query = std::auto_ptr(new udp::resolver::query(udp::v4(), addr, port)); break; + case IPV6_ONLY: query = std::auto_ptr(new udp::resolver::query(udp::v6(), addr, port)); break; + default: query = std::auto_ptr(new udp::resolver::query(addr, port)); break; + } + } + else { + switch(r) { + case IPV4_ONLY: query = std::auto_ptr(new udp::resolver::query(udp::v4(), port)); break; + case IPV6_ONLY: query = std::auto_ptr(new udp::resolver::query(udp::v6(), port)); break; + default: query = std::auto_ptr(new udp::resolver::query(port)); break; + } + } + UdpResolveHandler handler(addr, port, onResolve, r); + udp_resolver_.async_resolve(*query, handler); } -void Resolver::resolveTcp(const std::string& addr, const std::string& port, boost::function const& onResolve) +using ::boost::asio::ip::tcp; + +void Resolver::resolveTcp(const std::string& addr, const std::string& port, boost::function const& onResolve, ResolvAddrType r) { cLog.msg(Log::PRIO_DEBUG) << "trying to resolv TCP: " << addr << " " << port; - boost::asio::ip::tcp::resolver::query query(addr, port); - TcpResolveHandler handler(addr, port, onResolve); - tcp_resolver_.async_resolve(query, handler); + std::auto_ptr query; + if(addr != "") { + switch(r) { + case IPV4_ONLY: query = std::auto_ptr(new tcp::resolver::query(tcp::v4(), addr, port)); break; + case IPV6_ONLY: query = std::auto_ptr(new tcp::resolver::query(tcp::v6(), addr, port)); break; + default: query = std::auto_ptr(new tcp::resolver::query(addr, port)); break; + } + } + else { + switch(r) { + case IPV4_ONLY: query = std::auto_ptr(new tcp::resolver::query(tcp::v4(), port)); break; + case IPV6_ONLY: query = std::auto_ptr(new tcp::resolver::query(tcp::v6(), port)); break; + default: query = std::auto_ptr(new tcp::resolver::query(port)); break; + } + } + TcpResolveHandler handler(addr, port, onResolve, r); + tcp_resolver_.async_resolve(*query, handler); } -- cgit v1.2.3