diff --git a/lib/shared_memory.cpp b/lib/shared_memory.cpp index 554715c7..b889ca2f 100644 --- a/lib/shared_memory.cpp +++ b/lib/shared_memory.cpp @@ -905,7 +905,7 @@ namespace IPC { } ///\brief Parse each of the possible payload pieces, and runs a callback on it if in use. - void sharedServer::parseEach(void (*callback)(char * data, size_t len, unsigned int id)) { + void sharedServer::parseEach(void (*activeCallback)(char * data, size_t len, unsigned int id), void (*disconCallback)(char * data, size_t len, unsigned int id)) { char * empty = 0; if (!hasCounter) { empty = (char *)malloc(payLen * sizeof(char)); @@ -944,7 +944,7 @@ namespace IPC { WARN_MSG("process disappeared, timing out. (pid %lu)", tmpPID); *counter = 125 | (0x80 & (*counter)); //if process is already dead, instant timeout. } - callback(it->mapped + offset + 1, payLen, id); + activeCallback(it->mapped + offset + 1, payLen, id); switch (countNum) { case 127: HIGH_MSG("Client %u requested disconnect", id); @@ -982,6 +982,9 @@ namespace IPC { break; } if (countNum == 127 || countNum == 126){ + if (disconCallback){ + disconCallback(it->mapped + offset + 1, payLen, id); + } memset(it->mapped + offset + 1, 0, payLen); it->mapped[offset] = 0; } else { @@ -1008,7 +1011,7 @@ namespace IPC { amount = id + 1; VERYHIGH_MSG("Shared memory %s is now at count %u", baseName.c_str(), amount); } - callback(it->mapped + offset, payLen, id); + activeCallback(it->mapped + offset, payLen, id); } else { //stop if we're past the amount counted and we're empty if (id >= amount) { diff --git a/lib/shared_memory.h b/lib/shared_memory.h index 21d0ed39..1b665b78 100644 --- a/lib/shared_memory.h +++ b/lib/shared_memory.h @@ -181,7 +181,7 @@ namespace IPC { sharedServer(std::string name, int len, bool withCounter = false); void init(std::string name, int len, bool withCounter = false); ~sharedServer(); - void parseEach(void (*callback)(char * data, size_t len, unsigned int id)); + void parseEach(void (*activeCallback)(char * data, size_t len, unsigned int id), void (*disconCallback)(char * data, size_t len, unsigned int id) = 0); char * getIndex(unsigned int id); operator bool() const; ///\brief The amount of connected clients diff --git a/src/controller/controller_statistics.cpp b/src/controller/controller_statistics.cpp index 37603358..f16e19bc 100644 --- a/src/controller/controller_statistics.cpp +++ b/src/controller/controller_statistics.cpp @@ -455,14 +455,18 @@ void Controller::parseStatistics(char * data, size_t len, unsigned int id){ sessions.erase(connToSession[id]); } } + if (!connToSession.count(id)){ + INSANE_MSG("New connection: %lu as %s", id, idx.toStr().c_str()); + } //store the index for later comparison connToSession[id] = idx; //update the session with the latest data sessions[idx].update(id, tmpEx); //check validity of stats data - char counter = (*(data - 1)); + char counter = (*(data - 1)) & 0x7F; if (counter == 126 || counter == 127){ //the data is no longer valid - connection has gone away, store for later + INSANE_MSG("Ended connection: %lu as %s", id, idx.toStr().c_str()); sessions[idx].finish(id); connToSession.erase(id); }