0943f8
diff --git a/support/ab.c b/support/ab.c
0943f8
index f54c402..93c9066 100644
0943f8
--- a/support/ab.c
0943f8
+++ b/support/ab.c
0943f8
@@ -344,6 +344,7 @@ apr_time_t start, lasttime, stoptime;
0943f8
 char _request[2048];
0943f8
 char *request = _request;
0943f8
 apr_size_t reqlen;
0943f8
+int requests_initialized = 0;
0943f8
 
0943f8
 /* one global throw-away buffer to read stuff into */
0943f8
 char buffer[8192];
0943f8
@@ -1253,12 +1254,18 @@ static void start_connect(struct connection * c)
0943f8
         else {
0943f8
             set_conn_state(c, STATE_UNCONNECTED);
0943f8
             apr_socket_close(c->aprsock);
0943f8
-            err_conn++;
0943f8
-            if (bad++ > 10) {
0943f8
+            if (good == 0 && destsa->next) {
0943f8
+                destsa = destsa->next;
0943f8
+                err_conn = 0;
0943f8
+            }
0943f8
+            else if (bad++ > 10) {
0943f8
                 fprintf(stderr,
0943f8
                    "\nTest aborted after 10 failures\n\n");
0943f8
                 apr_err("apr_socket_connect()", rv);
0943f8
             }
0943f8
+            else {
0943f8
+                err_conn++;
0943f8
+            }
0943f8
 
0943f8
             start_connect(c);
0943f8
             return;
0943f8
@@ -1339,6 +1346,7 @@ static void read_connection(struct connection * c)
0943f8
     apr_status_t status;
0943f8
     char *part;
0943f8
     char respcode[4];       /* 3 digits and null */
0943f8
+    int i;
0943f8
 
0943f8
     r = sizeof(buffer);
0943f8
 #ifdef USE_SSL
0943f8
@@ -1362,6 +1370,13 @@ static void read_connection(struct connection * c)
0943f8
                 good++;
0943f8
                 close_connection(c);
0943f8
             }
0943f8
+            else if (scode == SSL_ERROR_SYSCALL 
0943f8
+                     && c->read == 0
0943f8
+                     && destsa->next
0943f8
+                     && c->state == STATE_CONNECTING
0943f8
+                     && good == 0) {
0943f8
+                return;
0943f8
+            }
0943f8
             else if (scode != SSL_ERROR_WANT_WRITE
0943f8
                      && scode != SSL_ERROR_WANT_READ) {
0943f8
                 /* some fatal error: */
0943f8
@@ -1387,8 +1402,8 @@ static void read_connection(struct connection * c)
0943f8
         }
0943f8
         /* catch legitimate fatal apr_socket_recv errors */
0943f8
         else if (status != APR_SUCCESS) {
0943f8
-            err_recv++;
0943f8
             if (recverrok) {
0943f8
+                err_recv++;
0943f8
                 bad++;
0943f8
                 close_connection(c);
0943f8
                 if (verbosity >= 1) {
0943f8
@@ -1396,7 +1411,12 @@ static void read_connection(struct connection * c)
0943f8
                     fprintf(stderr,"%s: %s (%d)\n", "apr_socket_recv", apr_strerror(status, buf, sizeof buf), status);
0943f8
                 }
0943f8
                 return;
0943f8
-            } else {
0943f8
+            } else if (destsa->next && c->state == STATE_CONNECTING
0943f8
+                       && c->read == 0 && good == 0) {
0943f8
+                return;
0943f8
+            }
0943f8
+            else {
0943f8
+                err_recv++;
0943f8
                 apr_err("apr_socket_recv", status);
0943f8
             }
0943f8
         }
0943f8
@@ -1523,6 +1543,16 @@ static void read_connection(struct connection * c)
0943f8
             }
0943f8
             c->bread += c->cbx - (s + l - c->cbuff) + r - tocopy;
0943f8
             totalbread += c->bread;
0943f8
+
0943f8
+            /* We have received the header, so we know this destination socket
0943f8
+             * address is working, so initialize all remaining requests. */
0943f8
+            if (!requests_initialized) {
0943f8
+                for (i = 1; i < concurrency; i++) {
0943f8
+                    con[i].socknum = i;
0943f8
+                    start_connect(&con[i]);
0943f8
+                }
0943f8
+                requests_initialized = 1;
0943f8
+            }
0943f8
         }
0943f8
     }
0943f8
     else {
0943f8
@@ -1734,11 +1764,10 @@ static void test(void)
0943f8
     apr_signal(SIGINT, output_results);
0943f8
 #endif
0943f8
 
0943f8
-    /* initialise lots of requests */
0943f8
-    for (i = 0; i < concurrency; i++) {
0943f8
-        con[i].socknum = i;
0943f8
-        start_connect(&con[i]);
0943f8
-    }
0943f8
+    /* initialise first connection to determine destination socket address
0943f8
+     * which should be used for next connections. */
0943f8
+    con[0].socknum = 0;
0943f8
+    start_connect(&con[0]);
0943f8
 
0943f8
     do {
0943f8
         apr_int32_t n;
0943f8
@@ -1786,14 +1815,20 @@ static void test(void)
0943f8
             if ((rtnev & APR_POLLIN) || (rtnev & APR_POLLPRI) || (rtnev & APR_POLLHUP))
0943f8
                 read_connection(c);
0943f8
             if ((rtnev & APR_POLLERR) || (rtnev & APR_POLLNVAL)) {
0943f8
-                bad++;
0943f8
-                err_except++;
0943f8
-                /* avoid apr_poll/EINPROGRESS loop on HP-UX, let recv discover ECONNREFUSED */
0943f8
-                if (c->state == STATE_CONNECTING) {
0943f8
-                    read_connection(c);
0943f8
+                if (destsa->next && c->state == STATE_CONNECTING && good == 0) {
0943f8
+                    destsa = destsa->next;
0943f8
+                    start_connect(c);
0943f8
                 }
0943f8
                 else {
0943f8
-                    start_connect(c);
0943f8
+                    bad++;
0943f8
+                    err_except++;
0943f8
+                    /* avoid apr_poll/EINPROGRESS loop on HP-UX, let recv discover ECONNREFUSED */
0943f8
+                    if (c->state == STATE_CONNECTING) {
0943f8
+                        read_connection(c);
0943f8
+                    }
0943f8
+                    else {
0943f8
+                        start_connect(c);
0943f8
+                    }
0943f8
                 }
0943f8
                 continue;
0943f8
             }