aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/examples/curlgtk.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/docs/examples/curlgtk.c b/docs/examples/curlgtk.c
index bba1fe1c9..69b016261 100644
--- a/docs/examples/curlgtk.c
+++ b/docs/examples/curlgtk.c
@@ -1,8 +1,8 @@
/*****************************************************************************
- * _ _ ____ _
- * Project ___| | | | _ \| |
- * / __| | | | |_) | |
- * | (__| |_| | _ <| |___
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* $Id$
@@ -17,10 +17,13 @@
#include <curl/types.h> /* new for v7 */
#include <curl/easy.h> /* new for v7 */
-#include <pthread.h>
-
GtkWidget *Bar;
+size_t my_write_func(void *ptr, size_t size, size_t nmemb, FILE *stream)
+{
+ return fwrite(ptr, size, nmemb, stream);
+}
+
size_t my_read_func(void *ptr, size_t size, size_t nmemb, FILE *stream)
{
return fread(ptr, size, nmemb, stream);
@@ -45,25 +48,27 @@ void *curl_thread(void *ptr)
CURLcode res;
FILE *outfile;
gchar *url = ptr;
-
+
curl = curl_easy_init();
if(curl)
{
- outfile = fopen("/tmp/test.curl", "w");
+ outfile = fopen("test.curl", "w");
curl_easy_setopt(curl, CURLOPT_URL, url);
- curl_easy_setopt(curl, CURLOPT_FILE, outfile);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_write_func);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, my_read_func);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, my_progress_func);
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, Bar);
-
+
res = curl_easy_perform(curl);
fclose(outfile);
/* always cleanup */
curl_easy_cleanup(curl);
}
+
return NULL;
}
@@ -71,11 +76,10 @@ int main(int argc, char **argv)
{
GtkWidget *Window, *Frame, *Frame2;
GtkAdjustment *adj;
- pthread_t curl_tid;
/* Init thread */
g_thread_init(NULL);
-
+
gtk_init(&argc, &argv);
Window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
Frame = gtk_frame_new(NULL);
@@ -90,8 +94,10 @@ int main(int argc, char **argv)
gtk_container_add(GTK_CONTAINER(Frame2), Bar);
gtk_widget_show_all(Window);
- pthread_create(&curl_tid, NULL, curl_thread, argv[1]);
-
+ if (!g_thread_create(&curl_thread, argv[1], FALSE, NULL) != 0)
+ g_warning("can't create the thread");
+
+
gdk_threads_enter();
gtk_main();
gdk_threads_leave();