summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/datasource/networkspeed.cpp24
-rw-r--r--src/datasource/networkspeed.h2
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_ */