examples: consistent variable naming across examples

- 'CURL *' handles are called 'curl'
- 'CURLM *' handles are called 'multi'
- write callbacks are called 'write_cb'
- read callbacs are called 'read_cb'
- CURLcode variables are called 'res'

It makes the examples look and feel more consistent. It allows for
easier copy and pasting between examples.

Closes #19299
This commit is contained in:
Daniel Stenberg 2025-10-31 14:42:30 +01:00
parent 0313223853
commit 928363f28c
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
59 changed files with 715 additions and 725 deletions

View file

@ -89,11 +89,11 @@ static void dump(const char *text, unsigned char *ptr, size_t size, char nohex)
}
}
static int my_trace(CURL *handle, curl_infotype type,
static int my_trace(CURL *curl, curl_infotype type,
char *data, size_t size, void *userp)
{
const char *text;
(void)handle;
(void)curl;
(void)userp;
switch(type) {
case CURLINFO_TEXT:
@ -127,32 +127,32 @@ static int my_trace(CURL *handle, curl_infotype type,
#define OUTPUTFILE "dl"
static int setup(CURL *hnd, const char *url)
static int setup(CURL *curl, const char *url)
{
out_download = fopen(OUTPUTFILE, "wb");
if(!out_download)
return 1; /* failed */
/* set the same URL */
curl_easy_setopt(hnd, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_URL, url);
/* HTTP/2 please */
curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
/* we use a self-signed test server, skip verification during debugging */
curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
/* write to this file */
curl_easy_setopt(hnd, CURLOPT_WRITEDATA, out_download);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, out_download);
/* please be verbose */
curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(hnd, CURLOPT_DEBUGFUNCTION, my_trace);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
#if CURLPIPE_MULTIPLEX > 0
/* wait for pipe connection to confirm */
curl_easy_setopt(hnd, CURLOPT_PIPEWAIT, 1L);
curl_easy_setopt(curl, CURLOPT_PIPEWAIT, 1L);
#endif
return 0; /* all is good */
}
@ -161,7 +161,7 @@ static FILE *out_push;
/* called when there is an incoming push */
static int server_push_callback(CURL *parent,
CURL *easy,
CURL *curl,
size_t num_headers,
struct curl_pushheaders *headers,
void *userp)
@ -185,7 +185,7 @@ static int server_push_callback(CURL *parent,
}
/* write to this file */
curl_easy_setopt(easy, CURLOPT_WRITEDATA, out_push);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, out_push);
fprintf(stderr, "**** push callback approves stream %u, got %lu headers!\n",
count, (unsigned long)num_headers);
@ -211,8 +211,8 @@ static int server_push_callback(CURL *parent,
int main(int argc, char *argv[])
{
CURLcode res;
CURL *easy;
CURLM *multi_handle;
CURL *curl;
CURLM *multi;
int transfers = 1; /* we start with one */
const char *url = "https://localhost:8443/index.html";
@ -224,33 +224,33 @@ int main(int argc, char *argv[])
return (int)res;
/* init a multi stack */
multi_handle = curl_multi_init();
if(!multi_handle)
multi = curl_multi_init();
if(!multi)
goto error;
easy = curl_easy_init();
curl = curl_easy_init();
/* set options */
if(!easy || setup(easy, url)) {
if(!curl || setup(curl, url)) {
fprintf(stderr, "failed\n");
goto error;
}
curl_multi_setopt(multi_handle, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
curl_multi_setopt(multi_handle, CURLMOPT_PUSHFUNCTION, server_push_callback);
curl_multi_setopt(multi_handle, CURLMOPT_PUSHDATA, &transfers);
curl_multi_setopt(multi, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
curl_multi_setopt(multi, CURLMOPT_PUSHFUNCTION, server_push_callback);
curl_multi_setopt(multi, CURLMOPT_PUSHDATA, &transfers);
/* add the easy transfer */
curl_multi_add_handle(multi_handle, easy);
curl_multi_add_handle(multi, curl);
do {
struct CURLMsg *m;
int still_running; /* keep number of running handles */
CURLMcode mc = curl_multi_perform(multi_handle, &still_running);
CURLMcode mc = curl_multi_perform(multi, &still_running);
if(still_running)
/* wait for activity, timeout or "nothing" */
mc = curl_multi_poll(multi_handle, NULL, 0, 1000, NULL);
mc = curl_multi_poll(multi, NULL, 0, 1000, NULL);
if(mc)
break;
@ -262,12 +262,12 @@ int main(int argc, char *argv[])
*/
do {
int msgq = 0;
m = curl_multi_info_read(multi_handle, &msgq);
m = curl_multi_info_read(multi, &msgq);
if(m && (m->msg == CURLMSG_DONE)) {
CURL *e = m->easy_handle;
curl = m->easy_handle;
transfers--;
curl_multi_remove_handle(multi_handle, e);
curl_easy_cleanup(e);
curl_multi_remove_handle(multi, curl);
curl_easy_cleanup(curl);
}
} while(m);
@ -275,8 +275,8 @@ int main(int argc, char *argv[])
error:
if(multi_handle)
curl_multi_cleanup(multi_handle);
if(multi)
curl_multi_cleanup(multi);
curl_global_cleanup();