--- jcc.c.orig Sun Apr 3 22:10:50 2005 +++ jcc.c Sun Apr 9 14:48:52 2006 @@ -857,6 +857,7 @@ fd_set rfds; int n; jb_socket maxfd; + unsigned int socks_retries = 0; int server_body; int ms_iis5_hack = 0; int byte_count = 0; @@ -1207,10 +1208,19 @@ log_error(LOG_LEVEL_CONNECT, "to %s", http->hostport); } - /* here we connect to the server, gateway, or the forwarder */ - - csp->sfd = forwarded_connect(fwd, http, csp); - + /* Here we connect to the server, gateway, or the forwarder. + * + * If socks4a is used, EINVAL can be the result of a DNS + * timeout on the socks server. Retry several times to + * make sure it's a real problem before bothering the user. + */ + + while ( (csp->sfd = forwarded_connect(fwd, http, csp)) + && (fwd->type == SOCKS_4A) && (errno == EINVAL) && (socks_retries++ < 3)) + { + log_error(LOG_LEVEL_ERROR, "failed the %u. time to connect to %s. Trying again.", + socks_retries, http->hostport); + } if (csp->sfd == JB_INVALID_SOCKET) { log_error(LOG_LEVEL_CONNECT, "connect to: %s failed: %E",