summaryrefslogtreecommitdiffstats
path: root/Source/cmcmd.cxx
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@qt.io>2016-09-09 08:01:44 (GMT)
committerBrad King <brad.king@kitware.com>2016-09-22 12:06:38 (GMT)
commit1d601c6cb978a3b6b6143fdf64e284fb3a098d1e (patch)
tree1f274c04ba934cbc06cff9b8f9d33b7defbc7212 /Source/cmcmd.cxx
parent2c2ffd3874f749979d723d7a788d45e3830952d6 (diff)
downloadCMake-1d601c6cb978a3b6b6143fdf64e284fb3a098d1e.zip
CMake-1d601c6cb978a3b6b6143fdf64e284fb3a098d1e.tar.gz
CMake-1d601c6cb978a3b6b6143fdf64e284fb3a098d1e.tar.bz2
server-mode: Introduce cmServerConnection
Use it to split pipe and stdin/out handling out of cmServer itself. The server will shut down when it looses its connection to the client. This has the nice property that a crashing client will cause the server to terminate as the OS will close the connection on behave of the client.
Diffstat (limited to 'Source/cmcmd.cxx')
-rw-r--r--Source/cmcmd.cxx42
1 files changed, 30 insertions, 12 deletions
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index 38f00e6..9daed4b 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -25,6 +25,7 @@
#if defined(HAVE_SERVER_MODE) && HAVE_SERVER_MODE
#include "cmServer.h"
+#include "cmServerConnection.h"
#endif
#if defined(CMAKE_BUILD_WITH_CMAKE)
@@ -913,32 +914,49 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
}
return 0;
} else if (args[1] == "server") {
- if (args.size() > 3) {
- cmSystemTools::Error("Too many arguments to start server mode");
- return 1;
- }
+ const std::string pipePrefix = "--pipe=";
bool supportExperimental = false;
- if (args.size() == 3) {
- if (args[2] == "--experimental") {
+ bool isDebug = false;
+ std::string pipe;
+
+ for (size_t i = 2; i < args.size(); ++i) {
+ const std::string& a = args[i];
+
+ if (a == "--experimental") {
supportExperimental = true;
+ } else if (a == "--debug") {
+ pipe.clear();
+ isDebug = true;
+ } else if (a.substr(0, pipePrefix.size()) == pipePrefix) {
+ isDebug = false;
+ pipe = a.substr(pipePrefix.size());
+ if (pipe.empty()) {
+ cmSystemTools::Error("No pipe given after --pipe=");
+ return 2;
+ }
} else {
cmSystemTools::Error("Unknown argument for server mode");
return 1;
}
}
#if defined(HAVE_SERVER_MODE) && HAVE_SERVER_MODE
- cmServer server(supportExperimental);
- if (server.Serve()) {
+ cmServerConnection* conn;
+ if (isDebug) {
+ conn = new cmServerStdIoConnection;
+ } else {
+ conn = new cmServerPipeConnection(pipe);
+ }
+ cmServer server(conn, supportExperimental);
+ std::string errorMessage;
+ if (server.Serve(&errorMessage)) {
return 0;
} else {
- cmSystemTools::Error(
- "CMake server could not find any supported protocol. "
- "Try with \"--experimental\" to enable "
- "experimental support.");
+ cmSystemTools::Error(errorMessage.c_str());
return 1;
}
#else
static_cast<void>(supportExperimental);
+ static_cast<void>(isDebug);
cmSystemTools::Error("CMake was not built with server mode enabled");
return 1;
#endif