From b8a5196a89a5e7c298f962c8965e9778b69493ce Mon Sep 17 00:00:00 2001 From: Thulinma Date: Thu, 23 Oct 2014 15:13:16 +0200 Subject: [PATCH] Added CRC field to statistics class. --- lib/shared_memory.cpp | 17 +++++++++++++++++ lib/shared_memory.h | 7 ++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/shared_memory.cpp b/lib/shared_memory.cpp index d8a7cea6..85dd0d16 100644 --- a/lib/shared_memory.cpp +++ b/lib/shared_memory.cpp @@ -39,6 +39,11 @@ namespace IPC { val = ((long)p[0] << 24) | ((long)p[1] << 16) | ((long)p[2] << 8) | p[3]; } + /// Reads a long value of p in host order to val. + static void btohl(char * p, unsigned int & val) { + val = ((long)p[0] << 24) | ((long)p[1] << 16) | ((long)p[2] << 8) | p[3]; + } + /// Reads a long long value of p in host order to val. static void btohll(char * p, long long & val) { val = ((long long)p[0] << 56) | ((long long)p[1] << 48) | ((long long)p[2] << 40) | ((long long)p[3] << 32) | ((long long)p[4] << 24) | ((long long)p[5] << 16) | ((long long)p[6] << 8) | p[7]; @@ -577,6 +582,18 @@ namespace IPC { return std::string(data + 68, std::min((int)strlen(data + 68), 20)); } + ///\brief Sets checksum field + void statExchange::crc(unsigned int sum) { + htobl(data + 88, sum); + } + + ///\brief Gets checksum field + unsigned int statExchange::crc() { + unsigned int result; + btohl(data + 88, result); + return result; + } + ///\brief Creates a semaphore guard, locks the semaphore on call semGuard::semGuard(semaphore * thisSemaphore) : mySemaphore(thisSemaphore) { mySemaphore->wait(); diff --git a/lib/shared_memory.h b/lib/shared_memory.h index 87cb4f08..2c58f4d7 100644 --- a/lib/shared_memory.h +++ b/lib/shared_memory.h @@ -10,6 +10,8 @@ #include #endif +#define STAT_EX_SIZE 92 + namespace IPC { ///\brief A class used for the exchange of statistics over shared memory. @@ -32,7 +34,9 @@ namespace IPC { std::string streamName(); void connector(std::string name); std::string connector(); - private: + void crc(unsigned int sum); + unsigned int crc(); + private: ///\brief The payload for the stat exchange /// - 8 byte - now (timestamp of last statistics) /// - 4 byte - time (duration of the current connection) @@ -42,6 +46,7 @@ namespace IPC { /// - 16 byte - host (ip address of the peer) /// - 20 byte - streamName (name of the stream peer is viewing) /// - 20 byte - connector (name of the connector the peer is using) + /// - 4 byte - CRC32 of user agent (or zero if none) char * data; };