From 509154dc8162a648b4938fb48b1273eba80bae12 Mon Sep 17 00:00:00 2001 From: hniksic Date: Thu, 13 Nov 2003 14:27:38 -0800 Subject: [PATCH] [svn] Use the new function retryable_socket_connect_error instead of the CONNECT_ERROR macro. --- src/ChangeLog | 12 ++++++++++++ src/connect.c | 35 ++++++++++++++++++++++------------- src/connect.h | 2 +- src/ftp.c | 6 ++++-- src/http.c | 3 ++- src/wget.h | 11 ----------- 6 files changed, 41 insertions(+), 28 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 0bd2ec89..69eb8f39 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +2003-11-13 Hrvoje Niksic + + * http.c (gethttp): Ditto. + + * ftp.c (getftp): Use retryable_socket_connect_error instead of + CONNECT_ERROR. + + * wget.h (CONNECT_ERROR): Removed. + + * connect.c (retryable_socket_connect_error): New function instead + of unsupported_socket_family_error. + 2003-11-13 Hrvoje Niksic * wget.h (CONNECT_ERROR): Use it. diff --git a/src/connect.c b/src/connect.c index f73c9501..f69b3a69 100644 --- a/src/connect.c +++ b/src/connect.c @@ -574,34 +574,43 @@ socket_ip_address (int sock, ip_address *ip, int endpoint) return 0; } -/* Return non-zero of the errno code passed to the function is a - result of an attempt to create a socket of unsupported family. */ +/* Return non-zero if the error from the connect code can be + considered retryable. Wget normally retries after errors, but the + exception are the "unsupported protocol" type errors (possible on + IPv4/IPv6 dual family systems) and "connection refused". */ int -unsupported_socket_family_error (int err) +retryable_socket_connect_error (int err) { /* Have to guard against some of these values not being defined. - Cannot use switch because some of the values might be equal. */ + Cannot use a switch statement because some of the values might be + equal. */ + if (0 #ifdef EAFNOSUPPORT - if (err == EAFNOSUPPORT) return 1; + || err == EAFNOSUPPORT #endif #ifdef EPFNOSUPPORT - if (err == EPFNOSUPPORT) return 1; + || err == EPFNOSUPPORT #endif #ifdef ESOCKTNOSUPPORT /* no, "sockt" is not a typo! */ - if (err == ESOCKTNOSUPPORT) return 1; + || err == ESOCKTNOSUPPORT #endif #ifdef EPROTONOSUPPORT - if (err == EPROTONOSUPPORT) return 1; + || err == EPROTONOSUPPORT #endif #ifdef ENOPROTOOPT - if (err == ENOPROTOOPT) return 1; + || err == ENOPROTOOPT #endif - /* Apparently, older versions of Linux used EINVAL instead of - EAFNOSUPPORT. */ - if (err == EINVAL) return 1; + /* Apparently, older versions of Linux and BSD used EINVAL + instead of EAFNOSUPPORT and such. */ + || err == EINVAL + ) + return 0; - return 0; + if (err == ECONNREFUSED && !opt.retry_connrefused) + return 0; + + return 1; } #ifdef HAVE_SELECT diff --git a/src/connect.h b/src/connect.h index 8872ee78..7de02ce3 100644 --- a/src/connect.h +++ b/src/connect.h @@ -56,7 +56,7 @@ enum { }; int socket_ip_address PARAMS ((int, ip_address *, int)); -int unsupported_socket_family_error PARAMS ((int)); +int retryable_socket_connect_error PARAMS ((int)); /* Flags for select_fd's WAIT_FOR argument. */ enum { diff --git a/src/ftp.c b/src/ftp.c index 21b023c2..8159a2d9 100644 --- a/src/ftp.c +++ b/src/ftp.c @@ -291,7 +291,8 @@ getftp (struct url *u, long *len, long restval, ccon *con) if (csock == E_HOST) return HOSTERR; else if (csock < 0) - return CONNECT_ERROR (errno); + return (retryable_socket_connect_error (errno) + ? CONERROR : CONIMPOSSIBLE); if (cmd & LEAVE_PENDING) rbuf_initialize (&con->rbuf, csock); @@ -693,7 +694,8 @@ Error in server response, closing control connection.\n")); logprintf (LOG_VERBOSE, _("couldn't connect to %s port %hu: %s\n"), pretty_print_address (&passive_addr), passive_port, strerror (save_errno)); - return CONNECT_ERROR (save_errno); + return (retryable_socket_connect_error (save_errno) + ? CONERROR : CONIMPOSSIBLE); } pasv_mode_open = 1; /* Flag to avoid accept port */ diff --git a/src/http.c b/src/http.c index ee8d4def..f25a6782 100644 --- a/src/http.c +++ b/src/http.c @@ -704,7 +704,8 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy) if (sock == E_HOST) return HOSTERR; else if (sock < 0) - return CONNECT_ERROR (errno); + return (retryable_socket_connect_error (errno) + ? CONERROR : CONIMPOSSIBLE); #ifdef HAVE_SSL if (conn->scheme == SCHEME_HTTPS) diff --git a/src/wget.h b/src/wget.h index edc15990..e582e008 100644 --- a/src/wget.h +++ b/src/wget.h @@ -223,15 +223,4 @@ typedef enum SSLERRCERTFILE,SSLERRCERTKEY,SSLERRCTXCREATE } uerr_t; -/* Whether the connection was unsuccessful or impossible. If the - connection is considered impossible (e.g. for unsupported socket - family errors), there is no sense in retrying. "Connection - refused" is normally not retried, except when opt.retry_connrefused - is specified. */ - -#define CONNECT_ERROR(err) ((unsupported_socket_family_error (err) \ - || ((err) == ECONNREFUSED \ - && !opt.retry_connrefused)) \ - ? CONIMPOSSIBLE : CONERROR) - #endif /* WGET_H */ -- 2.39.2