StatsValue - define operator+=
while this is a little bit more code, it seems much better for the accumulation operation to be next to the struct definition itself (in case we ever add more fields) Test: TreeHugger Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I26022db4566e69c964298d7b3f2cc4fa4a9a5152
This commit is contained in:
parent
4bcac5dadf
commit
a693bac180
2 changed files with 11 additions and 4 deletions
|
|
@ -55,6 +55,16 @@ typedef struct {
|
|||
} StatsValue;
|
||||
STRUCT_SIZE(StatsValue, 4 * 8); // 32
|
||||
|
||||
#ifdef __cplusplus
|
||||
static inline StatsValue& operator+=(StatsValue& lhs, const StatsValue& rhs) {
|
||||
lhs.rxPackets += rhs.rxPackets;
|
||||
lhs.rxBytes += rhs.rxBytes;
|
||||
lhs.txPackets += rhs.txPackets;
|
||||
lhs.txBytes += rhs.txBytes;
|
||||
return lhs;
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
char name[IFNAMSIZ];
|
||||
} IfaceValue;
|
||||
|
|
|
|||
|
|
@ -75,10 +75,7 @@ int bpfGetIfaceStatsInternal(const char* iface, StatsValue* stats,
|
|||
if (!statsEntry.ok()) {
|
||||
return statsEntry.error();
|
||||
}
|
||||
stats->rxPackets += statsEntry.value().rxPackets;
|
||||
stats->txPackets += statsEntry.value().txPackets;
|
||||
stats->rxBytes += statsEntry.value().rxBytes;
|
||||
stats->txBytes += statsEntry.value().txBytes;
|
||||
*stats += statsEntry.value();
|
||||
}
|
||||
return Result<void>();
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue