changeset 946:2d06a4e9b032 trunk

[svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
author nenolod
date Thu, 12 Apr 2007 13:22:28 -0700
parents 4f7a55282201
children 24a5068bb7f8
files ChangeLog src/curl/curl.c
diffstat 2 files changed, 31 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Apr 12 12:57:45 2007 -0700
+++ b/ChangeLog	Thu Apr 12 13:22:28 2007 -0700
@@ -1,3 +1,11 @@
+2007-04-12 19:57:45 +0000  William Pitcock <nenolod@sacredspiral.co.uk>
+  revision [2020]
+  - back out r2016,2018.
+  
+  trunk/src/curl/curl.c |   28 ++--------------------------
+  1 file changed, 2 insertions(+), 26 deletions(-)
+
+
 2007-04-12 19:33:04 +0000  William Pitcock <nenolod@sacredspiral.co.uk>
   revision [2018]
   - protect some functions with a mutex.
--- a/src/curl/curl.c	Thu Apr 12 12:57:45 2007 -0700
+++ b/src/curl/curl.c	Thu Apr 12 13:22:28 2007 -0700
@@ -83,6 +83,9 @@
   } proxy_info;
   
   gchar *local_ip;
+
+  GMutex *curl_mutex;
+  GCond *curl_cond;
 };
 
 void curl_vfs_rewind_impl(VFSFile * file);
@@ -310,6 +313,8 @@
   if (!handle->header)
     update_length(handle);
 
+  g_cond_signal(handle->curl_cond);
+
   while (ret < sz)
     {
       while (!(trans = buf_space(handle)) && !handle->cancel)
@@ -493,6 +498,9 @@
   if (DEBUG_CONNECTION)
     g_print("Done %p%s", handle, handle->cancel ? " (aborted)\n" : "\n");
   handle->cancel = 1;
+
+  g_cond_signal(handle->curl_cond);
+
   return NULL;
 }
 
@@ -513,6 +521,8 @@
 	g_print("Starting connection %p at %d\n", handle, handle->wr_abs);
       handle->thread = g_thread_create(curl_manage_request, handle, 
 				       TRUE, NULL);
+
+      g_cond_wait(handle->curl_cond, handle->curl_mutex);
     }
 }
 
@@ -562,6 +572,8 @@
   handle->failed = 0;
   handle->no_data = 0;
   handle->stream_stack = NULL;
+  handle->curl_mutex = g_mutex_new();
+  handle->curl_cond = g_cond_new();
 
   curl_easy_setopt(handle->curl, CURLOPT_URL, url);
   curl_easy_setopt(handle->curl, CURLOPT_WRITEFUNCTION, curl_writecb);
@@ -665,6 +677,9 @@
         g_slist_free(handle->stream_stack);
       curl_easy_cleanup(handle->curl);
 
+      g_mutex_free(handle->curl_mutex);
+      g_cond_free(handle->curl_cond);
+
       if (handle->local_ip != NULL)
         g_free(handle->local_ip);
 
@@ -700,6 +715,8 @@
 
 //  g_print("Reading %d*%d=%d from %p\n", size, nmemb, sz, handle);
 
+  memset(ptr, '\0', sz);
+
   /* check if there are ungetted chars that should be picked before the real fread */
   if ( handle->stream_stack != NULL )
   {
@@ -716,11 +733,15 @@
 
   curl_req_xfer(handle);
 
+  if (handle->failed == 1)
+  {
+      g_print("failed!\n");
+      return 0;
+  }
+
   if (DEBUG_SEEK)
     check(handle);
 
-  memset(ptr, '\0', sz);
-
   while (ret < sz)
     {
       ssize_t available;