From 226ec6ccdbcbd9800091e1127bf41d1ddb5c1298 Mon Sep 17 00:00:00 2001 From: Jason Antman Date: Sat, 26 Aug 2017 08:08:47 -0400 Subject: [PATCH] issue #130 - have Process::gettotal include closed connections removed from ConnList --- src/process.cpp | 7 +++++-- src/process.h | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/process.cpp b/src/process.cpp index 86f8643..ee22680 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -102,6 +102,9 @@ void Process::getkbps(float *recvd, float *sent) { ConnList *previous = NULL; while (curconn != NULL) { if (curconn->getVal()->getLastPacket() <= curtime.tv_sec - CONNTIMEOUT) { + /* capture sent and received totals before deleting */ + this->sent_by_closed_bytes += curconn->getVal()->sumSent; + this->rcvd_by_closed_bytes += curconn->getVal()->sumRecv; /* stalled connection, remove. */ ConnList *todelete = curconn; Connection *conn_todelete = curconn->getVal(); @@ -137,8 +140,8 @@ void Process::gettotal(u_int32_t *recvd, u_int32_t *sent) { } // std::cout << "Sum sent: " << sum_sent << std::endl; // std::cout << "Sum recv: " << sum_recv << std::endl; - *recvd = sum_recv; - *sent = sum_sent; + *recvd = sum_recv + this->rcvd_by_closed_bytes; + *sent = sum_sent + this->sent_by_closed_bytes; } void Process::gettotalmb(float *recvd, float *sent) { diff --git a/src/process.h b/src/process.h index 598e439..f964e3f 100644 --- a/src/process.h +++ b/src/process.h @@ -78,6 +78,8 @@ public: connections = NULL; pid = 0; uid = 0; + sent_by_closed_bytes = 0; + rcvd_by_closed_bytes = 0; } void check() { assert(pid >= 0); } @@ -99,6 +101,8 @@ public: char *cmdline; const char *devicename; int pid; + u_int32_t sent_by_closed_bytes; + u_int32_t rcvd_by_closed_bytes; ConnList *connections; uid_t getUid() { return uid; }