From 2a86d6f32e305bb6ff6bdc56e677970416dbd20c Mon Sep 17 00:00:00 2001 From: Jacek Jendrzej Date: Wed, 4 Feb 2015 15:35:13 +0100 Subject: [PATCH] pictureviewer.cpp: CPictureViewer::DownloadImage add curl timeout opt Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/1121e6210eb6e428b94b9cb0013ceb07324b2328 Author: Jacek Jendrzej Date: 2015-02-04 (Wed, 04 Feb 2015) --- src/driver/pictureviewer/pictureviewer.cpp | 27 ++++++++++++++-------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/driver/pictureviewer/pictureviewer.cpp b/src/driver/pictureviewer/pictureviewer.cpp index 022c4f553..aab815c70 100644 --- a/src/driver/pictureviewer/pictureviewer.cpp +++ b/src/driver/pictureviewer/pictureviewer.cpp @@ -111,15 +111,24 @@ std::string CPictureViewer::DownloadImage(std::string url) FILE *tmpFile = fopen(tmpname.c_str(), "wb"); if (tmpFile) { CURL *ch = curl_easy_init(); - curl_easy_setopt(ch, CURLOPT_VERBOSE, 0L); - curl_easy_setopt(ch, CURLOPT_NOPROGRESS, 1L); - curl_easy_setopt(ch, CURLOPT_NOSIGNAL, 1L); - curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, NULL); - curl_easy_setopt(ch, CURLOPT_WRITEDATA, tmpFile); - curl_easy_setopt(ch, CURLOPT_FAILONERROR, 1L); - curl_easy_setopt(ch, CURLOPT_URL, url.c_str()); - curl_easy_perform(ch); - curl_easy_cleanup(ch); + if(ch) + { + curl_easy_setopt(ch, CURLOPT_VERBOSE, 0L); + curl_easy_setopt(ch, CURLOPT_NOPROGRESS, 1L); + curl_easy_setopt(ch, CURLOPT_NOSIGNAL, 1L); + curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, NULL); + curl_easy_setopt(ch, CURLOPT_WRITEDATA, tmpFile); + curl_easy_setopt(ch, CURLOPT_FAILONERROR, 1L); + curl_easy_setopt(ch, CURLOPT_URL, url.c_str()); + curl_easy_setopt(ch, CURLOPT_NOSIGNAL,1); + curl_easy_setopt(ch, CURLOPT_CONNECTTIMEOUT, 3); + curl_easy_setopt(ch, CURLOPT_TIMEOUT, 4); + CURLcode res = curl_easy_perform(ch); + if (res != CURLE_OK){ + printf("[%s] curl_easy_perform() failed:%s\n",__func__, curl_easy_strerror(res)); + } + curl_easy_cleanup(ch); + } fclose(tmpFile); url = true; }