From d0d848e0f55afd23dc98728a5c30130345f273a6 Mon Sep 17 00:00:00 2001 From: Paul Harrison Date: Sun, 9 Jun 2013 11:54:33 +0100 Subject: [PATCH] MythZMServer: add a QUIT command to cleanly quit the server If the server receives a QUIT message from a client it will now cleanly exit. This also fixes Coverity ID 1026713 Logically dead code. --- mythplugins/mythzoneminder/mythzmserver/main.cpp | 2 +- mythplugins/mythzoneminder/mythzmserver/zmserver.cpp | 9 +++++++-- mythplugins/mythzoneminder/mythzmserver/zmserver.h | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/mythplugins/mythzoneminder/mythzmserver/main.cpp b/mythplugins/mythzoneminder/mythzmserver/main.cpp index de91d376395..c83e42fa902 100644 --- a/mythplugins/mythzoneminder/mythzmserver/main.cpp +++ b/mythplugins/mythzoneminder/mythzmserver/main.cpp @@ -343,7 +343,7 @@ int main(int argc, char **argv) else { ZMServer *server = serverList[i]; - server->processRequest(buf, nbytes); + quit = server->processRequest(buf, nbytes); } } } diff --git a/mythplugins/mythzoneminder/mythzmserver/zmserver.cpp b/mythplugins/mythzoneminder/mythzmserver/zmserver.cpp index c6cbaecd6b5..0593d464458 100644 --- a/mythplugins/mythzoneminder/mythzmserver/zmserver.cpp +++ b/mythplugins/mythzoneminder/mythzmserver/zmserver.cpp @@ -286,7 +286,8 @@ void ZMServer::tokenize(const string &command, vector &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 @@ -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") @@ -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 diff --git a/mythplugins/mythzoneminder/mythzmserver/zmserver.h b/mythplugins/mythzoneminder/mythzmserver/zmserver.h index 7eb75ad0a9d..4c9a29e913d 100644 --- a/mythplugins/mythzoneminder/mythzmserver/zmserver.h +++ b/mythplugins/mythzoneminder/mythzmserver/zmserver.h @@ -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);