diff --git a/lib/shared_memory.cpp b/lib/shared_memory.cpp index d0041fd5..d0e61ec5 100644 --- a/lib/shared_memory.cpp +++ b/lib/shared_memory.cpp @@ -22,6 +22,11 @@ #endif +/// Forces a disconnect to all users. +static void killStatistics(char * data, size_t len, unsigned int id){ + (*(data - 1)) = 126;//Send disconnect message; +} + namespace IPC { #if defined(__CYGWIN__) || defined(_WIN32) @@ -776,7 +781,6 @@ namespace IPC { ///\brief The deconstructor sharedServer::~sharedServer() { - finishEach(); mySemaphore.close(); mySemaphore.unlink(); } @@ -833,21 +837,16 @@ namespace IPC { return false; } - ///Disconnect all connected users + ///Disconnect all connected users, waits at most 2.5 seconds until completed void sharedServer::finishEach(){ if (!hasCounter){ return; } - for (std::set::iterator it = myPages.begin(); it != myPages.end(); it++) { - if (!it->mapped || !it->len) { - break; - } - unsigned int offset = 0; - while (offset + payLen + (hasCounter ? 1 : 0) <= it->len) { - it->mapped[offset] = 126; - offset += payLen + (hasCounter ? 1 : 0); - } - } + unsigned int c = 0;//to prevent eternal loops + do{ + parseEach(killStatistics); + Util::wait(250); + }while(amount && c++ < 10); } ///Returns a pointer to the data for the given index. diff --git a/lib/shared_memory.h b/lib/shared_memory.h index bc8906f2..920ca1b8 100644 --- a/lib/shared_memory.h +++ b/lib/shared_memory.h @@ -186,6 +186,7 @@ namespace IPC { ///\brief The amount of connected clients unsigned int amount; unsigned int connectedUsers; + void finishEach(); private: bool isInUse(unsigned int id); void newPage(); @@ -200,7 +201,6 @@ namespace IPC { semaphore mySemaphore; ///\brief Whether the payload has a counter, if so, it is added in front of the payload bool hasCounter; - void finishEach(); }; ///\brief The client part of a server/client model for shared memory. diff --git a/src/input/input_buffer.cpp b/src/input/input_buffer.cpp index e16b7b0d..76095fb2 100644 --- a/src/input/input_buffer.cpp +++ b/src/input/input_buffer.cpp @@ -396,6 +396,7 @@ namespace Mist { } else if (everHadPush && !resumeMode && config->is_active) { INFO_MSG("Shutting down buffer because resume mode is disabled and the source disconnected"); config->is_active = false; + userPage.finishEach(); } }