From 3f9b6d632eb263f13ca1c2e4beae833f9eab3a0a Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 22 Mar 2016 21:13:22 +0000 Subject: [PATCH] HTTP/curl - transfer byte metric work Should fix the missing download rate feedback on the splash screen and terra sync dialog. --- simgear/io/HTTPClient.cxx | 9 ++++++++- simgear/io/HTTPRequest.cxx | 1 + simgear/io/HTTPRequest.hxx | 7 +++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/simgear/io/HTTPClient.cxx b/simgear/io/HTTPClient.cxx index d42519d8..5ec7386b 100644 --- a/simgear/io/HTTPClient.cxx +++ b/simgear/io/HTTPClient.cxx @@ -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(userdata); req->processBodyBytes(ptr, byteSize); + + Client* cl = req->http(); + if (cl) { + cl->receivedBytes(byteSize); + } + return byteSize; } diff --git a/simgear/io/HTTPRequest.cxx b/simgear/io/HTTPRequest.cxx index c9d82d29..63bae965 100644 --- a/simgear/io/HTTPRequest.cxx +++ b/simgear/io/HTTPRequest.cxx @@ -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), diff --git a/simgear/io/HTTPRequest.hxx b/simgear/io/HTTPRequest.hxx index cc7ffd28..7c06fc8e 100644 --- a/simgear/io/HTTPRequest.hxx +++ b/simgear/io/HTTPRequest.hxx @@ -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; -- 2.39.5