]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
conncache: eliminate cpool's diconnect callback
authorStefan Eissing <stefan@eissing.org>
Mon, 24 Mar 2025 09:51:00 +0000 (10:51 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 24 Mar 2025 21:41:53 +0000 (22:41 +0100)
The callback, provided from url.c did the work that the cshutdn
functionality also implemented. Remove it.

Change some DEBUGF(infof()) to CURL_TRC_M().

Closes #16810

lib/conncache.c
lib/conncache.h
lib/multi.c
lib/share.c
lib/url.c
lib/url.h
tests/http/test_02_download.py

index 5f8229303f9444e153d2cd5a416dab5778d50b71..cf2807882dc1c88d3ec40ee6ffcea130e645a88a 100644 (file)
@@ -133,7 +133,6 @@ static void cpool_bundle_free_entry(void *freethis)
 }
 
 int Curl_cpool_init(struct cpool *cpool,
-                    Curl_cpool_disconnect_cb *disconnect_cb,
                     struct Curl_easy *idata,
                     struct Curl_share *share,
                     size_t size)
@@ -142,12 +141,8 @@ int Curl_cpool_init(struct cpool *cpool,
                  Curl_str_key_compare, cpool_bundle_free_entry);
 
   DEBUGASSERT(idata);
-  DEBUGASSERT(disconnect_cb);
-  if(!disconnect_cb)
-    return 1;
 
   cpool->idata = idata;
-  cpool->disconnect_cb = disconnect_cb;
   cpool->share = share;
   cpool->initialised = TRUE;
   return 0; /* good */
