]> git.mxchange.org Git - simgear.git/commitdiff
HTTP/curl - transfer byte metric work
authorJames Turner <zakalawe@mac.com>
Tue, 22 Mar 2016 21:13:22 +0000 (21:13 +0000)
committerJames Turner <zakalawe@mac.com>
Tue, 22 Mar 2016 21:13:22 +0000 (21:13 +0000)
Should fix the missing download rate feedback on the splash screen
and terra sync dialog.

simgear/io/HTTPClient.cxx
simgear/io/HTTPRequest.cxx
simgear/io/HTTPRequest.hxx

index d42519d8b9af017c4b1f86da1ce46c934d490116..5ec7386b724aaf232fb59dd2d89adac48b4f522a 100644 (file)
@@ -876,6 +876,8 @@ void Client::makeRequest(const Request_ptr& r)
         return;
     }
 
+    r->_client = this;
+
 #if defined(ENABLE_CURL)
     CURL* curlRequest = curl_easy_init();
     curl_easy_setopt(curlRequest, CURLOPT_URL, r->url().c_str());
@@ -1136,9 +1138,14 @@ uint64_t Client::totalBytesDownloaded() const
 size_t Client::requestWriteCallback(char *ptr, size_t size, size_t nmemb, void *userdata)
 {
   size_t byteSize = size * nmemb;
-
   Request* req = static_cast<Request*>(userdata);
   req->processBodyBytes(ptr, byteSize);
+
+  Client* cl = req->http();
+  if (cl) {
+    cl->receivedBytes(byteSize);
+  }
+
   return byteSize;
 }
 
index c9d82d29bac131c320604cd3139ba8f40f0068a0..63bae9650a20bd4a3867814200731c53bceefa42 100644 (file)
@@ -32,6 +32,7 @@ extern const int DEFAULT_HTTP_PORT;
 
 //------------------------------------------------------------------------------
 Request::Request(const std::string& url, const std::string method):
+  _client(0),
   _method(method),
   _url(url),
   _responseVersion(HTTP_VERSION_UNKNOWN),
index cc7ffd28dcb2b713f9f9ad0f02b25788ce9109d7..7c06fc8e3bd0184e6a23263767114338aabc171b 100644 (file)
@@ -37,6 +37,8 @@ namespace simgear
 namespace HTTP
 {
 
+class Client;
+
 /**
  * Base class for HTTP request (and answer).
  */
@@ -131,6 +133,9 @@ public:
     virtual std::string url() const
         { return _url; }
 
+    Client* http() const
+    { return _client; }
+
     virtual std::string scheme() const;
     virtual std::string path() const;
     virtual std::string host() const;
@@ -241,6 +246,8 @@ private:
     void processBodyBytes(const char* s, int n);
     void setReadyState(ReadyState state);
 
+    Client*       _client; // HTTP client we're active on
+
     std::string   _method;
     std::string   _url;
     StringMap     _request_headers;