diff options
author | Nathan Scott <nathans@redhat.com> | 2021-03-02 12:14:44 +1100 |
---|---|---|
committer | Nathan Scott <nathans@redhat.com> | 2021-03-02 12:14:44 +1100 |
commit | 88a11859a0a26de3683f8459611c11ab6b2efb36 (patch) | |
tree | c22ed24ae300b12a83bf55f70be92cec478ca627 /NetworkIOMeter.c | |
parent | 2d1839289eca016893b898dc713cbf1a1df92fc1 (diff) |
Switch NetworkIO Meter to using uint32_t and uint64_t
From review via @BenBE, this is now a whole lot cleaner.
Diffstat (limited to 'NetworkIOMeter.c')
-rw-r--r-- | NetworkIOMeter.c | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/NetworkIOMeter.c b/NetworkIOMeter.c index cd1d46b0..47605cd3 100644 --- a/NetworkIOMeter.c +++ b/NetworkIOMeter.c @@ -19,26 +19,26 @@ static const int NetworkIOMeter_attributes[] = { static bool hasData = false; -static unsigned long int cached_rxb_diff; -static unsigned long int cached_rxp_diff; -static unsigned long int cached_txb_diff; -static unsigned long int cached_txp_diff; +static uint32_t cached_rxb_diff; +static uint32_t cached_rxp_diff; +static uint32_t cached_txb_diff; +static uint32_t cached_txp_diff; static void NetworkIOMeter_updateValues(Meter* this, char* buffer, size_t len) { - static unsigned long long int cached_last_update = 0; + static uint64_t cached_last_update = 0; struct timeval tv; gettimeofday(&tv, NULL); - unsigned long long int timeInMilliSeconds = (unsigned long long int)tv.tv_sec * 1000 + (unsigned long long int)tv.tv_usec / 1000; - unsigned long long int passedTimeInMs = timeInMilliSeconds - cached_last_update; + uint64_t timeInMilliSeconds = (uint64_t)tv.tv_sec * 1000 + (uint64_t)tv.tv_usec / 1000; + uint64_t passedTimeInMs = timeInMilliSeconds - cached_last_update; /* update only every 500ms */ if (passedTimeInMs > 500) { - static unsigned long long int cached_rxb_total; - static unsigned long long int cached_rxp_total; - static unsigned long long int cached_txb_total; - static unsigned long long int cached_txp_total; - unsigned long long diff; + static uint64_t cached_rxb_total; + static uint64_t cached_rxp_total; + static uint64_t cached_txb_total; + static uint64_t cached_txp_total; + uint64_t diff; cached_last_update = timeInMilliSeconds; @@ -53,17 +53,17 @@ static void NetworkIOMeter_updateValues(Meter* this, char* buffer, size_t len) { diff = data.bytesReceived - cached_rxb_total; diff /= ONE_K; /* Meter_humanUnit() expects unit in kilo */ diff = (1000 * diff) / passedTimeInMs; /* convert to per second */ - cached_rxb_diff = (unsigned long)diff; + cached_rxb_diff = (uint32_t)diff; } else { - cached_rxb_diff = 0UL; + cached_rxb_diff = 0; } cached_rxb_total = data.bytesReceived; if (data.packetsReceived > cached_rxp_total) { diff = data.packetsReceived - cached_rxp_total; - cached_rxp_diff = (unsigned long)diff; + cached_rxp_diff = (uint32_t)diff; } else { - cached_rxp_diff = 0UL; + cached_rxp_diff = 0; } cached_rxp_total = data.packetsReceived; @@ -71,17 +71,17 @@ static void NetworkIOMeter_updateValues(Meter* this, char* buffer, size_t len) { diff = data.bytesTransmitted - cached_txb_total; diff /= ONE_K; /* Meter_humanUnit() expects unit in kilo */ diff = (1000 * diff) / passedTimeInMs; /* convert to per second */ - cached_txb_diff = (unsigned long)diff; + cached_txb_diff = (uint32_t)diff; } else { - cached_txb_diff = 0UL; + cached_txb_diff = 0; } cached_txb_total = data.bytesTransmitted; if (data.packetsTransmitted > cached_txp_total) { diff = data.packetsTransmitted - cached_txp_total; - cached_txp_diff = (unsigned long)diff; + cached_txp_diff = (uint32_t)diff; } else { - cached_txp_diff = 0UL; + cached_txp_diff = 0; } cached_txp_total = data.packetsTransmitted; } @@ -116,7 +116,7 @@ static void NetworkIOMeter_display(ATTR_UNUSED const Object* cast, RichString* o RichString_appendAscii(out, CRT_colors[METER_VALUE_IOWRITE], buffer); RichString_appendAscii(out, CRT_colors[METER_VALUE_IOWRITE], "iB/s"); - xSnprintf(buffer, sizeof(buffer), " (%lu/%lu packets) ", cached_rxp_diff, cached_txp_diff); + xSnprintf(buffer, sizeof(buffer), " (%u/%u packets) ", cached_rxp_diff, cached_txp_diff); RichString_appendAscii(out, CRT_colors[METER_TEXT], buffer); } |