Diff of /trunk/src/gcvote.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 161 by harbaum, Thu Nov 5 08:58:28 2009 UTC revision 162 by harbaum, Thu Nov 5 09:56:17 2009 UTC
# Line 177  static gboolean gcvote_result_handler(gp Line 177  static gboolean gcvote_result_handler(gp
177    
178    printf("gcvote: result handler\n");    printf("gcvote: result handler\n");
179    
180    /* worker thread has already reduced its refcounter */    if(request->refcount < 2) {
   if(request->refcount < 1) {  
181      printf("gcvote: main app isn't listening anymore\n");      printf("gcvote: main app isn't listening anymore\n");
182        gcvote_request_free(request);
183      return FALSE;      return FALSE;
184    }    }
185    
186    if(request->res) {    if(request->res) {
187      printf("gcvote: curl failed\n");      printf("gcvote: curl failed\n");
188      request->cb(NULL, request->userdata);      request->cb(NULL, request->userdata);
189        gcvote_request_free(request);
190      return FALSE;      return FALSE;
191    }    }
192    
# Line 194  static gboolean gcvote_result_handler(gp Line 195  static gboolean gcvote_result_handler(gp
195    if(!request->mem.ptr || !request->mem.len) {    if(!request->mem.ptr || !request->mem.len) {
196      printf("gcvote: ignoring zero length reply\n");      printf("gcvote: ignoring zero length reply\n");
197      request->cb(NULL, request->userdata);      request->cb(NULL, request->userdata);
198        gcvote_request_free(request);
199      return FALSE;      return FALSE;
200    }    }
201    
# Line 207  static gboolean gcvote_result_handler(gp Line 209  static gboolean gcvote_result_handler(gp
209    /* nothing could be parsed, just give up */    /* nothing could be parsed, just give up */
210    if(!doc) {    if(!doc) {
211      request->cb(NULL, request->userdata);      request->cb(NULL, request->userdata);
212        gcvote_request_free(request);
213      return FALSE;      return FALSE;
214    }    }
215    
# Line 235  static gboolean gcvote_result_handler(gp Line 238  static gboolean gcvote_result_handler(gp
238    } else    } else
239      printf("gcvote: no vote found\n");      printf("gcvote: no vote found\n");
240    
241      gcvote_request_free(request);
242    return FALSE;    return FALSE;
243  }  }
244    
# Line 299  static void *worker_thread(void *ptr) { Line 303  static void *worker_thread(void *ptr) {
303    CURL *curl = curl_easy_init();    CURL *curl = curl_easy_init();
304    if(!curl) {    if(!curl) {
305      curl_formfree(formpost);      curl_formfree(formpost);
     gcvote_request_free(request);  
306    
307      /* callback anyway, so main loop can also clean up */      /* callback anyway, so main loop can also clean up */
308      g_idle_add(gcvote_result_handler, request);      g_idle_add(gcvote_result_handler, request);
# Line 335  static void *worker_thread(void *ptr) { Line 338  static void *worker_thread(void *ptr) {
338    /* then cleanup the formpost chain */    /* then cleanup the formpost chain */
339    curl_formfree(formpost);    curl_formfree(formpost);
340    
341      /* cause gtk main loop to handle result only if main loop */
342      /* is still interested. Don't free request then, since the */
343      /* gcvote_result_handler will do this */
344      if(request->refcount > 1)
345        g_idle_add(gcvote_result_handler, request);
346      else
347        gcvote_request_free(request);
348    
349    printf("gcvote: worker thread done\n");    printf("gcvote: worker thread done\n");
   gcvote_request_free(request);  
350    
   /* cause gtk main loop to handle result */  
   g_idle_add(gcvote_result_handler, request);  
   
   printf("gcvote: thread terminating\n");  
   
351    return NULL;    return NULL;
352  }  }
353    

Legend:
Removed from v.161  
changed lines
  Added in v.162