[Box Backup-commit] COMMIT r1434 - box/chris/general/lib/common

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Thu Mar 22 23:46:55 GMT 2007


Author: chris
Date: 2007-03-22 23:46:55 +0000 (Thu, 22 Mar 2007)
New Revision: 1434

Removed:
   box/chris/general/lib/common/ServerControl.h
Log:
Remove ServerControl.h, now in lib/server


Deleted: box/chris/general/lib/common/ServerControl.h
===================================================================
--- box/chris/general/lib/common/ServerControl.h	2007-03-22 23:45:24 UTC (rev 1433)
+++ box/chris/general/lib/common/ServerControl.h	2007-03-22 23:46:55 UTC (rev 1434)
@@ -1,177 +0,0 @@
-#ifndef SERVER_CONTROL_H
-#define SERVER_CONTROL_H
-
-#ifdef WIN32
-
-#include "WinNamedPipeStream.h"
-#include "IOStreamGetLine.h"
-#include "BoxPortsAndFiles.h"
-#include "Test.h"
-
-static bool SendCommands(const std::string& rCmd)
-{
-	WinNamedPipeStream connection;
-
-	try
-	{
-		connection.Connect(BOX_NAMED_PIPE_NAME);
-	}
-	catch(...)
-	{
-		printf("Failed to connect to daemon control socket.\n");
-		return false;
-	}
-
-	// For receiving data
-	IOStreamGetLine getLine(connection);
-	
-	// Wait for the configuration summary
-	std::string configSummary;
-	if(!getLine.GetLine(configSummary))
-	{
-		printf("Failed to receive configuration summary from daemon\n");
-		return false;
-	}
-
-	// Was the connection rejected by the server?
-	if(getLine.IsEOF())
-	{
-		printf("Server rejected the connection.\n");
-		return false;
-	}
-
-	// Decode it
-	int autoBackup, updateStoreInterval, minimumFileAge, maxUploadWait;
-	if(::sscanf(configSummary.c_str(), "bbackupd: %d %d %d %d", 
-			&autoBackup, &updateStoreInterval, 
-			&minimumFileAge, &maxUploadWait) != 4)
-	{
-		printf("Config summary didn't decode\n");
-		return false;
-	}
-
-	std::string cmds;
-	bool expectResponse;
-
-	if (rCmd != "")
-	{
-		cmds = rCmd;
-		cmds += "\nquit\n";
-		expectResponse = true;
-	}
-	else
-	{
-		cmds = "quit\n";
-		expectResponse = false;
-	}
-	
-	connection.Write(cmds.c_str(), cmds.size());
-	
-	// Read the response
-	std::string line;
-	bool statusOk = !expectResponse;
-
-	while (expectResponse && !getLine.IsEOF() && getLine.GetLine(line))
-	{
-		// Is this an OK or error line?
-		if (line == "ok")
-		{
-			statusOk = true;
-		}
-		else if (line == "error")
-		{
-			printf("ERROR (%s)\n", rCmd.c_str());
-			break;
-		}
-		else
-		{
-			printf("WARNING: Unexpected response to command '%s': "
-				"%s", rCmd.c_str(), line.c_str());
-		}
-	}
-	
-	return statusOk;
-}
-
-inline bool HUPServer(int pid)
-{
-	return SendCommands("reload");
-}
-
-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());
-		return false;
-	}
-
-	if (!TerminateProcess(hProcess, 1))
-	{
-		printf("Failed to terminate process %d: error %d\n",
-			pid, (int)GetLastError());
-		CloseHandle(hProcess);
-		return false;
-	}
-
-	CloseHandle(hProcess);
-	return true;
-}
-
-#else // !WIN32
-
-inline bool HUPServer(int pid)
-{
-	if(pid == 0) return false;
-	return ::kill(pid, SIGHUP) == 0;
-}
-
-inline bool KillServerInternal(int pid)
-{
-	if(pid == 0 || pid == -1) return false;
-	bool killed = (::kill(pid, SIGTERM) == 0);
-	TEST_THAT(killed);
-	return killed;
-}
-
-#endif // WIN32
-
-inline bool KillServer(int pid)
-{
-	if (!KillServerInternal(pid))
-	{
-		return false;
-	}
-
-	for (int i = 0; i < 30; i++)
-	{
-		if (!ServerIsAlive(pid)) break;
-		::sleep(1);
-		if (!ServerIsAlive(pid)) break;
-
-		if (i == 0) 
-		{
-			printf("waiting for server to die");
-		}
-
-		printf(".");
-		fflush(stdout);
-	}
-
-	if (!ServerIsAlive(pid))
-	{
-		printf("done.\n");
-	}
-	else
-	{
-		printf("failed!\n");
-	}
-
-	fflush(stdout);
-
-	return !ServerIsAlive(pid);
-}
-
-#endif // SERVER_CONTROL_H




More information about the Boxbackup-commit mailing list