diff options
author | Chris Wilson <chris+github@qwirx.com> | 2007-10-17 12:49:18 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2007-10-17 12:49:18 +0000 |
commit | d23a3df00f15b0eff80781e6582cd315eb261b9b (patch) | |
tree | 24f1054f003cb28a254c5ba387a8a3ae4f0c6137 /lib/server/ServerControl.h | |
parent | e2190bee1c98a54b2fadac1817f8bc79974051d2 (diff) |
Added function to set the named pipe name, for use by any test which
calls HUPServer() or SendCommands(). (merges [1836])
Diffstat (limited to 'lib/server/ServerControl.h')
-rw-r--r-- | lib/server/ServerControl.h | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/lib/server/ServerControl.h b/lib/server/ServerControl.h index c51dd4e2..d5b92b56 100644 --- a/lib/server/ServerControl.h +++ b/lib/server/ServerControl.h @@ -9,17 +9,24 @@ #include "IOStreamGetLine.h" #include "BoxPortsAndFiles.h" +static std::string sPipeName; + +static void SetNamedPipeName(const std::string& rPipeName) +{ + sPipeName = rPipeName; +} + static bool SendCommands(const std::string& rCmd) { WinNamedPipeStream connection; try { - connection.Connect(BOX_NAMED_PIPE_NAME); + connection.Connect(sPipeName); } catch(...) { - printf("Failed to connect to daemon control socket.\n"); + BOX_ERROR("Failed to connect to daemon control socket"); return false; } @@ -30,14 +37,14 @@ static bool SendCommands(const std::string& rCmd) std::string configSummary; if(!getLine.GetLine(configSummary)) { - printf("Failed to receive configuration summary from daemon\n"); + BOX_ERROR("Failed to receive configuration summary from daemon"); return false; } // Was the connection rejected by the server? if(getLine.IsEOF()) { - printf("Server rejected the connection.\n"); + BOX_ERROR("Server rejected the connection"); return false; } @@ -47,7 +54,7 @@ static bool SendCommands(const std::string& rCmd) &autoBackup, &updateStoreInterval, &minimumFileAge, &maxUploadWait) != 4) { - printf("Config summary didn't decode\n"); + BOX_ERROR("Config summary didn't decode"); return false; } @@ -81,13 +88,13 @@ static bool SendCommands(const std::string& rCmd) } else if (line == "error") { - printf("ERROR (%s)\n", rCmd.c_str()); + BOX_ERROR(rCmd); break; } else { - printf("WARNING: Unexpected response to command '%s': " - "%s", rCmd.c_str(), line.c_str()); + BOX_WARNING("Unexpected response to command '" << + rCmd << "': " << line) } } @@ -104,15 +111,15 @@ inline bool KillServerInternal(int pid) HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, false, pid); if (hProcess == NULL) { - printf("Failed to open process %d: error %d\n", - pid, (int)GetLastError()); + BOX_ERROR("Failed to open process " << pid << ": " << + GetErrorMessage(GetLastError())); return false; } if (!TerminateProcess(hProcess, 1)) { - printf("Failed to terminate process %d: error %d\n", - pid, (int)GetLastError()); + BOX_ERROR("Failed to terminate process " << pid << ": " << + GetErrorMessage(GetLastError())); CloseHandle(hProcess); return false; } |