summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2015-07-30 12:24:36 +0200
committerPierre Ossman <ossman@cendio.se>2015-07-30 12:24:36 +0200
commit5a126667a3e375df227be69689a150fec0d75a28 (patch)
treeec2c464d94621f17f988ddbc172a93bcb7659d22
parenta5b37c0366478e469b6b3b41f903b03634113a7e (diff)
downloadtigervnc-5a126667a3e375df227be69689a150fec0d75a28.tar.gz
tigervnc-5a126667a3e375df227be69689a150fec0d75a28.zip
Properly report connect error codes
The logic was flawed and would treat all connect errors as if there were no addresses found.
-rw-r--r--common/network/TcpSocket.cxx24
1 files changed, 13 insertions, 11 deletions
diff --git a/common/network/TcpSocket.cxx b/common/network/TcpSocket.cxx
index 1ebaeecb..684ff8b3 100644
--- a/common/network/TcpSocket.cxx
+++ b/common/network/TcpSocket.cxx
@@ -145,9 +145,7 @@ TcpSocket::TcpSocket(int sock, bool close)
TcpSocket::TcpSocket(const char *host, int port)
: closeFd(true)
{
- int sock, err, result, family;
- vnc_sockaddr_t sa;
- socklen_t salen;
+ int sock, err, result;
struct addrinfo *ai, *current, hints;
// - Create a socket
@@ -165,11 +163,13 @@ TcpSocket::TcpSocket(const char *host, int port)
gai_strerror(result));
}
- // This logic is too complex for the compiler to determine if
- // sock is properly assigned or not.
sock = -1;
-
+ err = 0;
for (current = ai; current != NULL; current = current->ai_next) {
+ int family;
+ vnc_sockaddr_t sa;
+ socklen_t salen;
+
family = current->ai_family;
switch (family) {
@@ -208,6 +208,7 @@ TcpSocket::TcpSocket(const char *host, int port)
continue;
#endif
closesocket(sock);
+ sock = -1;
break;
}
@@ -217,11 +218,12 @@ TcpSocket::TcpSocket(const char *host, int port)
freeaddrinfo(ai);
- if (current == NULL)
- throw Exception("No useful address for host");
-
- if (result == -1)
- throw SocketException("unable connect to socket", err);
+ if (sock == -1) {
+ if (err == 0)
+ throw Exception("No useful address for host");
+ else
+ throw SocketException("unable connect to socket", err);
+ }
#ifndef WIN32
// - By default, close the socket on exec()