1*6236dae4SAndroid Build Coastguard Worker--- 2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al. 3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl 4*6236dae4SAndroid Build Coastguard WorkerTitle: curl_easy_upkeep 5*6236dae4SAndroid Build Coastguard WorkerSection: 3 6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl 7*6236dae4SAndroid Build Coastguard WorkerSee-also: 8*6236dae4SAndroid Build Coastguard Worker - CURLOPT_TCP_KEEPALIVE (3) 9*6236dae4SAndroid Build Coastguard Worker - CURLOPT_TCP_KEEPIDLE (3) 10*6236dae4SAndroid Build Coastguard WorkerProtocol: 11*6236dae4SAndroid Build Coastguard Worker - All 12*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.62.0 13*6236dae4SAndroid Build Coastguard Worker--- 14*6236dae4SAndroid Build Coastguard Worker 15*6236dae4SAndroid Build Coastguard Worker# NAME 16*6236dae4SAndroid Build Coastguard Worker 17*6236dae4SAndroid Build Coastguard Workercurl_easy_upkeep - keep existing connections alive 18*6236dae4SAndroid Build Coastguard Worker 19*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS 20*6236dae4SAndroid Build Coastguard Worker 21*6236dae4SAndroid Build Coastguard Worker~~~c 22*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h> 23*6236dae4SAndroid Build Coastguard Worker 24*6236dae4SAndroid Build Coastguard WorkerCURLcode curl_easy_upkeep(CURL *handle); 25*6236dae4SAndroid Build Coastguard Worker~~~ 26*6236dae4SAndroid Build Coastguard Worker 27*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION 28*6236dae4SAndroid Build Coastguard Worker 29*6236dae4SAndroid Build Coastguard WorkerSome protocols have "connection upkeep" mechanisms. These mechanisms usually 30*6236dae4SAndroid Build Coastguard Workersend some traffic on existing connections in order to keep them alive; this 31*6236dae4SAndroid Build Coastguard Workercan prevent connections from being closed due to overzealous firewalls, for 32*6236dae4SAndroid Build Coastguard Workerexample. 33*6236dae4SAndroid Build Coastguard Worker 34*6236dae4SAndroid Build Coastguard WorkerCurrently the only protocol with a connection upkeep mechanism is HTTP/2: when 35*6236dae4SAndroid Build Coastguard Workerthe connection upkeep interval is exceeded and curl_easy_upkeep(3) 36*6236dae4SAndroid Build Coastguard Workeris called, an HTTP/2 PING frame is sent on the connection. 37*6236dae4SAndroid Build Coastguard Worker 38*6236dae4SAndroid Build Coastguard WorkerThis function must be explicitly called in order to perform the upkeep work. 39*6236dae4SAndroid Build Coastguard WorkerThe connection upkeep interval is set with 40*6236dae4SAndroid Build Coastguard WorkerCURLOPT_UPKEEP_INTERVAL_MS(3). 41*6236dae4SAndroid Build Coastguard Worker 42*6236dae4SAndroid Build Coastguard WorkerIf you call this function on an easy handle that uses a shared connection cache 43*6236dae4SAndroid Build Coastguard Workerthen upkeep is performed on the connections in that cache, even if those 44*6236dae4SAndroid Build Coastguard Workerconnections were never used by the easy handle. (Added in 8.10.0) 45*6236dae4SAndroid Build Coastguard Worker 46*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS% 47*6236dae4SAndroid Build Coastguard Worker 48*6236dae4SAndroid Build Coastguard Worker# EXAMPLE 49*6236dae4SAndroid Build Coastguard Worker 50*6236dae4SAndroid Build Coastguard Worker~~~c 51*6236dae4SAndroid Build Coastguard Workerint main(void) 52*6236dae4SAndroid Build Coastguard Worker{ 53*6236dae4SAndroid Build Coastguard Worker CURL *curl = curl_easy_init(); 54*6236dae4SAndroid Build Coastguard Worker if(curl) { 55*6236dae4SAndroid Build Coastguard Worker /* Make a connection to an HTTP/2 server. */ 56*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 57*6236dae4SAndroid Build Coastguard Worker 58*6236dae4SAndroid Build Coastguard Worker /* Set the interval to 30000ms / 30s */ 59*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_UPKEEP_INTERVAL_MS, 30000L); 60*6236dae4SAndroid Build Coastguard Worker 61*6236dae4SAndroid Build Coastguard Worker curl_easy_perform(curl); 62*6236dae4SAndroid Build Coastguard Worker 63*6236dae4SAndroid Build Coastguard Worker /* Perform more work here. */ 64*6236dae4SAndroid Build Coastguard Worker 65*6236dae4SAndroid Build Coastguard Worker /* While the connection is being held open, curl_easy_upkeep() can be 66*6236dae4SAndroid Build Coastguard Worker called. If curl_easy_upkeep() is called and the time since the last 67*6236dae4SAndroid Build Coastguard Worker upkeep exceeds the interval, then an HTTP/2 PING is sent. */ 68*6236dae4SAndroid Build Coastguard Worker curl_easy_upkeep(curl); 69*6236dae4SAndroid Build Coastguard Worker 70*6236dae4SAndroid Build Coastguard Worker /* Perform more work here. */ 71*6236dae4SAndroid Build Coastguard Worker 72*6236dae4SAndroid Build Coastguard Worker /* always cleanup */ 73*6236dae4SAndroid Build Coastguard Worker curl_easy_cleanup(curl); 74*6236dae4SAndroid Build Coastguard Worker } 75*6236dae4SAndroid Build Coastguard Worker} 76*6236dae4SAndroid Build Coastguard Worker~~~ 77*6236dae4SAndroid Build Coastguard Worker 78*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY% 79*6236dae4SAndroid Build Coastguard Worker 80*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE 81*6236dae4SAndroid Build Coastguard Worker 82*6236dae4SAndroid Build Coastguard WorkerOn success, returns **CURLE_OK**. 83*6236dae4SAndroid Build Coastguard Worker 84*6236dae4SAndroid Build Coastguard WorkerOn failure, returns the appropriate error code. 85