Skip to content

Commit

Permalink
* memcache/apr_memcache.c (conn_connect, mc_conn_construct): Fix
Browse files Browse the repository at this point in the history
  regression in IPv4 handling in r1907242. Cycle through the address
  list handling v4/v6 addresses correctly.

Submitted by: Lubos Uhliarik <luhliari redhat.com>
Github: closes #44


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1910629 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
notroj committed Jun 27, 2023
1 parent 40e0bc2 commit 59341af
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions memcache/apr_memcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,14 +361,26 @@ static apr_status_t conn_connect(apr_memcache_conn_t *conn)
return rv;
}

rv = apr_socket_timeout_set(conn->sock, 1 * APR_USEC_PER_SEC);
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);
}
}

rv = apr_socket_connect(conn->sock, sa);
if (rv != APR_SUCCESS) {
return rv;
if (!sa) {
return APR_ECONNREFUSED;
}

rv = apr_socket_timeout_set(conn->sock, -1);
Expand All @@ -388,11 +400,6 @@ mc_conn_construct(void **conn_, void *params, apr_pool_t *pool)
apr_pool_t *np;
apr_pool_t *tp;
apr_memcache_server_t *ms = params;
#if APR_HAVE_SOCKADDR_UN
apr_int32_t family = ms->host[0] != '/' ? APR_UNSPEC : APR_UNIX;
#else
apr_int32_t family = APR_UNSPEC;
#endif

rv = apr_pool_create(&np, pool);
if (rv != APR_SUCCESS) {
Expand All @@ -410,13 +417,6 @@ mc_conn_construct(void **conn_, void *params, apr_pool_t *pool)
conn->p = np;
conn->tp = tp;

rv = apr_socket_create(&conn->sock, family, SOCK_STREAM, 0, np);

if (rv != APR_SUCCESS) {
apr_pool_destroy(np);
return rv;
}

conn->buffer = apr_palloc(conn->p, BUFFER_SIZE + 1);
conn->blen = 0;
conn->ms = ms;
Expand Down

0 comments on commit 59341af

Please sign in to comment.