1eebf72e7ad8714a1e1747273feecad599bea8ec max Tue May 9 06:55:25 2023 -0700 improving error message when server cannot be connected to. refs #15324 diff --git src/lib/net.c src/lib/net.c index baa3a02..0795279 100644 --- src/lib/net.c +++ src/lib/net.c @@ -9,30 +9,32 @@ #include #include #include #include "errAbort.h" #include "hash.h" #include "net.h" #include "linefile.h" #include "base64.h" #include "cheapcgi.h" #include "htmlPage.h" #include "https.h" #include "sqlNum.h" #include "obscure.h" #include "errCatch.h" +char *timeoutErrorMessage = ""; + /* Brought errno in to get more useful error messages */ extern int errno; static int netStreamSocketFromAddrInfo(struct addrinfo *address) /* Create a socket from addrinfo structure. * Complain and return something negative if can't. */ { int sd = socket(address->ai_family, address->ai_socktype, address->ai_protocol); if (sd < 0) warn("Couldn't make %s socket.", familyToString(address->ai_family)); return sd; } static int setSocketNonBlocking(int sd, boolean set) @@ -162,31 +164,31 @@ if (getsockopt(sd, SOL_SOCKET, SO_ERROR, (void*) (&valOpt), &lon) < 0) { warn("Error in getsockopt() %d - %s", errno, strerror(errno)); return -1; } // Check the value returned... if (valOpt) { dyStringPrintf(dy, "Error in TCP non-blocking connect() %d - %s. Host %s IP %s port %d.\n", valOpt, strerror(valOpt), hostName, ipStr, port); return -1; } break; // OK } else { - dyStringPrintf(dy, "TCP non-blocking connect() to %s IP %s timed-out in select() after %ld milliseconds - Cancelling!", hostName, ipStr, msTimeout); + dyStringPrintf(dy, "TCP non-blocking connect() to %s IP %s timed-out in select() after %ld milliseconds. %s", hostName, ipStr, msTimeout, timeoutErrorMessage); return -1; } } } else { dyStringPrintf(dy, "TCP non-blocking connect() error %d - %s", errno, strerror(errno)); return -1; } } return 0; // OK } int netConnectWithTimeout(char *hostName, int port, long msTimeout) @@ -2314,15 +2316,18 @@ } break; } } } return qCount; } /* netHttpMultipleQueries */ boolean hasProtocol(char *urlOrPath) /* Return TRUE if it looks like it has http://, ftp:// etc. */ { return stringIn("://", urlOrPath) != NULL; } +void netSetTimeoutErrorMsg(char *msg) { + timeoutErrorMessage = msg; +}