Made sure that curl_global_init is called in all the multithreaded
example programs.
This commit is contained in:
parent
16a9c5e02b
commit
bf52cef16f
4
CHANGES
4
CHANGES
@ -6,6 +6,10 @@
|
|||||||
|
|
||||||
Changelog
|
Changelog
|
||||||
|
|
||||||
|
Daniel Fandrich (3 Apr 2008)
|
||||||
|
- Made sure that curl_global_init is called in all the multithreaded
|
||||||
|
example programs.
|
||||||
|
|
||||||
Michal Marek (31 Mar 2008)
|
Michal Marek (31 Mar 2008)
|
||||||
- Removed the generated ca-bundle.h file. The verbatim value of $ca and
|
- Removed the generated ca-bundle.h file. The verbatim value of $ca and
|
||||||
$capath is known to configure, so it can be defined in config.h instead.
|
$capath is known to configure, so it can be defined in config.h instead.
|
||||||
|
@ -29,7 +29,7 @@ size_t my_read_func(void *ptr, size_t size, size_t nmemb, FILE *stream)
|
|||||||
return fread(ptr, size, nmemb, stream);
|
return fread(ptr, size, nmemb, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
int my_progress_func(GtkWidget *Bar,
|
int my_progress_func(GtkWidget *bar,
|
||||||
double t, /* dltotal */
|
double t, /* dltotal */
|
||||||
double d, /* dlnow */
|
double d, /* dlnow */
|
||||||
double ultotal,
|
double ultotal,
|
||||||
@ -37,7 +37,7 @@ int my_progress_func(GtkWidget *Bar,
|
|||||||
{
|
{
|
||||||
/* printf("%d / %d (%g %%)\n", d, t, d*100.0/t);*/
|
/* printf("%d / %d (%g %%)\n", d, t, d*100.0/t);*/
|
||||||
gdk_threads_enter();
|
gdk_threads_enter();
|
||||||
gtk_progress_set_value(GTK_PROGRESS(Bar), d*100.0/t);
|
gtk_progress_set_value(GTK_PROGRESS(bar), d*100.0/t);
|
||||||
gdk_threads_leave();
|
gdk_threads_leave();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -77,6 +77,9 @@ int main(int argc, char **argv)
|
|||||||
GtkWidget *Window, *Frame, *Frame2;
|
GtkWidget *Window, *Frame, *Frame2;
|
||||||
GtkAdjustment *adj;
|
GtkAdjustment *adj;
|
||||||
|
|
||||||
|
/* Must initialize libcurl before any threads are started */
|
||||||
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
|
|
||||||
/* Init thread */
|
/* Init thread */
|
||||||
g_thread_init(NULL);
|
g_thread_init(NULL);
|
||||||
|
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
|
|
||||||
|
#define NUMT 4
|
||||||
|
|
||||||
/*
|
/*
|
||||||
List of URLs to fetch.
|
List of URLs to fetch.
|
||||||
|
|
||||||
@ -24,14 +26,14 @@
|
|||||||
http://www.openssl.org/docs/crypto/threads.html#DESCRIPTION
|
http://www.openssl.org/docs/crypto/threads.html#DESCRIPTION
|
||||||
|
|
||||||
*/
|
*/
|
||||||
const char *urls[]= {
|
const char * const urls[NUMT]= {
|
||||||
"http://curl.haxx.se/",
|
"http://curl.haxx.se/",
|
||||||
"ftp://cool.haxx.se/",
|
"ftp://cool.haxx.se/",
|
||||||
"http://www.contactor.se/",
|
"http://www.contactor.se/",
|
||||||
"www.haxx.se"
|
"www.haxx.se"
|
||||||
};
|
};
|
||||||
|
|
||||||
void *pull_one_url(void *url)
|
static void *pull_one_url(void *url)
|
||||||
{
|
{
|
||||||
CURL *curl;
|
CURL *curl;
|
||||||
|
|
||||||
@ -52,10 +54,14 @@ void *pull_one_url(void *url)
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
pthread_t tid[4];
|
pthread_t tid[NUMT];
|
||||||
int i;
|
int i;
|
||||||
int error;
|
int error;
|
||||||
for(i=0; i< 4; i++) {
|
|
||||||
|
/* Must initialize libcurl before any threads are started */
|
||||||
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
|
|
||||||
|
for(i=0; i< NUMT; i++) {
|
||||||
error = pthread_create(&tid[i],
|
error = pthread_create(&tid[i],
|
||||||
NULL, /* default attributes please */
|
NULL, /* default attributes please */
|
||||||
pull_one_url,
|
pull_one_url,
|
||||||
@ -67,7 +73,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* now wait for all threads to terminate */
|
/* now wait for all threads to terminate */
|
||||||
for(i=0; i< 4; i++) {
|
for(i=0; i< NUMT; i++) {
|
||||||
error = pthread_join(tid[i], NULL);
|
error = pthread_join(tid[i], NULL);
|
||||||
fprintf(stderr, "Thread %d terminated\n", i);
|
fprintf(stderr, "Thread %d terminated\n", i);
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
gint num_urls = 9; /* Just make sure this is less than urls[]*/
|
gint num_urls = 9; /* Just make sure this is less than urls[]*/
|
||||||
char *urls[]= {
|
const char * const urls[]= {
|
||||||
"90022",
|
"90022",
|
||||||
"90023",
|
"90023",
|
||||||
"90024",
|
"90024",
|
||||||
@ -58,7 +58,6 @@ void *pull_one_url(void *NaN)
|
|||||||
CURLcode res;
|
CURLcode res;
|
||||||
gchar *http;
|
gchar *http;
|
||||||
FILE *outfile;
|
FILE *outfile;
|
||||||
gint i;
|
|
||||||
|
|
||||||
/* Stop threads from entering unless j is incremented */
|
/* Stop threads from entering unless j is incremented */
|
||||||
pthread_mutex_lock(&lock);
|
pthread_mutex_lock(&lock);
|
||||||
@ -167,7 +166,9 @@ static gboolean cb_delete(GtkWidget *window, gpointer data)
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
GtkWidget *top_window, *outside_frame, *inside_frame, *progress_bar;
|
GtkWidget *top_window, *outside_frame, *inside_frame, *progress_bar;
|
||||||
GtkAdjustment *adj;
|
|
||||||
|
/* Must initialize libcurl before any threads are started */
|
||||||
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
|
|
||||||
/* Init thread */
|
/* Init thread */
|
||||||
g_thread_init(NULL);
|
g_thread_init(NULL);
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
|
|
||||||
|
#define NUMT 4
|
||||||
|
|
||||||
/* we have this global to let the callback get easy access to it */
|
/* we have this global to let the callback get easy access to it */
|
||||||
static pthread_mutex_t *lockarray;
|
static pthread_mutex_t *lockarray;
|
||||||
|
|
||||||
@ -89,7 +91,7 @@ void init_locks(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* List of URLs to fetch.*/
|
/* List of URLs to fetch.*/
|
||||||
const char *urls[]= {
|
const char * const urls[]= {
|
||||||
"https://www.sf.net/",
|
"https://www.sf.net/",
|
||||||
"https://www.openssl.org/",
|
"https://www.openssl.org/",
|
||||||
"https://www.sf.net/",
|
"https://www.sf.net/",
|
||||||
@ -114,15 +116,18 @@ static void *pull_one_url(void *url)
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
pthread_t tid[4];
|
pthread_t tid[NUMT];
|
||||||
int i;
|
int i;
|
||||||
int error;
|
int error;
|
||||||
(void)argc; /* we don't use any arguments in this example */
|
(void)argc; /* we don't use any arguments in this example */
|
||||||
(void)argv;
|
(void)argv;
|
||||||
|
|
||||||
|
/* Must initialize libcurl before any threads are started */
|
||||||
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
|
|
||||||
init_locks();
|
init_locks();
|
||||||
|
|
||||||
for(i=0; i< 4; i++) {
|
for(i=0; i< NUMT; i++) {
|
||||||
error = pthread_create(&tid[i],
|
error = pthread_create(&tid[i],
|
||||||
NULL, /* default attributes please */
|
NULL, /* default attributes please */
|
||||||
pull_one_url,
|
pull_one_url,
|
||||||
@ -134,7 +139,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* now wait for all threads to terminate */
|
/* now wait for all threads to terminate */
|
||||||
for(i=0; i< 4; i++) {
|
for(i=0; i< NUMT; i++) {
|
||||||
error = pthread_join(tid[i], NULL);
|
error = pthread_join(tid[i], NULL);
|
||||||
fprintf(stderr, "Thread %d terminated\n", i);
|
fprintf(stderr, "Thread %d terminated\n", i);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user