Fixed stats issue for quick switching connections.
This commit is contained in:
parent
497a89588d
commit
8f6d75e51e
3 changed files with 12 additions and 5 deletions
|
@ -905,7 +905,7 @@ namespace IPC {
|
||||||
}
|
}
|
||||||
|
|
||||||
///\brief Parse each of the possible payload pieces, and runs a callback on it if in use.
|
///\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;
|
char * empty = 0;
|
||||||
if (!hasCounter) {
|
if (!hasCounter) {
|
||||||
empty = (char *)malloc(payLen * sizeof(char));
|
empty = (char *)malloc(payLen * sizeof(char));
|
||||||
|
@ -944,7 +944,7 @@ namespace IPC {
|
||||||
WARN_MSG("process disappeared, timing out. (pid %lu)", tmpPID);
|
WARN_MSG("process disappeared, timing out. (pid %lu)", tmpPID);
|
||||||
*counter = 125 | (0x80 & (*counter)); //if process is already dead, instant timeout.
|
*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) {
|
switch (countNum) {
|
||||||
case 127:
|
case 127:
|
||||||
HIGH_MSG("Client %u requested disconnect", id);
|
HIGH_MSG("Client %u requested disconnect", id);
|
||||||
|
@ -982,6 +982,9 @@ namespace IPC {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (countNum == 127 || countNum == 126){
|
if (countNum == 127 || countNum == 126){
|
||||||
|
if (disconCallback){
|
||||||
|
disconCallback(it->mapped + offset + 1, payLen, id);
|
||||||
|
}
|
||||||
memset(it->mapped + offset + 1, 0, payLen);
|
memset(it->mapped + offset + 1, 0, payLen);
|
||||||
it->mapped[offset] = 0;
|
it->mapped[offset] = 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1008,7 +1011,7 @@ namespace IPC {
|
||||||
amount = id + 1;
|
amount = id + 1;
|
||||||
VERYHIGH_MSG("Shared memory %s is now at count %u", baseName.c_str(), amount);
|
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 {
|
} else {
|
||||||
//stop if we're past the amount counted and we're empty
|
//stop if we're past the amount counted and we're empty
|
||||||
if (id >= amount) {
|
if (id >= amount) {
|
||||||
|
|
|
@ -181,7 +181,7 @@ namespace IPC {
|
||||||
sharedServer(std::string name, int len, bool withCounter = false);
|
sharedServer(std::string name, int len, bool withCounter = false);
|
||||||
void init(std::string name, int len, bool withCounter = false);
|
void init(std::string name, int len, bool withCounter = false);
|
||||||
~sharedServer();
|
~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);
|
char * getIndex(unsigned int id);
|
||||||
operator bool() const;
|
operator bool() const;
|
||||||
///\brief The amount of connected clients
|
///\brief The amount of connected clients
|
||||||
|
|
|
@ -455,14 +455,18 @@ void Controller::parseStatistics(char * data, size_t len, unsigned int id){
|
||||||
sessions.erase(connToSession[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
|
//store the index for later comparison
|
||||||
connToSession[id] = idx;
|
connToSession[id] = idx;
|
||||||
//update the session with the latest data
|
//update the session with the latest data
|
||||||
sessions[idx].update(id, tmpEx);
|
sessions[idx].update(id, tmpEx);
|
||||||
//check validity of stats data
|
//check validity of stats data
|
||||||
char counter = (*(data - 1));
|
char counter = (*(data - 1)) & 0x7F;
|
||||||
if (counter == 126 || counter == 127){
|
if (counter == 126 || counter == 127){
|
||||||
//the data is no longer valid - connection has gone away, store for later
|
//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);
|
sessions[idx].finish(id);
|
||||||
connToSession.erase(id);
|
connToSession.erase(id);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue