diff --git a/docs/examples/.gitignore b/docs/examples/.gitignore index ffda1ce70a..c96ad91272 100644 --- a/docs/examples/.gitignore +++ b/docs/examples/.gitignore @@ -123,7 +123,6 @@ smtp-vrfy sslbackend synctime threaded -threaded-ssl unixsocket url2file urlapi diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index 39b2efcd59..8c85fb8382 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -148,7 +148,6 @@ COMPLICATED_MAY_BUILD = \ multi-uv.c \ sessioninfo.c \ threaded.c \ - threaded-ssl.c \ usercertinmem.c # These examples require external dependencies that may not be commonly diff --git a/docs/examples/threaded-ssl.c b/docs/examples/threaded-ssl.c deleted file mode 100644 index d8053d3ccc..0000000000 --- a/docs/examples/threaded-ssl.c +++ /dev/null @@ -1,110 +0,0 @@ -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) Daniel Stenberg, , et al. - * - * This software is licensed as described in the file COPYING, which - * you should have received as part of this distribution. The terms - * are also available at https://curl.se/docs/copyright.html. - * - * You may opt to use, copy, modify, merge, publish, distribute and/or sell - * copies of the Software, and permit persons to whom the Software is - * furnished to do so, under the terms of the COPYING file. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - * SPDX-License-Identifier: curl - * - ***************************************************************************/ -/* - * Show the required mutex callback setups for GnuTLS and OpenSSL when using - * libcurl multi-threaded. - * - */ -/* A multi-threaded example that uses pthreads and fetches 4 remote files at - * once over HTTPS. - * - * Recent versions of OpenSSL and GnuTLS are thread-safe by design, assuming - * support for the underlying OS threading API is built-in. Older revisions - * of this example demonstrated locking callbacks for the SSL library, which - * are no longer necessary. An older revision with callbacks can be found at - * https://github.com/curl/curl/blob/curl-7_88_1/docs/examples/threaded-ssl.c - */ - -/* Requires: HAVE_PTHREAD_H */ -/* Also requires TLS support to run */ - -#include - -#include - -#include - -#define NUMT 4 - -/* List of URLs to fetch.*/ -static const char * const urls[] = { - "https://www.example.com/", - "https://www2.example.com/", - "https://www3.example.com/", - "https://www4.example.com/", -}; - -static void *pull_one_url(void *pindex) -{ - CURL *curl; - - curl = curl_easy_init(); - if(curl) { - int i = *(int *)pindex; - curl_easy_setopt(curl, CURLOPT_URL, urls[i]); - /* this example does not verify the server's certificate, which means we - might be downloading stuff from an impostor */ - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); - (void)curl_easy_perform(curl); /* ignores error */ - curl_easy_cleanup(curl); - } - - return NULL; -} - -int main(int argc, char **argv) -{ - CURLcode res; - pthread_t tid[NUMT]; - int i; - (void)argc; - (void)argv; - - /* Must initialize libcurl before any threads are started */ - res = curl_global_init(CURL_GLOBAL_ALL); - if(res) - return (int)res; - - for(i = 0; i < NUMT; i++) { - int error = pthread_create(&tid[i], - NULL, /* default attributes please */ - pull_one_url, - (void *)&i); - if(error) - fprintf(stderr, "Could not run thread number %d, errno %d\n", i, error); - else - fprintf(stderr, "Thread %d, gets %s\n", i, urls[i]); - } - - /* now wait for all threads to terminate */ - for(i = 0; i < NUMT; i++) { - pthread_join(tid[i], NULL); - fprintf(stderr, "Thread %d terminated\n", i); - } - - curl_global_cleanup(); - - return 0; -} diff --git a/docs/examples/threaded.c b/docs/examples/threaded.c index 4e56312cbd..bb64221224 100644 --- a/docs/examples/threaded.c +++ b/docs/examples/threaded.c @@ -25,8 +25,18 @@ * A multi-threaded program using pthreads to fetch several files at once * */ +/* A multi-threaded example that uses pthreads and fetches 4 remote files at + * once over HTTPS. + * + * Recent versions of OpenSSL and GnuTLS are thread-safe by design, assuming + * support for the underlying OS threading API is built-in. Older revisions + * of this example demonstrated locking callbacks for the SSL library, which + * are no longer necessary. An older revision with callbacks can be found at + * https://github.com/curl/curl/blob/curl-7_88_1/docs/examples/threaded-ssl.c + */ /* Requires: HAVE_PTHREAD_H */ +/* Also requires TLS support to run */ #include @@ -36,15 +46,7 @@ #define NUMT 4 -/* - List of URLs to fetch. - - If you intend to use an SSL-based protocol here you might need to setup TLS - library mutex callbacks as described here: - - https://curl.se/libcurl/c/threadsafe.html - -*/ +/* List of URLs to fetch. */ static const char * const urls[NUMT] = { "https://curl.se/", "ftp://example.com/", @@ -59,10 +61,10 @@ struct targ { static void *pull_one_url(void *p) { CURL *curl; - struct targ *targ = p; curl = curl_easy_init(); if(curl) { + struct targ *targ = p; curl_easy_setopt(curl, CURLOPT_URL, targ->url); (void)curl_easy_perform(curl); /* ignores error */ curl_easy_cleanup(curl); @@ -73,8 +75,8 @@ static void *pull_one_url(void *p) /* int pthread_create(pthread_t *new_thread_ID, - const pthread_attr_t *attr, - void * (*start_func)(void *), void *arg); + const pthread_attr_t *attr, + void * (*start_func)(void *), void *arg); */ int main(void)