← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2705: Socket::resolve doesn't throw

 

------------------------------------------------------------
revno: 2705
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Thu 2011-12-08 18:17:49 +0100
message:
  Socket::resolve doesn't throw
modified:
  dcpp/Socket.cpp
  dcpp/Socket.h


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'dcpp/Socket.cpp'
--- dcpp/Socket.cpp	2011-12-06 19:51:07 +0000
+++ dcpp/Socket.cpp	2011-12-08 17:17:49 +0000
@@ -282,7 +282,8 @@
 	addrinfo_p ai(nullptr, nullptr);
 
 	if(!v4only) {
-		try { ai = resolveAddr(localIp6, port, AF_INET6, AI_PASSIVE | AI_ADDRCONFIG); } catch(const SocketException&) { }
+		try { ai = resolveAddr(localIp6, port, AF_INET6, AI_PASSIVE | AI_ADDRCONFIG); }
+		catch(const SocketException&) { ai.reset(); }
 		for(auto a = ai.get(); a && !sock6.valid(); a = a->ai_next) {
 			try {
 				create(*a);
@@ -301,7 +302,8 @@
 		}
 	}
 
-	try { ai = resolveAddr(localIp4, port, AF_INET, AI_PASSIVE | AI_ADDRCONFIG); } catch(const SocketException&) { }
+	try { ai = resolveAddr(localIp4, port, AF_INET, AI_PASSIVE | AI_ADDRCONFIG); }
+	catch(const SocketException&) { ai.reset(); }
 	for(auto a = ai.get(); a && !sock4.valid(); a = a->ai_next) {
 		try {
 			create(*a);
@@ -737,20 +739,21 @@
 	return true;
 }
 
-string Socket::resolve(const string& aDns, int af) {
+string Socket::resolve(const string& aDns, int af) noexcept {
 	addrinfo hints = { 0 };
 	hints.ai_family = af;
 
 	addrinfo *result = 0;
 
-	auto err = ::getaddrinfo(aDns.c_str(), NULL, &hints, &result);
-	if(err) {
-		throw SocketException(err);
+	string ret;
+
+	if(!::getaddrinfo(aDns.c_str(), NULL, &hints, &result)) {
+		try { ret = resolveName(result->ai_addr, result->ai_addrlen); }
+		catch(const SocketException&) { }
+
+		::freeaddrinfo(result);
 	}
 
-	auto ret = resolveName(result->ai_addr, result->ai_addrlen);
-	::freeaddrinfo(result);
-
 	return ret;
 }
 

=== modified file 'dcpp/Socket.h'
--- dcpp/Socket.h	2011-10-22 16:41:13 +0000
+++ dcpp/Socket.h	2011-12-08 17:17:49 +0000
@@ -153,7 +153,7 @@
 	virtual std::pair<bool, bool> wait(uint32_t millis, bool checkRead, bool checkWrite);
 
 	typedef std::unique_ptr<addrinfo, decltype(&freeaddrinfo)> addrinfo_p;
-	static string resolve(const string& aDns, int af = AF_UNSPEC);
+	static string resolve(const string& aDns, int af = AF_UNSPEC) noexcept;
 	addrinfo_p resolveAddr(const string& name, const string& port, int family = AF_UNSPEC, int flags = 0);
 
 	static uint64_t getTotalDown() { return stats.totalDown; }