Fix crashes and blocking with curl threads 46/162546/1 accepted/tizen/unified/20171205.060637 submit/tizen/20171204.082943
authorchanywa <cbible.kim@samsung.com>
Mon, 4 Dec 2017 07:09:07 +0000 (16:09 +0900)
committerchanywa <cbible.kim@samsung.com>
Mon, 4 Dec 2017 07:09:07 +0000 (16:09 +0900)
Change-Id: I5b9d94e957644f2c47eb6f381f76535fef266566
Signed-off-by: chanywa <cbible.kim@samsung.com>
maps-plugin-mapzen.changes
packaging/maps-plugin-mapzen.spec
src/mapzen/mapzen_restcurl.c

index cd244c7..079219e 100644 (file)
@@ -1,3 +1,8 @@
+[Version]   maps-plugin-mapzen_0.1.2
+[Date]      04 Dec 2017
+[Title]     Fix crashes and blocking with curl threads
+[Developer] Seechan Kim <cbible.kim@samsung.com>
+
 [Version]   maps-plugin-mapzen_0.1.1
 [Date]      30 Oct 2017
 [Title]     Revise timeout limits for downloading map tiles.
index ed6b0bd..c7c2b0c 100644 (file)
@@ -1,6 +1,6 @@
 Name:       maps-plugin-mapzen
 Summary:    Tizen Mapzen Maps Plug-in Library
-Version:    0.1.1
+Version:    0.1.2
 Release:    1
 Group:      Location/Libraries
 License:    Apache-2.0 and MIT
index 913a717..3414298 100644 (file)
@@ -26,6 +26,7 @@
 #include "mapzen_util.h"
 
 #define RESTCURL_USE_MULTI_CURL
+#define TIZEN_CFG_CURL_TIMEOUT 120
 
 CURLM *__cm_handle;
 pthread_t __CurlThread;
@@ -305,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;
 }
@@ -406,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);
 
@@ -419,6 +420,9 @@ int add_handle(const char *url, mapzen_req_type type, void *user_data)
        /* some servers don't like requests that are made without a user-agent field, so we provide one */
        curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
 
+       /* Timeout for the entire request */
+       curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, TIZEN_CFG_CURL_TIMEOUT);
+
        pMultiCurlArg->curl_handle = curl_handle;
        pMultiCurlArg->req_type = type;
        pMultiCurlArg->request_id = req_id;
@@ -473,7 +477,7 @@ static void __post_curl(mapzen_req_type type, MemoryStruct_s *m_chunk, void *use
 
 static void *__curl_thread_handler(void *user_data)
 {
-       __thread_running_for_curlmulti = true;
+       //__thread_running_for_curlmulti = true;
        pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
 
 #ifdef RESTCURL_USE_MULTI_CURL
@@ -537,13 +541,22 @@ static void *__curl_thread_handler(void *user_data)
                        }
                }
 
+               pthread_mutex_lock(&__curl_deliver_mutex);
                if (__thread_running_for_curlmulti && !__MultiCurlArgsRemain) {
-                       pthread_mutex_lock(&__curl_deliver_mutex);
+                       #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);
-                       pthread_mutex_unlock(&__curl_deliver_mutex);
+                       #endif
                }
+               pthread_mutex_unlock(&__curl_deliver_mutex);
        }
-
 #else
        /* curl_easy_perform */
 #endif
@@ -587,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;
@@ -597,14 +610,13 @@ int init_curl()
 int deinit_curl()
 {
 #ifdef RESTCURL_USE_MULTI_CURL
+       pthread_mutex_lock(&__curl_deliver_mutex);
        __thread_running_for_curlmulti = false;
        __MultiCurlArgsRemain = 0;
-
-       pthread_mutex_lock(&__curl_deliver_mutex);
        pthread_cond_signal(&__curl_delivered_cond);
        pthread_mutex_unlock(&__curl_deliver_mutex);
 
-       pthread_cancel(__CurlThread);
+       //pthread_cancel(__CurlThread);
 
        pthread_join(__CurlThread, NULL);