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

@ -36,52 +36,51 @@
*/
int main(void)
{
CURL *http_handle;
CURL *http_handle2;
CURL *curl;
CURL *curl2;
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
if(res)
return (int)res;
http_handle = curl_easy_init();
http_handle2 = curl_easy_init();
curl = curl_easy_init();
curl2 = curl_easy_init();
if(http_handle &&
http_handle2) {
if(curl && curl2) {
CURLM *multi_handle;
CURLM *multi;
/* set options */
curl_easy_setopt(http_handle, CURLOPT_URL, "https://www.example.com/");
curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/");
/* set options */
curl_easy_setopt(http_handle2, CURLOPT_URL, "http://localhost/");
curl_easy_setopt(curl2, CURLOPT_URL, "http://localhost/");
/* init a multi stack */
multi_handle = curl_multi_init();
if(multi_handle) {
multi = curl_multi_init();
if(multi) {
int still_running = 1; /* keep number of running handles */
/* add the individual transfers */
curl_multi_add_handle(multi_handle, http_handle);
curl_multi_add_handle(multi_handle, http_handle2);
curl_multi_add_handle(multi, curl);
curl_multi_add_handle(multi, curl2);
while(still_running) {
CURLMsg *msg;
int queued;
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;
do {
msg = curl_multi_info_read(multi_handle, &queued);
msg = curl_multi_info_read(multi, &queued);
if(msg) {
if(msg->msg == CURLMSG_DONE) {
/* a transfer ended */
@ -91,15 +90,15 @@ int main(void)
} while(msg);
}
curl_multi_remove_handle(multi_handle, http_handle);
curl_multi_remove_handle(multi_handle, http_handle2);
curl_multi_remove_handle(multi, curl);
curl_multi_remove_handle(multi, curl2);
curl_multi_cleanup(multi_handle);
curl_multi_cleanup(multi);
}
}
curl_easy_cleanup(http_handle);
curl_easy_cleanup(http_handle2);
curl_easy_cleanup(curl);
curl_easy_cleanup(curl2);
curl_global_cleanup();