mirror of
https://github.com/curl/curl.git
synced 2026-07-24 18:57:18 +03:00
examples: improve global init, error checks and returning errors
- add `curl_global_init()` and `curl_global_cleanup()` where missing. - check the result of `curl_global_init()` where missing. - return the last curl error from `main()`. - drop Win32-specific socket initialization in favor of `curl_global_init()`. - rename some outliers to `res` for curl result code. - fix cleanup in some error cases. Inspired by Joshua's report on examples. Closes #19053
This commit is contained in:
parent
3049c8e0a0
commit
4c7507daf9
129 changed files with 990 additions and 485 deletions
|
|
@ -212,6 +212,7 @@ static int server_push_callback(CURL *parent,
|
|||
*/
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
CURLcode res;
|
||||
CURL *easy;
|
||||
CURLM *multi_handle;
|
||||
int transfers = 1; /* we start with one */
|
||||
|
|
@ -221,6 +222,10 @@ int main(int argc, char *argv[])
|
|||
if(argc == 2)
|
||||
url = argv[1];
|
||||
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
/* init a multi stack */
|
||||
multi_handle = curl_multi_init();
|
||||
|
||||
|
|
@ -229,6 +234,7 @@ int main(int argc, char *argv[])
|
|||
/* set options */
|
||||
if(setup(easy, url)) {
|
||||
fprintf(stderr, "failed\n");
|
||||
curl_global_cleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -270,7 +276,7 @@ int main(int argc, char *argv[])
|
|||
} while(transfers); /* as long as we have transfers going */
|
||||
|
||||
curl_multi_cleanup(multi_handle);
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue