[aseprite] 36/64: Abort curl connections setting the timeout (avoid crash closing connections)

Tobias Hansen thansen at moszumanska.debian.org
Tue Jun 21 14:43:03 UTC 2016


This is an automated email from the git hooks/post-receive script.

thansen pushed a commit to branch master
in repository aseprite.

commit d495c4d18a4d337ceb724e5c473d2b63a7431fad
Author: David Capello <davidcapello at gmail.com>
Date:   Tue May 17 16:13:25 2016 -0300

    Abort curl connections setting the timeout (avoid crash closing connections)
---
 src/net/http_request.cpp     | 38 +++++++++++++++++---------------------
 src/net/http_request.h       |  7 +++----
 src/updater/check_update.cpp | 21 ++++++++++++---------
 src/updater/check_update.h   |  2 +-
 4 files changed, 33 insertions(+), 35 deletions(-)

diff --git a/src/net/http_request.cpp b/src/net/http_request.cpp
index 3517802..f7ff544 100644
--- a/src/net/http_request.cpp
+++ b/src/net/http_request.cpp
@@ -18,30 +18,26 @@
 
 namespace net {
 
-class HttpRequestImpl
-{
+class HttpRequestImpl {
 public:
   HttpRequestImpl(const std::string& url)
     : m_curl(curl_easy_init())
-    , m_headerlist(NULL)
-    , m_response(NULL)
-  {
+    , m_headerlist(nullptr)
+    , m_response(nullptr) {
     curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, this);
     curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, &HttpRequestImpl::writeBodyCallback);
     curl_easy_setopt(m_curl, CURLOPT_URL, url.c_str());
     curl_easy_setopt(m_curl, CURLOPT_NOSIGNAL, 1);
   }
 
-  ~HttpRequestImpl()
-  {
+  ~HttpRequestImpl() {
     if (m_headerlist)
       curl_slist_free_all(m_headerlist);
 
     curl_easy_cleanup(m_curl);
   }
 
-  void setHeaders(const HttpHeaders& headers)
-  {
+  void setHeaders(const HttpHeaders& headers) {
     if (m_headerlist) {
       curl_slist_free_all(m_headerlist);
       m_headerlist = NULL;
@@ -59,31 +55,31 @@ public:
     curl_easy_setopt(m_curl, CURLOPT_HTTPHEADER, m_headerlist);
   }
 
-  void send(HttpResponse& response)
-  {
+  bool send(HttpResponse& response) {
     m_response = &response;
-    curl_easy_perform(m_curl);
+    int res = curl_easy_perform(m_curl);
+    if (res != CURLE_OK)
+      return false;
 
     long code;
     curl_easy_getinfo(m_curl, CURLINFO_RESPONSE_CODE, &code);
     m_response->setStatus(code);
+    return true;
   }
 
-  void abort()
-  {
-    curl_easy_cleanup(m_curl);
+  void abort() {
+    curl_easy_setopt(m_curl, CURLOPT_TIMEOUT_MS, 1);
+    curl_easy_setopt(m_curl, CURLOPT_CONNECTTIMEOUT_MS, 1);
   }
 
 private:
-  std::size_t writeBody(char* ptr, std::size_t bytes)
-  {
+  std::size_t writeBody(char* ptr, std::size_t bytes) {
     ASSERT(m_response != NULL);
     m_response->write(ptr, bytes);
     return bytes;
   }
 
-  static std::size_t writeBodyCallback(char* ptr, std::size_t size, std::size_t nmemb, void* userdata)
-  {
+  static std::size_t writeBodyCallback(char* ptr, std::size_t size, std::size_t nmemb, void* userdata) {
     HttpRequestImpl* req = reinterpret_cast<HttpRequestImpl*>(userdata);
     return req->writeBody(ptr, size*nmemb);
   }
@@ -108,9 +104,9 @@ void HttpRequest::setHeaders(const HttpHeaders& headers)
   m_impl->setHeaders(headers);
 }
 
-void HttpRequest::send(HttpResponse& response)
+bool HttpRequest::send(HttpResponse& response)
 {
-  m_impl->send(response);
+  return m_impl->send(response);
 }
 
 void HttpRequest::abort()
diff --git a/src/net/http_request.h b/src/net/http_request.h
index 9a8af46..f124ab1 100644
--- a/src/net/http_request.h
+++ b/src/net/http_request.h
@@ -1,5 +1,5 @@
 // Aseprite Network Library
-// Copyright (c) 2001-2015 David Capello
+// Copyright (c) 2001-2016 David Capello
 //
 // This file is released under the terms of the MIT license.
 // Read LICENSE.txt for more information.
@@ -18,14 +18,13 @@ class HttpHeaders;
 class HttpRequestImpl;
 class HttpResponse;
 
-class HttpRequest
-{
+class HttpRequest {
 public:
   HttpRequest(const std::string& url);
   ~HttpRequest();
 
   void setHeaders(const HttpHeaders& headers);
-  void send(HttpResponse& response);
+  bool send(HttpResponse& response);
   void abort();
 
 private:
diff --git a/src/updater/check_update.cpp b/src/updater/check_update.cpp
index fd50de3..60f67ee 100644
--- a/src/updater/check_update.cpp
+++ b/src/updater/check_update.cpp
@@ -96,7 +96,7 @@ public:
       m_request->abort();
   }
 
-  void checkNewVersion(const Uuid& uuid, const std::string& extraParams, CheckUpdateDelegate* delegate)
+  bool checkNewVersion(const Uuid& uuid, const std::string& extraParams, CheckUpdateDelegate* delegate)
   {
 #ifndef UPDATE_URL
 #define UPDATE_URL ""
@@ -120,13 +120,16 @@ public:
 
     std::stringstream body;
     net::HttpResponse response(&body);
-    m_request->send(response);
+    if (m_request->send(response)) {
+      TRACE("Checking updates: %s (User-Agent: %s)\n", url.c_str(), getUserAgent().c_str());
+      TRACE("Response:\n--\n%s--\n", body.str().c_str());
 
-    TRACE("Checking updates: %s (User-Agent: %s)\n", url.c_str(), getUserAgent().c_str());
-    TRACE("Response:\n--\n%s--\n", body.str().c_str());
-
-    CheckUpdateResponse data(body.str());
-    delegate->onResponse(data);
+      CheckUpdateResponse data(body.str());
+      delegate->onResponse(data);
+      return true;
+    }
+    else
+      return false;
   }
 
 private:
@@ -148,9 +151,9 @@ void CheckUpdate::abort()
   m_impl->abort();
 }
 
-void CheckUpdate::checkNewVersion(const Uuid& uuid, const std::string& extraParams, CheckUpdateDelegate* delegate)
+bool CheckUpdate::checkNewVersion(const Uuid& uuid, const std::string& extraParams, CheckUpdateDelegate* delegate)
 {
-  m_impl->checkNewVersion(uuid, extraParams, delegate);
+  return m_impl->checkNewVersion(uuid, extraParams, delegate);
 }
 
 } // namespace updater
diff --git a/src/updater/check_update.h b/src/updater/check_update.h
index 20146b9..0253bc0 100644
--- a/src/updater/check_update.h
+++ b/src/updater/check_update.h
@@ -80,7 +80,7 @@ namespace updater {
 
     // Sends a request to the "updates server" and calls the delegate
     // when the response is received.
-    void checkNewVersion(const Uuid& uuid, const std::string& extraParams, CheckUpdateDelegate* delegate);
+    bool checkNewVersion(const Uuid& uuid, const std::string& extraParams, CheckUpdateDelegate* delegate);
 
   private:
     class CheckUpdateImpl;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git



More information about the Pkg-games-commits mailing list