From be49f880b8d4a65e439590322855fbd402756206 Mon Sep 17 00:00:00 2001 From: James Turner Date: Fri, 5 Feb 2021 10:37:07 +0000 Subject: [PATCH] Fix HTTPClient reset() behaviour MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ensure all data members are correctly re-initialzied when doing a reset. This shoed up as negative ‘bytes downloaded’ counts after a TerraSync abandon and retry. --- simgear/io/HTTPClient.cxx | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/simgear/io/HTTPClient.cxx b/simgear/io/HTTPClient.cxx index 7611dd4d..1c94ccfb 100644 --- a/simgear/io/HTTPClient.cxx +++ b/simgear/io/HTTPClient.cxx @@ -81,21 +81,8 @@ void Client::ClientPrivate::createCurlMulti() { #endif } -Client::Client() : - d(new ClientPrivate) +Client::Client() { - d->proxyPort = 0; - d->maxConnections = 4; - d->maxHostConnections = 4; - d->bytesTransferred = 0; - d->lastTransferRate = 0; - d->timeTransferSample.stamp(); - d->totalBytesDownloaded = 0; - d->maxPipelineDepth = 5; - setUserAgent("SimGear-" SG_STRINGIZE(SIMGEAR_VERSION)); - - d->tlsCertificatePath = SGPath::fromEnv("SIMGEAR_TLS_CERT_PATH"); - static bool didInitCurlGlobal = false; static std::mutex initMutex; @@ -105,7 +92,7 @@ Client::Client() : didInitCurlGlobal = true; } - d->createCurlMulti(); + reset(); } Client::~Client() @@ -139,8 +126,21 @@ void Client::setMaxPipelineDepth(unsigned int depth) void Client::reset() { - curl_multi_cleanup(d->curlMulti); + if (d.get()) { + curl_multi_cleanup(d->curlMulti); + } + d.reset(new ClientPrivate); + + d->proxyPort = 0; + d->maxConnections = 4; + d->maxHostConnections = 4; + d->bytesTransferred = 0; + d->lastTransferRate = 0; + d->timeTransferSample.stamp(); + d->totalBytesDownloaded = 0; + d->maxPipelineDepth = 5; + setUserAgent("SimGear-" SG_STRINGIZE(SIMGEAR_VERSION)); d->tlsCertificatePath = SGPath::fromEnv("SIMGEAR_TLS_CERT_PATH"); d->createCurlMulti(); }