@@ -457,9 +452,9 @@ CURLcode Curl_cpool_add(struct Curl_easy *data,
   cpool_bundle_add(bundle, conn);
   conn->connection_id = cpool->next_connection_id++;
   cpool->num_conn++;
-  DEBUGF(infof(data, "Added connection %" FMT_OFF_T ". "
-               "The cache now contains %zu members",
-               conn->connection_id, cpool->num_conn));
+  CURL_TRC_M(data, "[CPOOL] added connection %" FMT_OFF_T ". "
+             "The cache now contains %zu members",
+             conn->connection_id, cpool->num_conn);
 out:
   CPOOL_UNLOCK(cpool, data);
 
@@ -669,8 +664,10 @@ void Curl_conn_terminate(struct Curl_easy *data,
     DEBUGASSERT(!conn->bits.in_cpool);
   }
 
-  /* Run the callback to let it clean up anything it wants to. */
-  aborted = cpool->disconnect_cb(data, conn, aborted);
+  /* treat the connection as aborted in CONNECT_ONLY situations,
+   * so no graceful shutdown is attempted. */
+  if(conn->connect_only)
+    aborted = TRUE;
 
   if(data->multi) {
     /* Add it to the multi's cpool for shutdown handling */
index 1e65660423da74d50001ff0257c7f22d1e1c3854..d8b90c0f4a899aa2a90d07029df1569f08a2370c 100644 (file)
@@ -48,18 +48,6 @@ void Curl_conn_terminate(struct Curl_easy *data,
                          struct connectdata *conn,
                          bool aborted);
 
-/**
- * Callback invoked when disconnecting connections.
- * @param data    transfer last handling the connection, not attached
- * @param conn    the connection to discard
- * @param aborted if the connection is being aborted
- * @return if the connection is being aborted, e.g. should NOT perform
- *         a shutdown and just close.
- **/
-typedef bool Curl_cpool_disconnect_cb(struct Curl_easy *data,
-                                      struct connectdata *conn,
-                                      bool aborted);
-
 struct cpool {
    /* the pooled connections, bundled per destination */
   struct Curl_hash dest2bundle;
@@ -68,8 +56,7 @@ struct cpool {
   curl_off_t next_easy_id;
   struct curltime last_cleanup;
   struct Curl_easy *idata; /* internal handle for maintenance */
-  struct Curl_share *share; /* != NULL iff pool belongs to share */
-  Curl_cpool_disconnect_cb *disconnect_cb;
+  struct Curl_share *share; /* != NULL if pool belongs to share */
   BIT(locked);
   BIT(initialised);
 };
@@ -78,7 +65,6 @@ struct cpool {
  * returns 1 on error, 0 is fine.
  */
 int Curl_cpool_init(struct cpool *cpool,
-                    Curl_cpool_disconnect_cb *disconnect_cb,
                     struct Curl_easy *idata,
                     struct Curl_share *share,
                     size_t size);
index 7b54850a63b0c9677bb7feada6c5c34f3f448fb3..09afe804c0bfaab94b72467236f2f9b0d54d37ab 100644 (file)
@@ -242,8 +242,7 @@ struct Curl_multi *Curl_multi_handle(size_t ev_hashsize,  /* event hash */
   if(Curl_cshutdn_init(&multi->cshutdn, multi))
     goto error;
 
-  if(Curl_cpool_init(&multi->cpool, Curl_on_disconnect,
-                     multi->admin, NULL, chashsize))
+  if(Curl_cpool_init(&multi->cpool, multi->admin, NULL, chashsize))
     goto error;
 
   if(Curl_ssl_scache_create(sesssize, 2, &multi->ssl_scache))
index 938c9a9d799793cde06d29ef162b864f4c4671f2..110adef68e1935da352d27f30e5a0a53c9b5d7c8 100644 (file)
@@ -136,8 +136,7 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...)
     case CURL_LOCK_DATA_CONNECT:
       /* It is safe to set this option several times on a share. */
       if(!share->cpool.initialised) {
-        if(Curl_cpool_init(&share->cpool, Curl_on_disconnect,
-                           share->admin, share, 103))
+        if(Curl_cpool_init(&share->cpool, share->admin, share, 103))
           res = CURLSHE_NOMEM;
       }
       break;
index cc0f6d372b3aa1783ae915b8686ebcdb48d13998..2125a97afd1d850e82b73af724daf20741089050 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -599,52 +599,6 @@ void Curl_conn_free(struct Curl_easy *data, struct connectdata *conn)
   free(conn); /* free all the connection oriented data */
 }
 
-/*
- * Disconnects the given connection. Note the connection may not be the
- * primary connection, like when freeing room in the connection pool or
- * killing of a dead old connection.
- *
- * A connection needs an easy handle when closing down. We support this passed
- * in separately since the connection to get closed here is often already
- * disassociated from an easy handle.
- *
- * This function MUST NOT reset state in the Curl_easy struct if that
- * is not strictly bound to the life-time of *this* particular connection.
- */
-bool Curl_on_disconnect(struct Curl_easy *data,
-                        struct connectdata *conn, bool aborted)
-{
-  /* there must be a connection to close */
-  DEBUGASSERT(conn);
-
-  /* it must be removed from the connection pool */
-  DEBUGASSERT(!conn->bits.in_cpool);
-
-  /* there must be an associated transfer */
-  DEBUGASSERT(data);
-
-  /* the transfer must be detached from the connection */
-  DEBUGASSERT(!data->conn);
-
-  DEBUGF(infof(data, "Curl_disconnect(conn #%" FMT_OFF_T ", aborted=%d)",
-         conn->connection_id, aborted));
-
-  if(conn->dns_entry)
-    Curl_resolv_unlink(data, &conn->dns_entry);
-
-  /* Cleanup NTLM connection-related data */
-  Curl_http_auth_cleanup_ntlm(conn);
-
-  /* Cleanup NEGOTIATE connection-related data */
-  Curl_http_auth_cleanup_negotiate(conn);
-
-  if(conn->connect_only)
-    /* treat the connection as aborted in CONNECT_ONLY situations */
-    aborted = TRUE;
-
-  return aborted;
-}
-
 /*
  * xfer_may_multiplex()
  *
index 47c1db44f3ec715db3849eb7a0ec369804081069..f60460671ef2f2dc1621c7beb2fc7e43b6c107eb 100644 (file)
--- a/lib/url.h
+++ b/lib/url.h
@@ -37,8 +37,6 @@ void Curl_freeset(struct Curl_easy *data);
 CURLcode Curl_uc_to_curlcode(CURLUcode uc);
 CURLcode Curl_close(struct Curl_easy **datap); /* opposite of curl_open() */
 CURLcode Curl_connect(struct Curl_easy *, bool *async, bool *protocol_connect);
-bool Curl_on_disconnect(struct Curl_easy *data,
-                        struct connectdata *, bool aborted);
 CURLcode Curl_setup_conn(struct Curl_easy *data,
                          bool *protocol_done);
 void Curl_conn_free(struct Curl_easy *data, struct connectdata *conn);
index fa2c002091ede898aed1e05689067c3ffecefac1..4b9ae3caefab557b36da65e53f36eee2203559ec 100644 (file)
@@ -633,7 +633,9 @@ class TestDownload:
         docname = 'data-10k'
         port = env.port_for(proto)
         url = f'https://{env.domain1}:{port}/{docname}'
-        client = LocalClient(name='hx-download', env=env)
+        run_env = os.environ.copy()
+        run_env['CURL_DEBUG'] = 'multi'
+        client = LocalClient(name='hx-download', env=env, run_env=run_env)
         if not client.exists():
             pytest.skip(f'example client not built: {client.name}')
         r = client.run(args=[
@@ -667,7 +669,9 @@ class TestDownload:
         docname = 'data-10k'
         port = env.port_for(proto)
         url = f'https://{env.domain1}:{port}/{docname}'
-        client = LocalClient(name='hx-download', env=env)
+        run_env = os.environ.copy()
+        run_env['CURL_DEBUG'] = 'multi'
+        client = LocalClient(name='hx-download', env=env, run_env=run_env)
         if not client.exists():
             pytest.skip(f'example client not built: {client.name}')
         r = client.run(args=[