]> sjero.net Git - wget/commitdiff
[svn] Correctly check for unsupported socket families.
authorhniksic <devnull@localhost>
Thu, 13 Nov 2003 20:26:18 +0000 (12:26 -0800)
committerhniksic <devnull@localhost>
Thu, 13 Nov 2003 20:26:18 +0000 (12:26 -0800)
src/ChangeLog
src/connect.c
src/connect.h
src/wget.h

index 068f92b37ffb5a5f3981207844c00b8226b3cbdf..0bd2ec89fdc70a7d466da470ed918341a3fdbed9 100644 (file)
@@ -1,3 +1,9 @@
+2003-11-13  Hrvoje Niksic  <hniksic@xemacs.org>
+
+       * wget.h (CONNECT_ERROR): Use it.
+
+       * connect.c (unsupported_socket_family_error): New function.
+
 2003-11-13  Hrvoje Niksic  <hniksic@xemacs.org>
 
        * connect.c (bind_local): Renamed bindport to bind_local; return
index 46b0aa02d7f2630250c5ffd0db27b02ccfc7407a..f73c9501cc9d5514584649e5f6f1e5e17a514a8d 100644 (file)
@@ -484,41 +484,6 @@ bind_local (const ip_address *bind_address, int *port)
   return sock;
 }
 
-#ifdef HAVE_SELECT
-/* Wait for file descriptor FD to be readable or writable or both,
-   timing out after MAXTIME seconds.  Returns 1 if FD is available, 0
-   for timeout and -1 for error.  The argument WAIT_FOR can be a
-   combination of WAIT_READ and WAIT_WRITE.
-
-   This is a mere convenience wrapper around the select call, and
-   should be taken as such.  */
-
-int
-select_fd (int fd, double maxtime, int wait_for)
-{
-  fd_set fdset;
-  fd_set *rd = NULL, *wr = NULL;
-  struct timeval tmout;
-  int result;
-
-  FD_ZERO (&fdset);
-  FD_SET (fd, &fdset);
-  if (wait_for & WAIT_FOR_READ)
-    rd = &fdset;
-  if (wait_for & WAIT_FOR_WRITE)
-    wr = &fdset;
-
-  tmout.tv_sec = (long) maxtime;
-  tmout.tv_usec = 1000000L * (maxtime - (long) maxtime);
-
-  do
-    result = select (fd + 1, rd, wr, NULL, &tmout);
-  while (result < 0 && errno == EINTR);
-
-  return result;
-}
-#endif /* HAVE_SELECT */
-
 /* Like a call to accept(), but with the added check for timeout.
 
    In other words, accept a client connection on LOCAL_SOCK, and
@@ -608,6 +573,73 @@ 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.  */
+
+int
+unsupported_socket_family_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.  */
+#ifdef EAFNOSUPPORT
+  if (err == EAFNOSUPPORT) return 1;
+#endif
+#ifdef EPFNOSUPPORT
+  if (err == EPFNOSUPPORT) return 1;
+#endif
+#ifdef ESOCKTNOSUPPORT         /* no, "sockt" is not a typo! */
+  if (err == ESOCKTNOSUPPORT) return 1;
+#endif
+#ifdef EPROTONOSUPPORT
+  if (err == EPROTONOSUPPORT) return 1;
+#endif
+#ifdef ENOPROTOOPT
+  if (err == ENOPROTOOPT) return 1;
+#endif
+  /* Apparently, older versions of Linux used EINVAL instead of
+     EAFNOSUPPORT. */
+  if (err == EINVAL) return 1;
+
+  return 0;
+}
+
+#ifdef HAVE_SELECT
+
+/* Wait for file descriptor FD to be readable or writable or both,
+   timing out after MAXTIME seconds.  Returns 1 if FD is available, 0
+   for timeout and -1 for error.  The argument WAIT_FOR can be a
+   combination of WAIT_READ and WAIT_WRITE.
+
+   This is a mere convenience wrapper around the select call, and
+   should be taken as such.  */
+
+int
+select_fd (int fd, double maxtime, int wait_for)
+{
+  fd_set fdset;
+  fd_set *rd = NULL, *wr = NULL;
+  struct timeval tmout;
+  int result;
+
+  FD_ZERO (&fdset);
+  FD_SET (fd, &fdset);
+  if (wait_for & WAIT_FOR_READ)
+    rd = &fdset;
+  if (wait_for & WAIT_FOR_WRITE)
+    wr = &fdset;
+
+  tmout.tv_sec = (long) maxtime;
+  tmout.tv_usec = 1000000L * (maxtime - (long) maxtime);
+
+  do
+    result = select (fd + 1, rd, wr, NULL, &tmout);
+  while (result < 0 && errno == EINTR);
+
+  return result;
+}
+
+#endif /* HAVE_SELECT */
 \f
 /* Basic socket operations, mostly EINTR wrappers.  */
 
index 9d67d070df139e7f45b7f13e6dd92380f4e285ff..8872ee7816e057ff2c7a2bc4b7804e2e12e175a1 100644 (file)
@@ -56,6 +56,8 @@ enum {
 };
 int socket_ip_address PARAMS ((int, ip_address *, int));
 
+int unsupported_socket_family_error PARAMS ((int));
+
 /* Flags for select_fd's WAIT_FOR argument. */
 enum {
   WAIT_FOR_READ = 1,
index 6cdfbeb0125f0dd79d468f70454c99df789c6d9a..edc159900a63fd04dabfa07d3acc087acc2fe549 100644 (file)
@@ -223,15 +223,15 @@ typedef enum
   SSLERRCERTFILE,SSLERRCERTKEY,SSLERRCTXCREATE
 } uerr_t;
 
-/* In case old systems don't have EAFNOSUPPORT, which we use below. */
-#ifndef EAFNOSUPPORT
-# define EAFNOSUPPORT EINVAL
-#endif
-
-#define CONNECT_ERROR(err) ((   (err) == EAFNOSUPPORT          \
-                            || (err) == EINVAL                 \
-                            || ((err) == ECONNREFUSED          \
-                                && !opt.retry_connrefused))    \
+/* 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 */