NetUsage: rename to NetIO

This commit is contained in:
李通洲
2023-09-27 00:05:37 +08:00
parent 3866f27448
commit 154657b455
26 changed files with 102 additions and 102 deletions
+1 -1
View File
@@ -130,7 +130,7 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
if (hHidFile && HidD_GetProductString(hHidFile, displayName, sizeof(wchar_t) * 126))
ffStrbufSetWS(&device->name, displayName);
else
ffStrbufSetF(&device->name, "Unknown gamepad %4X-%4X", rdi.hid.dwVendorId, rdi.hid.dwProductId);
ffStrbufSetF(&device->name, "Unknown gamepad %4X-%4X", (unsigned) rdi.hid.dwVendorId, (unsigned) rdi.hid.dwProductId);
}
}
@@ -1,26 +1,26 @@
#include "netusage.h"
#include "netio.h"
#include "common/time.h"
const char* ffNetUsageGetIoCounters(FFlist* result, FFNetUsageOptions* options);
const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options);
static FFlist ioCounters1;
static uint64_t time1;
void ffPrepareNetUsage(FFNetUsageOptions* options)
void ffPrepareNetIO(FFNetIOOptions* options)
{
ffListInit(&ioCounters1, sizeof(FFNetUsageIoCounters));
ffNetUsageGetIoCounters(&ioCounters1, options);
ffListInit(&ioCounters1, sizeof(FFNetIOResult));
ffNetIOGetIoCounters(&ioCounters1, options);
time1 = ffTimeGetNow();
}
const char* ffDetectNetUsage(FFlist* result, FFNetUsageOptions* options)
const char* ffDetectNetIO(FFlist* result, FFNetIOOptions* options)
{
const char* error = NULL;
if (time1 == 0)
{
ffListInit(&ioCounters1, sizeof(FFNetUsageIoCounters));
error = ffNetUsageGetIoCounters(&ioCounters1, options);
ffListInit(&ioCounters1, sizeof(FFNetIOResult));
error = ffNetIOGetIoCounters(&ioCounters1, options);
if (error)
return error;
time1 = ffTimeGetNow();
@@ -36,7 +36,7 @@ const char* ffDetectNetUsage(FFlist* result, FFNetUsageOptions* options)
time2 = ffTimeGetNow();
}
error = ffNetUsageGetIoCounters(result, options);
error = ffNetIOGetIoCounters(result, options);
if (error)
return error;
@@ -45,13 +45,13 @@ const char* ffDetectNetUsage(FFlist* result, FFNetUsageOptions* options)
for (uint32_t i = 0; i < result->length; ++i)
{
FFNetUsageIoCounters* icPrev = (FFNetUsageIoCounters*)ffListGet(&ioCounters1, i);
FFNetUsageIoCounters* icCurr = (FFNetUsageIoCounters*)ffListGet(result, i);
FFNetIOResult* icPrev = (FFNetIOResult*)ffListGet(&ioCounters1, i);
FFNetIOResult* icCurr = (FFNetIOResult*)ffListGet(result, i);
if (!ffStrbufEqual(&icPrev->name, &icCurr->name))
return "Network interface name changed";
static_assert(sizeof(FFNetUsageIoCounters) - offsetof(FFNetUsageIoCounters, txBytes) == sizeof(uint64_t) * 8, "Unexpected struct FFNetUsageIoCounters layout");
for (size_t off = offsetof(FFNetUsageIoCounters, txBytes); off < sizeof(FFNetUsageIoCounters); off += sizeof(uint64_t))
static_assert(sizeof(FFNetIOResult) - offsetof(FFNetIOResult, txBytes) == sizeof(uint64_t) * 8, "Unexpected struct FFNetIOResult layout");
for (size_t off = offsetof(FFNetIOResult, txBytes); off < sizeof(FFNetIOResult); off += sizeof(uint64_t))
{
uint64_t* prevValue = (uint64_t*) ((uint8_t*) icPrev + off);
uint64_t* currValue = (uint64_t*) ((uint8_t*) icCurr + off);
@@ -1,6 +1,6 @@
#include "fastfetch.h"
typedef struct FFNetUsageIoCounters
typedef struct FFNetIOResult
{
FFstrbuf name;
bool defaultRoute;
@@ -12,6 +12,6 @@ typedef struct FFNetUsageIoCounters
uint64_t txErrors;
uint64_t rxDrops;
uint64_t txDrops;
} FFNetUsageIoCounters;
} FFNetIOResult;
const char* ffDetectNetUsage(FFlist* result, FFNetUsageOptions* options);
const char* ffDetectNetIO(FFlist* result, FFNetIOOptions* options);
@@ -1,4 +1,4 @@
#include "netusage.h"
#include "netio.h"
#include "common/io/io.h"
#include "common/netif/netif.h"
@@ -12,7 +12,7 @@
#include <sys/sysctl.h>
#include <sys/socket.h>
const char* ffNetUsageGetIoCounters(FFlist* result, FFNetUsageOptions* options)
const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options)
{
size_t bufSize = 0;
if (sysctl((int[]) { CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST2, 0 }, 6, NULL, &bufSize, 0, 0) < 0)
@@ -43,8 +43,8 @@ const char* ffNetUsageGetIoCounters(FFlist* result, FFNetUsageOptions* options)
if (options->namePrefix.length && strncmp(sdl->sdl_data, options->namePrefix.chars, options->namePrefix.length) != 0)
continue;
FFNetUsageIoCounters* counters = (FFNetUsageIoCounters*) ffListAdd(result);
*counters = (FFNetUsageIoCounters) {
FFNetIOResult* counters = (FFNetIOResult*) ffListAdd(result);
*counters = (FFNetIOResult) {
.name = ffStrbufCreateNS(sdl->sdl_nlen, sdl->sdl_data),
.txBytes = ifm->ifm_data.ifi_obytes,
.rxBytes = ifm->ifm_data.ifi_ibytes,
@@ -1,4 +1,4 @@
#include "netusage.h"
#include "netio.h"
#include "common/io/io.h"
#include "common/netif/netif.h"
@@ -6,7 +6,7 @@
#include <net/if.h>
const char* ffNetUsageGetIoCounters(FFlist* result, FFNetUsageOptions* options)
const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options)
{
FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/sys/class/net");
if (!dirp) return "opendir(\"/sys/class/net\") == NULL";
@@ -33,7 +33,7 @@ const char* ffNetUsageGetIoCounters(FFlist* result, FFNetUsageOptions* options)
if(!ffReadFileBuffer(path.chars, &buffer) || !ffStrbufEqualS(&buffer, "up"))
continue;
FFNetUsageIoCounters* counters = (FFNetUsageIoCounters*) ffListAdd(result);
FFNetIOResult* counters = (FFNetIOResult*) ffListAdd(result);
ffStrbufInitS(&counters->name, entry->d_name);
counters->defaultRoute = isDefaultRoute;
@@ -1,4 +1,4 @@
#include "netusage.h"
#include "netio.h"
#include "common/netif/netif.h"
#include "util/mallocHelper.h"
@@ -7,7 +7,7 @@
#include <ws2tcpip.h>
#include <iphlpapi.h>
const char* ffNetUsageGetIoCounters(FFlist* result, FFNetUsageOptions* options)
const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options)
{
IP_ADAPTER_ADDRESSES* FF_AUTO_FREE adapter_addresses = NULL;
@@ -54,8 +54,8 @@ const char* ffNetUsageGetIoCounters(FFlist* result, FFNetUsageOptions* options)
MIB_IF_ROW2 ifRow = { .InterfaceIndex = adapter->IfIndex };
if (GetIfEntry2(&ifRow) == NO_ERROR)
{
FFNetUsageIoCounters* counters = (FFNetUsageIoCounters*) ffListAdd(result);
*counters = (FFNetUsageIoCounters) {
FFNetIOResult* counters = (FFNetIOResult*) ffListAdd(result);
*counters = (FFNetIOResult) {
.name = ffStrbufCreateS(name),
.txBytes = ifRow.OutOctets,
.rxBytes = ifRow.InOctets,