multi: add CURLMOPT_NETWORK_CHANGED to signal network changed

New multi option CURLMOPT_NETWORK_CHANGED with a long bitmask value:

- CURLM_NWCOPT_CLEAR_CONNS: do not reuse existing connections, close all
  idle connections.

- CURLM_NWCOPT_CLEAR_DNS: clear the multi's DNS cache.

All other bits reserved for future extensions.

Fixes #17225
Reported-by: ウさん
Closes #17613
This commit is contained in:
Stefan Eissing 2025-06-13 12:38:44 +02:00 committed by Daniel Stenberg
parent 7b8594176d
commit 55c045c863
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
19 changed files with 354 additions and 4 deletions

View file

@ -68,6 +68,10 @@ CURLMOPT_MAX_HOST_CONNECTIONS(3)
Max simultaneously open connections. See CURLMOPT_MAX_TOTAL_CONNECTIONS(3)
## CURLMOPT_NETWORK_CHANGED
Signal that the network has changed. See CURLMOPT_NETWORK_CHANGED(3)
## CURLMOPT_PIPELINING
Enable HTTP multiplexing. See CURLMOPT_PIPELINING(3)

View file

@ -0,0 +1,80 @@
---
c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
SPDX-License-Identifier: curl
Title: CURLMOPT_NETWORK_CHANGED
Section: 3
Source: libcurl
See-also:
- CURLOPT_FRESH_CONNECT (3)
- CURLOPT_FORBID_REUSE (3)
Protocol:
- All
Added-in: 8.16.0
---
# NAME
CURLMOPT_NETWORK_CHANGED - signal network changed
# SYNOPSIS
~~~c
#include <curl/curl.h>
CURLMcode curl_multi_setopt(CURLM *handle, CURLMOPT_NETWORK_CHANGED,
long value);
~~~
# DESCRIPTION
Pass a long with a bitmask to tell libcurl how the multi
handle should react. The following values in the mask are
defined. All bits not mentioned are reserved for future
extensions.
This option can be set at any time and repeatedly. Each call only
affects the *currently* cached connections and DNS information.
Any connection created or DNS information added afterwards is
cached the usual way again. Phrasing it another way: the option is
not persisted but setting it serves as a "trigger"
to clear the caches.
The call affects only the connection and DNS cache of the multi handle
itself and not the ones owned by SHARE handles.
## CURLM_NWCOPT_CLEAR_CONNS
No longer reuse any existing connection in the multi handle's
connection cache. This closes all connections that are not in use.
Ongoing transfers continue on the connections they operate on.
## CURLM_NWCOPT_CLEAR_DNS
Clear the multi handle's DNS cache.
# DEFAULT
0, which has no effect.
# %PROTOCOLS%
# EXAMPLE
~~~c
int main(void)
{
CURLM *m = curl_multi_init();
/* do transfers on the multi handle */
/* do not reuse existing connections */
curl_multi_setopt(m, CURLMOPT_NETWORK_CHANGED, CURLM_NWCOPT_CLEAR_CONNS);
}
~~~
# %AVAILABILITY%
# RETURN VALUE
curl_multi_setopt(3) returns a CURLMcode indicating success or error.
CURLM_OK (0) means everything was OK, non-zero means an error occurred, see
libcurl-errors(3).

View file

@ -8,6 +8,7 @@ See-also:
- CURLOPT_FRESH_CONNECT (3)
- CURLOPT_MAXCONNECTS (3)
- CURLOPT_MAXLIFETIME_CONN (3)
- CURLMOPT_NETWORK_CHANGED (3)
Protocol:
- All
Added-in: 7.7

View file

@ -10,6 +10,7 @@ See-also:
- CURLOPT_FORBID_REUSE (3)
- CURLOPT_MAXAGE_CONN (3)
- CURLOPT_MAXLIFETIME_CONN (3)
- CURLMOPT_NETWORK_CHANGED (3)
Added-in: 7.7
---

View file

@ -108,6 +108,7 @@ man_MANS = \
CURLMOPT_MAX_PIPELINE_LENGTH.3 \
CURLMOPT_MAX_TOTAL_CONNECTIONS.3 \
CURLMOPT_MAXCONNECTS.3 \
CURLMOPT_NETWORK_CHANGED.3 \
CURLMOPT_PIPELINING.3 \
CURLMOPT_PIPELINING_SERVER_BL.3 \
CURLMOPT_PIPELINING_SITE_BL.3 \

View file

@ -545,6 +545,8 @@ CURLM_BAD_SOCKET 7.15.4
CURLM_CALL_MULTI_PERFORM 7.9.6
CURLM_CALL_MULTI_SOCKET 7.15.5
CURLM_INTERNAL_ERROR 7.9.6
CURLM_NWCOPT_CLEAR_CONNS 8.16.0
CURLM_NWCOPT_CLEAR_DNS 8.16.0
CURLM_OK 7.9.6
CURLM_OUT_OF_MEMORY 7.9.6
CURLM_RECURSIVE_API_CALL 7.59.0
@ -559,6 +561,7 @@ CURLMOPT_MAX_HOST_CONNECTIONS 7.30.0
CURLMOPT_MAX_PIPELINE_LENGTH 7.30.0
CURLMOPT_MAX_TOTAL_CONNECTIONS 7.30.0
CURLMOPT_MAXCONNECTS 7.16.3
CURLMOPT_NETWORK_CHANGED 8.16.0
CURLMOPT_PIPELINING 7.16.0
CURLMOPT_PIPELINING_SERVER_BL 7.30.0
CURLMOPT_PIPELINING_SITE_BL 7.30.0