summaryrefslogtreecommitdiffstats
path: root/Utilities/cmcurl/lib/conncache.c
diff options
context:
space:
mode:
Diffstat (limited to 'Utilities/cmcurl/lib/conncache.c')
-rw-r--r--Utilities/cmcurl/lib/conncache.c63
1 files changed, 26 insertions, 37 deletions
diff --git a/Utilities/cmcurl/lib/conncache.c b/Utilities/cmcurl/lib/conncache.c
index fec1937..aa29620 100644
--- a/Utilities/cmcurl/lib/conncache.c
+++ b/Utilities/cmcurl/lib/conncache.c
@@ -6,7 +6,7 @@
* \___|\___/|_| \_\_____|
*
* Copyright (C) 2012 - 2016, Linus Nielsen Feltzing, <linus@haxx.se>
- * Copyright (C) 2012 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2012 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -132,13 +132,11 @@ void Curl_conncache_destroy(struct conncache *connc)
}
/* creates a key to find a bundle for this connection */
-static void hashkey(struct connectdata *conn, char *buf,
- size_t len, /* something like 128 is fine */
- const char **hostp)
+static void hashkey(struct connectdata *conn, char *buf, size_t len)
{
const char *hostname;
long port = conn->remote_port;
-
+ DEBUGASSERT(len >= HASHKEY_SIZE);
#ifndef CURL_DISABLE_PROXY
if(conn->bits.httpproxy && !conn->bits.tunnel_proxy) {
hostname = conn->http_proxy.host.name;
@@ -151,12 +149,12 @@ static void hashkey(struct connectdata *conn, char *buf,
else
hostname = conn->host.name;
- if(hostp)
- /* report back which name we used */
- *hostp = hostname;
-
- /* put the number first so that the hostname gets cut off if too long */
- msnprintf(buf, len, "%ld%s", port, hostname);
+ /* put the numbers first so that the hostname gets cut off if too long */
+#ifdef ENABLE_IPV6
+ msnprintf(buf, len, "%u/%ld/%s", conn->scope_id, port, hostname);
+#else
+ msnprintf(buf, len, "%ld/%s", port, hostname);
+#endif
Curl_strntolower(buf, buf, len);
}
@@ -179,27 +177,24 @@ size_t Curl_conncache_size(struct Curl_easy *data)
struct connectbundle *
Curl_conncache_find_bundle(struct Curl_easy *data,
struct connectdata *conn,
- struct conncache *connc,
- const char **hostp)
+ struct conncache *connc)
{
struct connectbundle *bundle = NULL;
CONNCACHE_LOCK(data);
if(connc) {
char key[HASHKEY_SIZE];
- hashkey(conn, key, sizeof(key), hostp);
+ hashkey(conn, key, sizeof(key));
bundle = Curl_hash_pick(&connc->hash, key, strlen(key));
}
return bundle;
}
-static bool conncache_add_bundle(struct conncache *connc,
- char *key,
- struct connectbundle *bundle)
+static void *conncache_add_bundle(struct conncache *connc,
+ char *key,
+ struct connectbundle *bundle)
{
- void *p = Curl_hash_add(&connc->hash, key, strlen(key), bundle);
-
- return p?TRUE:FALSE;
+ return Curl_hash_add(&connc->hash, key, strlen(key), bundle);
}
static void conncache_remove_bundle(struct conncache *connc,
@@ -235,10 +230,8 @@ CURLcode Curl_conncache_add_conn(struct Curl_easy *data)
DEBUGASSERT(conn);
/* *find_bundle() locks the connection cache */
- bundle = Curl_conncache_find_bundle(data, conn, data->state.conn_cache,
- NULL);
+ bundle = Curl_conncache_find_bundle(data, conn, data->state.conn_cache);
if(!bundle) {
- int rc;
char key[HASHKEY_SIZE];
result = bundle_create(&bundle);
@@ -246,10 +239,9 @@ CURLcode Curl_conncache_add_conn(struct Curl_easy *data)
goto unlock;
}
- hashkey(conn, key, sizeof(key), NULL);
- rc = conncache_add_bundle(data->state.conn_cache, key, bundle);
+ hashkey(conn, key, sizeof(key));
- if(!rc) {
+ if(!conncache_add_bundle(data->state.conn_cache, key, bundle)) {
bundle_destroy(bundle);
result = CURLE_OUT_OF_MEMORY;
goto unlock;
@@ -410,7 +402,7 @@ bool Curl_conncache_return_conn(struct Curl_easy *data,
conn_candidate = Curl_conncache_extract_oldest(data);
if(conn_candidate) {
/* the winner gets the honour of being disconnected */
- (void)Curl_disconnect(data, conn_candidate, /* dead_connection */ FALSE);
+ Curl_disconnect(data, conn_candidate, /* dead_connection */ FALSE);
}
}
@@ -535,6 +527,7 @@ void Curl_conncache_close_all_connections(struct conncache *connc)
{
struct connectdata *conn;
char buffer[READBUFFER_MIN + 1];
+ SIGPIPE_VARIABLE(pipe_st);
if(!connc->closure_handle)
return;
connc->closure_handle->state.buffer = buffer;
@@ -542,27 +535,23 @@ void Curl_conncache_close_all_connections(struct conncache *connc)
conn = conncache_find_first_connection(connc);
while(conn) {
- SIGPIPE_VARIABLE(pipe_st);
sigpipe_ignore(connc->closure_handle, &pipe_st);
/* This will remove the connection from the cache */
connclose(conn, "kill all");
Curl_conncache_remove_conn(connc->closure_handle, conn, TRUE);
- (void)Curl_disconnect(connc->closure_handle, conn, FALSE);
+ Curl_disconnect(connc->closure_handle, conn, FALSE);
sigpipe_restore(&pipe_st);
conn = conncache_find_first_connection(connc);
}
connc->closure_handle->state.buffer = NULL;
- if(connc->closure_handle) {
- SIGPIPE_VARIABLE(pipe_st);
- sigpipe_ignore(connc->closure_handle, &pipe_st);
+ sigpipe_ignore(connc->closure_handle, &pipe_st);
- Curl_hostcache_clean(connc->closure_handle,
- connc->closure_handle->dns.hostcache);
- Curl_close(&connc->closure_handle);
- sigpipe_restore(&pipe_st);
- }
+ Curl_hostcache_clean(connc->closure_handle,
+ connc->closure_handle->dns.hostcache);
+ Curl_close(&connc->closure_handle);
+ sigpipe_restore(&pipe_st);
}
#if 0