[Boxbackup-dev] current trunk

Kai Liebenau Kai.Liebenau at gmx.net
Thu Oct 9 20:35:44 BST 2014


Hi Chris,

i have some bugs found in the svn-trunk tree. I missed the getopt.h
file, but in the browser trunk tree is it present.
Now then the WinNamedPipeStream.cpp file have some incorrect definition.
Here is the patch for them.

In the file Daemon.cpp is missing one include for Win32. I have added
this and now i can compile it.

For the ticket #69 "CRTL+C closes bbackupquery console window under
Windows", i have some modification.
The current handler ignore the Ctrl+C and Ctrl Colse Events. I don't
knowing were i can interrupt the current action.

Cheers Kai
-------------- next part --------------
Index: WinNamedPipeStream.cpp
===================================================================
--- WinNamedPipeStream.cpp	(revision 3412)
+++ WinNamedPipeStream.cpp	(working copy)
@@ -91,7 +91,7 @@
 				GetErrorMessage(err));
 			Close();
 			THROW_EXCEPTION(ConnectionException, 
-				Conn_SocketReadError)
+				SocketReadError)
 		}
 	}
 }
@@ -334,7 +334,7 @@
 
 					Close();
 					THROW_EXCEPTION(ConnectionException, 
-						Conn_SocketReadError)
+						SocketReadError)
 				}
 			}
 		}
@@ -394,7 +394,7 @@
 					<< GetErrorMessage(err));
 				Close();
 				THROW_EXCEPTION(ConnectionException, 
-					Conn_SocketReadError)
+					SocketReadError)
 			}
 		}
 	}
@@ -424,7 +424,7 @@
 				BOX_ERROR("Failed to read from control socket: "
 					<< GetErrorMessage(err));
 				THROW_EXCEPTION(ConnectionException, 
-					Conn_SocketReadError)
+					SocketReadError)
 			}
 		}
 		
@@ -486,7 +486,7 @@
 			Close();
 
 			THROW_EXCEPTION(ConnectionException, 
-				Conn_SocketWriteError)
+				SocketWriteError)
 		}
 
 		NumBytesWrittenTotal += NumBytesWrittenThisTime;
-------------- next part --------------
Index: Daemon.cpp
===================================================================
--- Daemon.cpp	(revision 3412)
+++ Daemon.cpp	(working copy)
@@ -24,6 +24,7 @@
 #endif
 
 #ifdef WIN32
+	#include <Strsafe.h>
 	#include <ws2tcpip.h>
 	#include <process.h>
 #endif
-------------- next part --------------
Index: bbackupquery.cpp
===================================================================
--- bbackupquery.cpp	(revision 3412)
+++ bbackupquery.cpp	(working copy)
@@ -181,6 +181,36 @@
 
 #endif // HAVE_LIBREADLINE
 
+#ifdef WIN32
+// Ticket #69, CRTL+C closes bbackupquery console window under Windows
+BOOL Win32CtrlHandler(DWORD dwCtrlType)
+{
+	BOOL isHandled = FALSE;
+
+	switch(dwCtrlType)
+	{
+		case CTRL_C_EVENT:	// interrupting the current action
+			BOX_INFO("Ctrl-C event");
+			isHandled = TRUE;
+			break;
+		case CTRL_BREAK_EVENT:	// interrupting the current action also?
+			BOX_INFO("Break event");
+			break;
+		case CTRL_CLOSE_EVENT:	// interrupting the current action ,logoff from store and exit process
+			BOX_INFO("Close event");
+			isHandled = TRUE;
+			break;
+		case CTRL_LOGOFF_EVENT:	// interrupting the current action ,logoff from store and exit process
+			BOX_INFO("Logoff event");
+			break;
+		case CTRL_SHUTDOWN_EVENT:	// interrupting the current action ,logoff from store and exit process
+			BOX_INFO("Shutdown event");
+			break;
+	}
+	return isHandled;
+}
+#endif
+
 int main(int argc, const char *argv[])
 {
 	int returnCode = 0;
@@ -407,6 +437,14 @@
 	BOX_INFO("Login complete.");
 	BOX_INFO("Type \"help\" for a list of commands.");
 	
+	// install the CtrlHandler to interrupt the running action
+#ifdef WIN32
+		if(SetConsoleCtrlHandler((PHANDLER_ROUTINE)Win32CtrlHandler,TRUE) != TRUE)
+		{
+			BOX_ERROR("Faild to install CtrlHandler: " <<
+				GetErrorMessage(GetLastError()));
+		}
+#endif
 	// Set up a context for our work
 	BackupQueries context(connection, conf, readWrite);
 	
@@ -512,7 +550,15 @@
 		}
 		#endif // HAVE_READLINE_HISTORY
 	}
-	
+	// uninstall the CtrlHandler to cleanup
+#ifdef WIN32
+		if(SetConsoleCtrlHandler((PHANDLER_ROUTINE)Win32CtrlHandler,FALSE) != TRUE)
+		{
+			BOX_ERROR("Faild to uninstall CtrlHandler: " <<
+				GetErrorMessage(GetLastError()));
+		}
+#endif
+
 	// Done... stop nicely
 	BOX_INFO("Logging off...");
 	connection.QueryFinished();


More information about the Boxbackup-dev mailing list