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: CURLOPT_SHARE 5*6236dae4SAndroid Build Coastguard WorkerSection: 3 6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl 7*6236dae4SAndroid Build Coastguard WorkerSee-also: 8*6236dae4SAndroid Build Coastguard Worker - CURLOPT_COOKIE (3) 9*6236dae4SAndroid Build Coastguard Worker - CURLSHOPT_SHARE (3) 10*6236dae4SAndroid Build Coastguard WorkerProtocol: 11*6236dae4SAndroid Build Coastguard Worker - All 12*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.10 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 WorkerCURLOPT_SHARE - share handle to use 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_setopt(CURL *handle, CURLOPT_SHARE, CURLSH *share); 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 WorkerPass a *share* handle as a parameter. The share handle must have been 30*6236dae4SAndroid Build Coastguard Workercreated by a previous call to curl_share_init(3). Setting this option, 31*6236dae4SAndroid Build Coastguard Workermakes this curl handle use the data from the shared handle instead of keeping 32*6236dae4SAndroid Build Coastguard Workerthe data to itself. This enables several curl handles to share data. If the 33*6236dae4SAndroid Build Coastguard Workercurl handles are used simultaneously in multiple threads, you **MUST** use 34*6236dae4SAndroid Build Coastguard Workerthe locking methods in the share handle. See curl_share_setopt(3) for 35*6236dae4SAndroid Build Coastguard Workerdetails. 36*6236dae4SAndroid Build Coastguard Worker 37*6236dae4SAndroid Build Coastguard WorkerIf you add a share that is set to share cookies, your easy handle uses that 38*6236dae4SAndroid Build Coastguard Workercookie cache and get the cookie engine enabled. If you stop sharing an object 39*6236dae4SAndroid Build Coastguard Workerthat was using cookies (or change to another object that does not share 40*6236dae4SAndroid Build Coastguard Workercookies), the easy handle gets its cookie engine disabled. 41*6236dae4SAndroid Build Coastguard Worker 42*6236dae4SAndroid Build Coastguard WorkerData that the share object is not set to share is dealt with the usual way, as 43*6236dae4SAndroid Build Coastguard Workerif no share was used. 44*6236dae4SAndroid Build Coastguard Worker 45*6236dae4SAndroid Build Coastguard WorkerSet this option to NULL again to stop using that share object. 46*6236dae4SAndroid Build Coastguard Worker 47*6236dae4SAndroid Build Coastguard Worker# DEFAULT 48*6236dae4SAndroid Build Coastguard Worker 49*6236dae4SAndroid Build Coastguard WorkerNULL 50*6236dae4SAndroid Build Coastguard Worker 51*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS% 52*6236dae4SAndroid Build Coastguard Worker 53*6236dae4SAndroid Build Coastguard Worker# EXAMPLE 54*6236dae4SAndroid Build Coastguard Worker 55*6236dae4SAndroid Build Coastguard Worker~~~c 56*6236dae4SAndroid Build Coastguard Workerint main(void) 57*6236dae4SAndroid Build Coastguard Worker{ 58*6236dae4SAndroid Build Coastguard Worker CURL *curl = curl_easy_init(); 59*6236dae4SAndroid Build Coastguard Worker CURL *curl2 = curl_easy_init(); /* a second handle */ 60*6236dae4SAndroid Build Coastguard Worker if(curl) { 61*6236dae4SAndroid Build Coastguard Worker CURLcode res; 62*6236dae4SAndroid Build Coastguard Worker CURLSH *shobject = curl_share_init(); 63*6236dae4SAndroid Build Coastguard Worker curl_share_setopt(shobject, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE); 64*6236dae4SAndroid Build Coastguard Worker 65*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/"); 66*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_COOKIEFILE, ""); 67*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_SHARE, shobject); 68*6236dae4SAndroid Build Coastguard Worker res = curl_easy_perform(curl); 69*6236dae4SAndroid Build Coastguard Worker curl_easy_cleanup(curl); 70*6236dae4SAndroid Build Coastguard Worker 71*6236dae4SAndroid Build Coastguard Worker /* the second handle shares cookies from the first */ 72*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl2, CURLOPT_URL, "https://example.com/second"); 73*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl2, CURLOPT_COOKIEFILE, ""); 74*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl2, CURLOPT_SHARE, shobject); 75*6236dae4SAndroid Build Coastguard Worker res = curl_easy_perform(curl2); 76*6236dae4SAndroid Build Coastguard Worker curl_easy_cleanup(curl2); 77*6236dae4SAndroid Build Coastguard Worker 78*6236dae4SAndroid Build Coastguard Worker curl_share_cleanup(shobject); 79*6236dae4SAndroid Build Coastguard Worker } 80*6236dae4SAndroid Build Coastguard Worker} 81*6236dae4SAndroid Build Coastguard Worker~~~ 82*6236dae4SAndroid Build Coastguard Worker 83*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY% 84*6236dae4SAndroid Build Coastguard Worker 85*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE 86*6236dae4SAndroid Build Coastguard Worker 87*6236dae4SAndroid Build Coastguard WorkerReturns CURLE_OK 88