Mercurial > audlegacy-plugins
comparison src/curl/curl.c @ 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 |
comparison
equal
deleted
inserted
replaced
945:4f7a55282201 | 946:2d06a4e9b032 |
---|---|
81 gchar *proxy_host; | 81 gchar *proxy_host; |
82 gchar *proxy_auth; | 82 gchar *proxy_auth; |
83 } proxy_info; | 83 } proxy_info; |
84 | 84 |
85 gchar *local_ip; | 85 gchar *local_ip; |
86 | |
87 GMutex *curl_mutex; | |
88 GCond *curl_cond; | |
86 }; | 89 }; |
87 | 90 |
88 void curl_vfs_rewind_impl(VFSFile * file); | 91 void curl_vfs_rewind_impl(VFSFile * file); |
89 glong curl_vfs_ftell_impl(VFSFile * file); | 92 glong curl_vfs_ftell_impl(VFSFile * file); |
90 gboolean curl_vfs_feof_impl(VFSFile * file); | 93 gboolean curl_vfs_feof_impl(VFSFile * file); |
307 gint ret = 0; | 310 gint ret = 0; |
308 gint trans; | 311 gint trans; |
309 | 312 |
310 if (!handle->header) | 313 if (!handle->header) |
311 update_length(handle); | 314 update_length(handle); |
315 | |
316 g_cond_signal(handle->curl_cond); | |
312 | 317 |
313 while (ret < sz) | 318 while (ret < sz) |
314 { | 319 { |
315 while (!(trans = buf_space(handle)) && !handle->cancel) | 320 while (!(trans = buf_space(handle)) && !handle->cancel) |
316 { | 321 { |
491 handle->failed = 1; | 496 handle->failed = 1; |
492 } | 497 } |
493 if (DEBUG_CONNECTION) | 498 if (DEBUG_CONNECTION) |
494 g_print("Done %p%s", handle, handle->cancel ? " (aborted)\n" : "\n"); | 499 g_print("Done %p%s", handle, handle->cancel ? " (aborted)\n" : "\n"); |
495 handle->cancel = 1; | 500 handle->cancel = 1; |
501 | |
502 g_cond_signal(handle->curl_cond); | |
503 | |
496 return NULL; | 504 return NULL; |
497 } | 505 } |
498 | 506 |
499 static void curl_req_xfer(CurlHandle *handle) | 507 static void curl_req_xfer(CurlHandle *handle) |
500 { | 508 { |
511 handle->wr_abs = handle->rd_abs; | 519 handle->wr_abs = handle->rd_abs; |
512 if (DEBUG_CONNECTION) | 520 if (DEBUG_CONNECTION) |
513 g_print("Starting connection %p at %d\n", handle, handle->wr_abs); | 521 g_print("Starting connection %p at %d\n", handle, handle->wr_abs); |
514 handle->thread = g_thread_create(curl_manage_request, handle, | 522 handle->thread = g_thread_create(curl_manage_request, handle, |
515 TRUE, NULL); | 523 TRUE, NULL); |
524 | |
525 g_cond_wait(handle->curl_cond, handle->curl_mutex); | |
516 } | 526 } |
517 } | 527 } |
518 | 528 |
519 static void curl_req_sync_xfer(CurlHandle *handle, size_t old_rd_abs) | 529 static void curl_req_sync_xfer(CurlHandle *handle, size_t old_rd_abs) |
520 { | 530 { |
560 handle->length = -1; | 570 handle->length = -1; |
561 handle->cancel = 0; | 571 handle->cancel = 0; |
562 handle->failed = 0; | 572 handle->failed = 0; |
563 handle->no_data = 0; | 573 handle->no_data = 0; |
564 handle->stream_stack = NULL; | 574 handle->stream_stack = NULL; |
575 handle->curl_mutex = g_mutex_new(); | |
576 handle->curl_cond = g_cond_new(); | |
565 | 577 |
566 curl_easy_setopt(handle->curl, CURLOPT_URL, url); | 578 curl_easy_setopt(handle->curl, CURLOPT_URL, url); |
567 curl_easy_setopt(handle->curl, CURLOPT_WRITEFUNCTION, curl_writecb); | 579 curl_easy_setopt(handle->curl, CURLOPT_WRITEFUNCTION, curl_writecb); |
568 curl_easy_setopt(handle->curl, CURLOPT_WRITEDATA, handle); | 580 curl_easy_setopt(handle->curl, CURLOPT_WRITEDATA, handle); |
569 curl_easy_setopt(handle->curl, CURLOPT_HEADERDATA, handle); | 581 curl_easy_setopt(handle->curl, CURLOPT_HEADERDATA, handle); |
663 g_free(handle->name); | 675 g_free(handle->name); |
664 if (handle->stream_stack != NULL) | 676 if (handle->stream_stack != NULL) |
665 g_slist_free(handle->stream_stack); | 677 g_slist_free(handle->stream_stack); |
666 curl_easy_cleanup(handle->curl); | 678 curl_easy_cleanup(handle->curl); |
667 | 679 |
680 g_mutex_free(handle->curl_mutex); | |
681 g_cond_free(handle->curl_cond); | |
682 | |
668 if (handle->local_ip != NULL) | 683 if (handle->local_ip != NULL) |
669 g_free(handle->local_ip); | 684 g_free(handle->local_ip); |
670 | 685 |
671 if (handle->proxy_info.proxy_host != NULL) | 686 if (handle->proxy_info.proxy_host != NULL) |
672 g_free(handle->proxy_info.proxy_host); | 687 g_free(handle->proxy_info.proxy_host); |
698 if (sz < 0) | 713 if (sz < 0) |
699 return 0; | 714 return 0; |
700 | 715 |
701 // g_print("Reading %d*%d=%d from %p\n", size, nmemb, sz, handle); | 716 // g_print("Reading %d*%d=%d from %p\n", size, nmemb, sz, handle); |
702 | 717 |
718 memset(ptr, '\0', sz); | |
719 | |
703 /* check if there are ungetted chars that should be picked before the real fread */ | 720 /* check if there are ungetted chars that should be picked before the real fread */ |
704 if ( handle->stream_stack != NULL ) | 721 if ( handle->stream_stack != NULL ) |
705 { | 722 { |
706 guchar uc; | 723 guchar uc; |
707 while ( (ret < sz) && (handle->stream_stack != NULL) ) | 724 while ( (ret < sz) && (handle->stream_stack != NULL) ) |
714 } | 731 } |
715 } | 732 } |
716 | 733 |
717 curl_req_xfer(handle); | 734 curl_req_xfer(handle); |
718 | 735 |
736 if (handle->failed == 1) | |
737 { | |
738 g_print("failed!\n"); | |
739 return 0; | |
740 } | |
741 | |
719 if (DEBUG_SEEK) | 742 if (DEBUG_SEEK) |
720 check(handle); | 743 check(handle); |
721 | |
722 memset(ptr, '\0', sz); | |
723 | 744 |
724 while (ret < sz) | 745 while (ret < sz) |
725 { | 746 { |
726 ssize_t available; | 747 ssize_t available; |
727 while (!(available = buf_available(handle)) && !handle->cancel) | 748 while (!(available = buf_available(handle)) && !handle->cancel) |