From 577fc127f7cc7592c9c6b905da8dc5a1d70868dd Mon Sep 17 00:00:00 2001 From: david Date: Wed, 13 Jan 2010 19:22:41 +0000 Subject: [PATCH] Use socket_strerror, not plain strerror, to report the result of non-blocking connections in tcpip.cc. socket_strerror works with Winsock error codes whereas plain strerror returns "Unknown error". However, the error string for what is probably the most common error code, WSAEWOULDBLOCK, is the big ugly "A non-blocking socket operation could not be completed immediately.". Add a special case to use "Operation now in progress" for that specific error. --- tcpip.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tcpip.cc b/tcpip.cc index bdb8c42c0..8fb7d0494 100644 --- a/tcpip.cc +++ b/tcpip.cc @@ -825,10 +825,18 @@ void PacketTrace::traceConnect(u8 proto, const struct sockaddr *sock, assert(proto == IPPROTO_TCP || proto == IPPROTO_UDP); - if (connectrc == 0) + if (connectrc == 0) { Strncpy(errbuf, "Connected", sizeof(errbuf)); + } +#if WIN32 + else if (connect_errno == WSAEWOULDBLOCK) { + /* Special case for WSAEWOULDBLOCK. socket_strerror returns the unwieldy + "A non-blocking socket operation could not be completed immediately." */ + Strncpy(errbuf, "Operation now in progress", sizeof(errbuf)); + } +#endif else { - Snprintf(errbuf, sizeof(errbuf), "%s", strerror(connect_errno)); + Snprintf(errbuf, sizeof(errbuf), "%s", socket_strerror(connect_errno)); } if (sin->sin_family == AF_INET) {