SGTimeStamp timeTransferSample;
unsigned int bytesTransferred;
unsigned int lastTransferRate;
+ uint64_t totalBytesDownloaded;
};
class Connection : public NetChat
d->bytesTransferred = 0;
d->lastTransferRate = 0;
d->timeTransferSample.stamp();
+ d->totalBytesDownloaded = 0;
setUserAgent("SimGear-" SG_STRINGIZE(SIMGEAR_VERSION));
}
void Client::receivedBytes(unsigned int count)
{
d->bytesTransferred += count;
+ d->totalBytesDownloaded += count;
}
unsigned int Client::transferRateBytesPerSec() const
return smoothed;
}
+uint64_t Client::totalBytesDownloaded() const
+{
+ return d->totalBytesDownloaded;
+}
+
} // of namespace HTTP
} // of namespace simgear
#define SG_HTTP_CLIENT_HXX
#include <memory> // for std::auto_ptr
+#include <stdint.h> // for uint_64t
#include <simgear/io/HTTPRequest.hxx>
* suitable for user feedback and rough profiling, nothing more.
*/
unsigned int transferRateBytesPerSec() const;
+
+ /**
+ * total bytes downloaded by this HTTP client, for bandwidth usage
+ * monitoring
+ */
+ uint64_t totalBytesDownloaded() const;
private:
void requestFinished(Connection* con);
volatile int _allowed_errors;
volatile int _cache_hits;
volatile int _transfer_rate;
+ // kbytes, not bytes, because bytes might overflow 2^31
+ volatile int _total_kb_downloaded;
+
private:
virtual void run();
_allowed_errors(6),
_cache_hits(0),
_transfer_rate(0),
+ _total_kb_downloaded(0),
_use_built_in(true),
_is_dirty(false),
_stop(false),
while (!_stop) {
_http.update(100);
_transfer_rate = _http.transferRateBytesPerSec();
+ // convert from bytes to kbytes
+ _total_kb_downloaded = static_cast<int>(_http.totalBytesDownloaded() / 1024);
+
if (_stop)
break;
_tiedProperties.Tie( _terraRoot->getNode("cache-hits", true), (int*) &_svnThread->_cache_hits );
_tiedProperties.Tie( _terraRoot->getNode("transfer-rate-bytes-sec", true), (int*) &_svnThread->_transfer_rate );
+ // use kbytes here because propety doesn't support 64-bit and we might conceivably
+ // download more than 2G in a single session
+ _tiedProperties.Tie( _terraRoot->getNode("downloaded-kbytes", true), (int*) &_svnThread->_total_kb_downloaded );
+
_terraRoot->getNode("busy", true)->setAttribute(SGPropertyNode::WRITE,false);
_terraRoot->getNode("active", true)->setAttribute(SGPropertyNode::WRITE,false);
_terraRoot->getNode("update-count", true)->setAttribute(SGPropertyNode::WRITE,false);