Move the forwarded-connect-retries handling into a shiny new connect_to()
authorFabian Keil <fk@fabiankeil.de>
Sun, 27 Mar 2011 13:52:23 +0000 (13:52 +0000)
committerFabian Keil <fk@fabiankeil.de>
Sun, 27 Mar 2011 13:52:23 +0000 (13:52 +0000)
In the process, give the two former connect_to() versions different names.

jbsockets.c
jcc.c

index e36c0ac..f9d5ef3 100644 (file)
@@ -1,4 +1,4 @@
-const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.79 2010/07/26 11:30:09 fabiankeil Exp $";
+const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.80 2011/03/27 13:51:04 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/jbsockets.c,v $
@@ -118,6 +118,11 @@ const char jbsockets_h_rcs[] = JBSOCKETS_H_VERSION;
 
 #define MAX_LISTEN_BACKLOG 128
 
+#ifdef HAVE_RFC2553
+static jb_socket rfc2553_connect_to(const char *host, int portnum, struct client_state *csp);
+#else
+static jb_socket no_rfc2553_connect_to(const char *host, int portnum, struct client_state *csp);
+#endif
 
 /*********************************************************************
  *
@@ -135,9 +140,35 @@ const char jbsockets_h_rcs[] = JBSOCKETS_H_VERSION;
  *                file descriptor.
  *
  *********************************************************************/
+jb_socket connect_to(const char *host, int portnum, struct client_state *csp)
+{
+   jb_socket fd;
+   int forwarded_connect_retries = 0;
+
+   do
+   {
+#ifdef HAVE_RFC2553
+      fd = rfc2553_connect_to(host, portnum, csp);
+#else
+      fd = no_rfc2553_connect_to(host, portnum, csp);
+#endif
+      if ((fd != JB_INVALID_SOCKET) || (errno != EINVAL))
+      {
+         break;
+      }
+      forwarded_connect_retries++;
+      log_error(LOG_LEVEL_ERROR,
+         "Attempt %d to connect to %s failed. Trying again.",
+         forwarded_connect_retries, host);
+
+   } while (forwarded_connect_retries < csp->config->forwarded_connect_retries);
+
+   return fd;
+}
+
 #ifdef HAVE_RFC2553
 /* Getaddrinfo implementation */
-jb_socket connect_to(const char *host, int portnum, struct client_state *csp)
+static jb_socket rfc2553_connect_to(const char *host, int portnum, struct client_state *csp)
 {
    struct addrinfo hints, *result, *rp;
    char service[6];
@@ -336,7 +367,7 @@ jb_socket connect_to(const char *host, int portnum, struct client_state *csp)
 #else /* ndef HAVE_RFC2553 */
 /* Pre-getaddrinfo implementation */
 
-jb_socket connect_to(const char *host, int portnum, struct client_state *csp)
+static jb_socket no_rfc2553_connect_to(const char *host, int portnum, struct client_state *csp)
 {
    struct sockaddr_in inaddr;
    jb_socket fd;
diff --git a/jcc.c b/jcc.c
index 3b8b3aa..8f4e651 100644 (file)
--- a/jcc.c
+++ b/jcc.c
@@ -1,4 +1,4 @@
-const char jcc_rcs[] = "$Id: jcc.c,v 1.341 2011/03/03 14:41:29 fabiankeil Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 1.342 2011/03/03 14:44:00 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/jcc.c,v $
@@ -1522,8 +1522,6 @@ static void chat(struct client_state *csp)
    int server_body;
    int ms_iis5_hack = 0;
    unsigned long long byte_count = 0;
-   int forwarded_connect_retries = 0;
-   int max_forwarded_connect_retries = csp->config->forwarded_connect_retries;
    const struct forward_spec *fwd;
    struct http_request *http;
    long len = 0; /* for buffer sizes (and negative error codes) */
@@ -1659,14 +1657,7 @@ static void chat(struct client_state *csp)
       }
 #endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
 
-      while ((csp->server_connection.sfd = forwarded_connect(fwd, http, csp))
-         && (errno == EINVAL)
-         && (forwarded_connect_retries++ < max_forwarded_connect_retries))
-      {
-         log_error(LOG_LEVEL_ERROR,
-            "failed request #%u to connect to %s. Trying again.",
-            forwarded_connect_retries, http->hostport);
-      }
+      csp->server_connection.sfd = forwarded_connect(fwd, http, csp);
 
       if (csp->server_connection.sfd == JB_INVALID_SOCKET)
       {