From 770e4ffdedf75b5b120df8f814bc51fb7d37ac48 Mon Sep 17 00:00:00 2001 From: chanywa Date: Mon, 4 Dec 2017 15:56:49 +0900 Subject: [PATCH] Fix crashes and blocking with curl threads Change-Id: Ie9e1ebbc92d1d47de2a1394f752d96d06be4cece Signed-off-by: chanywa --- maps-plugin-mapzen.changes | 5 +++++ packaging/maps-plugin-mapzen.spec | 2 +- src/mapzen/mapzen_restcurl.c | 24 +++++++++++++++++------- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/maps-plugin-mapzen.changes b/maps-plugin-mapzen.changes index 107e3e6..9f9ee80 100644 --- a/maps-plugin-mapzen.changes +++ b/maps-plugin-mapzen.changes @@ -1,3 +1,8 @@ +[Version] maps-plugin-mapzen_0.0.9 +[Date] 04 Dec 2017 +[Title] Fix crashes and blocking with curl threads +[Developer] Seechan Kim + [Version] maps-plugin-mapzen_0.0.8 [Date] 30 Nov 2017 [Title] Fix crashes when terminating threads diff --git a/packaging/maps-plugin-mapzen.spec b/packaging/maps-plugin-mapzen.spec index 85b6264..a0081a8 100644 --- a/packaging/maps-plugin-mapzen.spec +++ b/packaging/maps-plugin-mapzen.spec @@ -1,6 +1,6 @@ Name: maps-plugin-mapzen Summary: Tizen Mapzen Maps Plug-in Library -Version: 0.0.8 +Version: 0.0.9 Release: 1 Group: Location/Libraries License: Apache-2.0 and MIT diff --git a/src/mapzen/mapzen_restcurl.c b/src/mapzen/mapzen_restcurl.c index 91b799d..3414298 100644 --- a/src/mapzen/mapzen_restcurl.c +++ b/src/mapzen/mapzen_restcurl.c @@ -306,8 +306,8 @@ static size_t __write_memory_callback(void *contents, size_t size, size_t nmemb, mem->size += realsize; - MAP_DEBUG("REal size : %d", realsize); - MAP_DEBUG("response size :: %d", strlen(mem->memory)); + MAP_DEBUG("Real size : %d", realsize); + MAP_DEBUG("Response size :: %d", strlen(mem->memory)); return realsize; } @@ -407,7 +407,7 @@ int add_handle(const char *url, mapzen_req_type type, void *user_data) curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 0L); - curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 1L); curl_easy_setopt(curl_handle, CURLOPT_PROXY, __proxy_address); @@ -542,11 +542,21 @@ static void *__curl_thread_handler(void *user_data) } pthread_mutex_lock(&__curl_deliver_mutex); - if (__thread_running_for_curlmulti && !__MultiCurlArgsRemain) + if (__thread_running_for_curlmulti && !__MultiCurlArgsRemain) { + #if 1 + struct timeval now; + struct timespec timeout; + gettimeofday(&now, NULL); + timeout.tv_sec = now.tv_sec + 3; + timeout.tv_nsec = now.tv_usec * 1000; + + pthread_cond_timedwait(&__curl_delivered_cond, &__curl_deliver_mutex, &timeout); + #else pthread_cond_wait(&__curl_delivered_cond, &__curl_deliver_mutex); + #endif + } pthread_mutex_unlock(&__curl_deliver_mutex); } - #else /* curl_easy_perform */ #endif @@ -590,8 +600,8 @@ int init_curl() curl_multi_setopt(__cm_handle, CURLMOPT_MAXCONNECTS, (long)CURL_MAX_CONNECTS); __MultiCurlArgsRemain = 0; - int ret = pthread_create(&__CurlThread, NULL, &__curl_thread_handler, NULL); __thread_running_for_curlmulti = true; + int ret = pthread_create(&__CurlThread, NULL, &__curl_thread_handler, NULL); #endif return ret; @@ -606,7 +616,7 @@ int deinit_curl() pthread_cond_signal(&__curl_delivered_cond); pthread_mutex_unlock(&__curl_deliver_mutex); - pthread_cancel(__CurlThread); + //pthread_cancel(__CurlThread); pthread_join(__CurlThread, NULL); -- 2.7.4