Throw GAIException() for getaddrinfo errors
Created a new subclass of Exception called GAIException() that will handle error messages from getaddrinfo() instead of letting Exception() handle it. GAIException() will make use of gai_strerror() to map the error code to text. On Windows, gai_strerrorW() must be used if the text is encoded with UTF-8.
This commit is contained in:
committed by
Lauri Kasanen
parent
209712b18f
commit
03639406dc
@@ -151,8 +151,7 @@ TcpSocket::TcpSocket(const char *host, int port)
|
||||
hints.ai_next = NULL;
|
||||
|
||||
if ((result = getaddrinfo(host, NULL, &hints, &ai)) != 0) {
|
||||
throw Exception("unable to resolve host by name: %s",
|
||||
gai_strerror(result));
|
||||
throw GAIException("unable to resolve host by name", result);
|
||||
}
|
||||
|
||||
sock = -1;
|
||||
@@ -603,8 +602,7 @@ void network::createTcpListeners(std::list<SocketListener*> *listeners,
|
||||
snprintf (service, sizeof (service) - 1, "%d", port);
|
||||
service[sizeof (service) - 1] = '\0';
|
||||
if ((result = getaddrinfo(addr, service, &hints, &ai)) != 0)
|
||||
throw rdr::Exception("unable to resolve listening address: %s",
|
||||
gai_strerror(result));
|
||||
throw GAIException("unable to resolve listening address", result);
|
||||
|
||||
try {
|
||||
createTcpListeners(listeners, ai);
|
||||
@@ -913,8 +911,7 @@ TcpFilter::Pattern TcpFilter::parsePattern(const char* p) {
|
||||
}
|
||||
|
||||
if ((result = getaddrinfo (p, NULL, &hints, &ai)) != 0) {
|
||||
throw Exception("unable to resolve host by name: %s",
|
||||
gai_strerror(result));
|
||||
throw GAIException("unable to resolve host by name", result);
|
||||
}
|
||||
|
||||
memcpy (&pattern.address.u.sa, ai->ai_addr, ai->ai_addrlen);
|
||||
|
||||
Reference in New Issue
Block a user