notroj commented on code in PR #44:
URL: https://github.com/apache/apr/pull/44#discussion_r1243279746


##########
memcache/apr_memcache.c:
##########
@@ -346,18 +346,37 @@ APR_DECLARE(apr_status_t) 
apr_memcache_disable_server(apr_memcache_t *mc, apr_me
     return make_server_dead(mc, ms);
 }
 
-static apr_status_t conn_connect(apr_memcache_conn_t *conn, apr_sockaddr_t *sa)
+static apr_status_t conn_connect(apr_memcache_conn_t *conn)
 {
     apr_status_t rv = APR_SUCCESS;
+    apr_sockaddr_t *sa;
+#if APR_HAVE_SOCKADDR_UN
+    apr_int32_t family = conn->ms->host[0] != '/' ? APR_UNSPEC : APR_UNIX;
+#else
+    apr_int32_t family = APR_UNSPEC;
+#endif
 
-    rv = apr_socket_timeout_set(conn->sock, 1 * APR_USEC_PER_SEC);
+    rv = apr_sockaddr_info_get(&sa, conn->ms->host, family, conn->ms->port, 0, 
conn->p);
     if (rv != APR_SUCCESS) {
         return rv;
     }
 
-    rv = apr_socket_connect(conn->sock, sa);
-    if (rv != APR_SUCCESS) {
-        return rv;
+    /* Cycle through address until a connect() succeeds. */
+    for (; sa; sa = sa->next) {
+        rv = apr_socket_create(&conn->sock, sa->family, SOCK_STREAM, 0, 
conn->p);
+        if (rv == APR_SUCCESS) {
+            rv = apr_socket_timeout_set(conn->sock, 1 * APR_USEC_PER_SEC);
+            if (rv != APR_SUCCESS) {
+                return rv;
+            }
+
+            rv = apr_socket_connect(conn->sock, sa);
+            if (rv == APR_SUCCESS) {
+                break;
+            }
+
+            apr_socket_close(conn->sock);
+        }
     }

Review Comment:
   This needs to catch the error case where no loop iteration succeeds, if sa 
is NULL after the for() loop then it should return with an error.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@apr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to