diff options
author | Simon Rettberg | 2022-06-20 16:02:07 +0200 |
---|---|---|
committer | Simon Rettberg | 2022-06-20 16:02:07 +0200 |
commit | ac88418638fc18144d9024702c62a6e4936ad81f (patch) | |
tree | 38a9b7ea8a60c82bdc0a37158a8cb09395997144 | |
parent | Qt4 -> Qt5 (diff) | |
download | speedcheck-ac88418638fc18144d9024702c62a6e4936ad81f.tar.gz speedcheck-ac88418638fc18144d9024702c62a6e4936ad81f.tar.xz speedcheck-ac88418638fc18144d9024702c62a6e4936ad81f.zip |
Was not working anymore since eth0 was renamed boot0 -.-
-rw-r--r-- | src/datasource/networkspeed.cpp | 24 | ||||
-rw-r--r-- | src/datasource/networkspeed.h | 2 |
2 files changed, 19 insertions, 7 deletions
diff --git a/src/datasource/networkspeed.cpp b/src/datasource/networkspeed.cpp index 8888fd4..451c97e 100644 --- a/src/datasource/networkspeed.cpp +++ b/src/datasource/networkspeed.cpp @@ -3,26 +3,38 @@ NetworkSpeed::NetworkSpeed() : _lastBytes(0), _lastMs(0), - _file("/sys/class/net/eth0/statistics/rx_bytes") + _file(nullptr) { - _timer.start(); + for (QString s : QStringList() + << "/sys/class/net/boot0/statistics/rx_bytes" + << "/sys/class/net/eth0/statistics/rx_bytes" + << "/sys/class/net/br0/statistics/rx_bytes") { + if (!QFile::exists(s)) + continue; + _file = new QFile(s); + } + if (_file != nullptr) { + _timer.start(); + } } NetworkSpeed::~NetworkSpeed() { - // TODO Auto-generated destructor stub + if (_file != nullptr) { + _file->deleteLater(); + } } qint64 NetworkSpeed::read() { char buffer[500]; qint64 ret, now; - if (!_file.open(QIODevice::ReadOnly)) { + if (_file == nullptr || !_file->open(QIODevice::ReadOnly)) { return -1; } now = _timer.elapsed(); - _file.readLine(buffer, sizeof(buffer)); - _file.close(); + _file->readLine(buffer, sizeof(buffer)); + _file->close(); QString line(buffer); const qint64 counter = (qint64)line.toLongLong(); if (_lastBytes == 0) { diff --git a/src/datasource/networkspeed.h b/src/datasource/networkspeed.h index 482f4cd..7b9d3ae 100644 --- a/src/datasource/networkspeed.h +++ b/src/datasource/networkspeed.h @@ -18,7 +18,7 @@ private: qint64 _lastBytes; qint64 _lastMs; QElapsedTimer _timer; - QFile _file; + QFile* _file; }; #endif /* NETWORKSPEED_H_ */ |