Skip to content

Commit

Permalink
MythZMServer: add a QUIT command to cleanly quit the server
Browse files Browse the repository at this point in the history
If the server receives a QUIT message from a client it will now cleanly
exit. This also fixes Coverity ID 1026713 Logically dead code.
  • Loading branch information
Paul Harrison committed Jun 9, 2013
1 parent cb53d4d commit d0d848e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion mythplugins/mythzoneminder/mythzmserver/main.cpp
Expand Up @@ -343,7 +343,7 @@ int main(int argc, char **argv)
else
{
ZMServer *server = serverList[i];
server->processRequest(buf, nbytes);
quit = server->processRequest(buf, nbytes);
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions mythplugins/mythzoneminder/mythzmserver/zmserver.cpp
Expand Up @@ -286,7 +286,8 @@ void ZMServer::tokenize(const string &command, vector<string> &tokens)
}
}

void ZMServer::processRequest(char* buf, int nbytes)
// returns true if we get a QUIT command from the client
bool ZMServer::processRequest(char* buf, int nbytes)
{
#if 0
// first 8 bytes is the length of the following data
Expand All @@ -302,13 +303,15 @@ void ZMServer::processRequest(char* buf, int nbytes)
tokenize(s, tokens);

if (tokens.empty())
return;
return false;

if (m_debug)
cout << "Processing: '" << tokens[0] << "'" << endl;

if (tokens[0] == "HELLO")
handleHello();
else if (tokens[0] == "QUIT")
return true;
else if (tokens[0] == "GET_SERVER_STATUS")
handleGetServerStatus();
else if (tokens[0] == "GET_MONITOR_STATUS")
Expand Down Expand Up @@ -339,6 +342,8 @@ void ZMServer::processRequest(char* buf, int nbytes)
handleSetMonitorFunction(tokens);
else
send("UNKNOWN_COMMAND");

return false;
}

bool ZMServer::send(const string s) const
Expand Down
2 changes: 1 addition & 1 deletion mythplugins/mythzoneminder/mythzmserver/zmserver.h
Expand Up @@ -152,7 +152,7 @@ class ZMServer
ZMServer(int sock, bool debug);
~ZMServer();

void processRequest(char* buf, int nbytes);
bool processRequest(char* buf, int nbytes);

private:
string getZMSetting(const string &setting);
Expand Down

0 comments on commit d0d848e

Please sign in to comment.