]> git.feebdaed.xyz Git - 0xmirror/curl.git/commitdiff
examples/threaded-ssl: delete in favor of `examples/threaded`
authorViktor Szakats <commit@vsz.me>
Tue, 16 Dec 2025 20:32:29 +0000 (21:32 +0100)
committerViktor Szakats <commit@vsz.me>
Tue, 16 Dec 2025 23:32:20 +0000 (00:32 +0100)
After applying a recent fix made to `threaded.c` (formerly
`multithread.c`) to `threaded-ssl.c`, syncing and updating comments,
the two examples turned out to be identical except their test URLs.

Delete one of them to avoid duplication.

Also:
- examples/threaded: scope a variable.
- examples/threaded: merge comments from its deleted sibling.

Follow-up to 61273f58125c41a84febe90a50238ee7fb12a9ad #20001
Follow-up to 971e8d661c68ce8859885c3ae865ff9441b62f0e #19526 #19524

Closes #20002

docs/examples/.gitignore
docs/examples/Makefile.inc
docs/examples/threaded-ssl.c [deleted file]
docs/examples/threaded.c

index ffda1ce70a45102de4fda25ed29c0f815e85de43..c96ad9127201928b528672a112c550f01a4a4fb7 100644 (file)
@@ -123,7 +123,6 @@ smtp-vrfy
 sslbackend
 synctime
 threaded
-threaded-ssl
 unixsocket
 url2file
 urlapi
index 39b2efcd59af046dbdbd43ebb64676994a475c7e..8c85fb8382329d1877c31fab2201a722d049af7c 100644 (file)
@@ -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 (file)
index d8053d3..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-/***************************************************************************
- *                                  _   _ ____  _
- *  Project                     ___| | | |  _ \| |
- *                             / __| | | | |_) | |
- *                            | (__| |_| |  _ <| |___
- *                             \___|\___/|_| \_\_____|
- *
- * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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
- *
- ***************************************************************************/
-/* <DESC>
- * Show the required mutex callback setups for GnuTLS and OpenSSL when using
- * libcurl multi-threaded.
- * </DESC>
- */
-/* 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 <stdio.h>
-
-#include <pthread.h>
-
-#include <curl/curl.h>
-
-#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;
-}
index 4e56312cbda2f222a14d3cd9beae70ea48b3801e..bb642212242b6518ff9e0820b25ceceb7ed206e7 100644 (file)
  * A multi-threaded program using pthreads to fetch several files at once
  * </DESC>
  */
+/* 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 <stdio.h>
 
 
 #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)