HTTP/curl - transfer byte metric work

Should fix the missing download rate feedback on the splash screen
and terra sync dialog.
This commit is contained in:
James Turner
2016-03-22 21:13:22 +00:00
parent 714a6ac47d
commit 3f9b6d632e
3 changed files with 16 additions and 1 deletions
+8 -1
View File
@@ -876,6 +876,8 @@ void Client::makeRequest(const Request_ptr& r)
return; return;
} }
r->_client = this;
#if defined(ENABLE_CURL) #if defined(ENABLE_CURL)
CURL* curlRequest = curl_easy_init(); CURL* curlRequest = curl_easy_init();
curl_easy_setopt(curlRequest, CURLOPT_URL, r->url().c_str()); 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 Client::requestWriteCallback(char *ptr, size_t size, size_t nmemb, void *userdata)
{ {
size_t byteSize = size * nmemb; size_t byteSize = size * nmemb;
Request* req = static_cast<Request*>(userdata); Request* req = static_cast<Request*>(userdata);
req->processBodyBytes(ptr, byteSize); req->processBodyBytes(ptr, byteSize);
Client* cl = req->http();
if (cl) {
cl->receivedBytes(byteSize);
}
return byteSize; return byteSize;
} }
+1
View File
@@ -32,6 +32,7 @@ extern const int DEFAULT_HTTP_PORT;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
Request::Request(const std::string& url, const std::string method): Request::Request(const std::string& url, const std::string method):
_client(0),
_method(method), _method(method),
_url(url), _url(url),
_responseVersion(HTTP_VERSION_UNKNOWN), _responseVersion(HTTP_VERSION_UNKNOWN),
+7
View File
@@ -37,6 +37,8 @@ namespace simgear
namespace HTTP namespace HTTP
{ {
class Client;
/** /**
* Base class for HTTP request (and answer). * Base class for HTTP request (and answer).
*/ */
@@ -131,6 +133,9 @@ public:
virtual std::string url() const virtual std::string url() const
{ return _url; } { return _url; }
Client* http() const
{ return _client; }
virtual std::string scheme() const; virtual std::string scheme() const;
virtual std::string path() const; virtual std::string path() const;
virtual std::string host() const; virtual std::string host() const;
@@ -241,6 +246,8 @@ private:
void processBodyBytes(const char* s, int n); void processBodyBytes(const char* s, int n);
void setReadyState(ReadyState state); void setReadyState(ReadyState state);
Client* _client; // HTTP client we're active on
std::string _method; std::string _method;
std::string _url; std::string _url;
StringMap _request_headers; StringMap _request_headers;