Made sharedServer::finishEach explicit

This commit is contained in:
Thulinma 2016-09-06 11:53:40 +02:00
parent 357eb4e722
commit a4f35ca11e
3 changed files with 13 additions and 13 deletions

View file

@ -22,6 +22,11 @@
#endif #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 { namespace IPC {
#if defined(__CYGWIN__) || defined(_WIN32) #if defined(__CYGWIN__) || defined(_WIN32)
@ -776,7 +781,6 @@ namespace IPC {
///\brief The deconstructor ///\brief The deconstructor
sharedServer::~sharedServer() { sharedServer::~sharedServer() {
finishEach();
mySemaphore.close(); mySemaphore.close();
mySemaphore.unlink(); mySemaphore.unlink();
} }
@ -833,21 +837,16 @@ namespace IPC {
return false; return false;
} }
///Disconnect all connected users ///Disconnect all connected users, waits at most 2.5 seconds until completed
void sharedServer::finishEach(){ void sharedServer::finishEach(){
if (!hasCounter){ if (!hasCounter){
return; return;
} }
for (std::set<sharedPage>::iterator it = myPages.begin(); it != myPages.end(); it++) { unsigned int c = 0;//to prevent eternal loops
if (!it->mapped || !it->len) { do{
break; parseEach(killStatistics);
} Util::wait(250);
unsigned int offset = 0; }while(amount && c++ < 10);
while (offset + payLen + (hasCounter ? 1 : 0) <= it->len) {
it->mapped[offset] = 126;
offset += payLen + (hasCounter ? 1 : 0);
}
}
} }
///Returns a pointer to the data for the given index. ///Returns a pointer to the data for the given index.

View file

@ -186,6 +186,7 @@ namespace IPC {
///\brief The amount of connected clients ///\brief The amount of connected clients
unsigned int amount; unsigned int amount;
unsigned int connectedUsers; unsigned int connectedUsers;
void finishEach();
private: private:
bool isInUse(unsigned int id); bool isInUse(unsigned int id);
void newPage(); void newPage();
@ -200,7 +201,6 @@ namespace IPC {
semaphore mySemaphore; semaphore mySemaphore;
///\brief Whether the payload has a counter, if so, it is added in front of the payload ///\brief Whether the payload has a counter, if so, it is added in front of the payload
bool hasCounter; bool hasCounter;
void finishEach();
}; };
///\brief The client part of a server/client model for shared memory. ///\brief The client part of a server/client model for shared memory.

View file

@ -396,6 +396,7 @@ namespace Mist {
} else if (everHadPush && !resumeMode && config->is_active) { } else if (everHadPush && !resumeMode && config->is_active) {
INFO_MSG("Shutting down buffer because resume mode is disabled and the source disconnected"); INFO_MSG("Shutting down buffer because resume mode is disabled and the source disconnected");
config->is_active = false; config->is_active = false;
userPage.finishEach();
} }
} }