summaryrefslogtreecommitdiffstats
path: root/NetworkIOMeter.c
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-10-20 21:40:51 +0200
committercgzones <cgzones@googlemail.com>2020-10-26 19:17:14 +0100
commitf757810f489b12d2a98dcb09751003f4ed002538 (patch)
tree4558520309803981d20d8c0aa6ab100211d9bd48 /NetworkIOMeter.c
parent167adc0a2b4a940cae6c9eb71f3185b5d2d3b4fa (diff)
Improve handling of no data in Disk and Network IO Meters
Diffstat (limited to 'NetworkIOMeter.c')
-rw-r--r--NetworkIOMeter.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/NetworkIOMeter.c b/NetworkIOMeter.c
index 44792c15..51d8d5ca 100644
--- a/NetworkIOMeter.c
+++ b/NetworkIOMeter.c
@@ -16,6 +16,7 @@ static const int NetworkIOMeter_attributes[] = {
METER_VALUE_IOWRITE,
};
+static bool hasData = false;
static unsigned long int cached_rxb_diff = 0;
static unsigned long int cached_rxp_diff = 0;
static unsigned long int cached_txb_diff = 0;
@@ -35,9 +36,15 @@ static void NetworkIOMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, i
/* update only every 500ms */
if (passedTimeInMs > 500) {
+ cached_last_update = timeInMilliSeconds;
+
unsigned long int bytesReceived, packetsReceived, bytesTransmitted, packetsTransmitted;
- Platform_getNetworkIO(&bytesReceived, &packetsReceived, &bytesTransmitted, &packetsTransmitted);
+ hasData = Platform_getNetworkIO(&bytesReceived, &packetsReceived, &bytesTransmitted, &packetsTransmitted);
+ if (!hasData) {
+ xSnprintf(buffer, len, "no data");
+ return;
+ }
cached_rxb_diff = (bytesReceived - cached_rxb_total) / 1024; /* Meter_humanUnit() expects unit in kilo */
cached_rxb_diff = 1000.0 * cached_rxb_diff / passedTimeInMs; /* convert to per second */
@@ -52,8 +59,6 @@ static void NetworkIOMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, i
cached_txp_diff = packetsTransmitted - cached_txp_total;
cached_txp_total = packetsTransmitted;
-
- cached_last_update = timeInMilliSeconds;
}
char bufferBytesReceived[12], bufferBytesTransmitted[12];
@@ -63,6 +68,11 @@ static void NetworkIOMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, i
}
static void NetworkIOMeter_display(ATTR_UNUSED const Object* cast, RichString* out) {
+ if (!hasData) {
+ RichString_write(out, CRT_colors[METER_VALUE_ERROR], "no data");
+ return;
+ }
+
char buffer[64];
RichString_write(out, CRT_colors[METER_TEXT], "rx: ");

© 2014-2024 Faster IT GmbH | imprint | privacy policy