[Box Backup-commit] COMMIT r1877 - box/trunk/lib/server

boxbackup-dev@fluffy.co.uk boxbackup-dev@fluffy.co.uk
Wed, 17 Oct 2007 13:48:05 +0100


Author: chris
Date: 2007-10-17 13:48:05 +0100 (Wed, 17 Oct 2007)
New Revision: 1877

Modified:
   box/trunk/lib/server/WinNamedPipeStream.cpp
   box/trunk/lib/server/WinNamedPipeStream.h
Log:
Prepend the system-required prefix to the named pipe name from the
configuration file. (merges [1833])


Modified: box/trunk/lib/server/WinNamedPipeStream.cpp
===================================================================
--- box/trunk/lib/server/WinNamedPipeStream.cpp	2007-10-17 12:47:37 UTC (rev 1876)
+++ box/trunk/lib/server/WinNamedPipeStream.cpp	2007-10-17 12:48:05 UTC (rev 1877)
@@ -26,6 +26,8 @@
 
 #include "MemLeakFindOn.h"
 
+std::string WinNamedPipeStream::sPipeNamePrefix = "\\\\.\\pipe\\";
+
 // --------------------------------------------------------------------------
 //
 // Function
@@ -72,21 +74,23 @@
 // --------------------------------------------------------------------------
 //
 // Function
-//		Name:    WinNamedPipeStream::Accept(const char* Name)
+//		Name:    WinNamedPipeStream::Accept(const std::string& rName)
 //		Purpose: Creates a new named pipe with the given name,
 //			and wait for a connection on it
 //		Created: 2005/12/07
 //
 // --------------------------------------------------------------------------
-void WinNamedPipeStream::Accept(const wchar_t* pName)
+void WinNamedPipeStream::Accept(const std::string& rName)
 {
 	if (mSocketHandle != INVALID_HANDLE_VALUE || mIsConnected) 
 	{
 		THROW_EXCEPTION(ServerException, SocketAlreadyOpen)
 	}
 
-	mSocketHandle = CreateNamedPipeW( 
-		pName,                     // pipe name 
+	std::string socket = sPipeNamePrefix + rName;
+
+	mSocketHandle = CreateNamedPipeA( 
+		socket.c_str(),            // pipe name 
 		PIPE_ACCESS_DUPLEX |       // read/write access 
 		FILE_FLAG_OVERLAPPED,      // enabled overlapped I/O
 		PIPE_TYPE_BYTE |           // message type pipe 
@@ -100,7 +104,7 @@
 
 	if (mSocketHandle == INVALID_HANDLE_VALUE)
 	{
-		BOX_ERROR("Failed to CreateNamedPipeW(" << pName << "): " <<
+		BOX_ERROR("Failed to CreateNamedPipeA(" << socket << "): " <<
 			GetErrorMessage(GetLastError()));
 		THROW_EXCEPTION(ServerException, SocketOpenError)
 	}
@@ -109,7 +113,7 @@
 
 	if (!connected)
 	{
-		BOX_ERROR("Failed to ConnectNamedPipe(" << pName << "): " <<
+		BOX_ERROR("Failed to ConnectNamedPipe(" << socket << "): " <<
 			GetErrorMessage(GetLastError()));
 		Close();
 		THROW_EXCEPTION(ServerException, SocketOpenError)
@@ -156,20 +160,22 @@
 // --------------------------------------------------------------------------
 //
 // Function
-//		Name:    WinNamedPipeStream::Connect(const char* Name)
+//		Name:    WinNamedPipeStream::Connect(const std::string& rName)
 //		Purpose: Opens a connection to a listening named pipe
 //		Created: 2005/12/07
 //
 // --------------------------------------------------------------------------
-void WinNamedPipeStream::Connect(const wchar_t* pName)
+void WinNamedPipeStream::Connect(const std::string& rName)
 {
 	if (mSocketHandle != INVALID_HANDLE_VALUE || mIsConnected) 
 	{
 		THROW_EXCEPTION(ServerException, SocketAlreadyOpen)
 	}
+
+	std::string socket = sPipeNamePrefix + rName;
 	
-	mSocketHandle = CreateFileW( 
-		pName,          // pipe name 
+	mSocketHandle = CreateFileA( 
+		socket.c_str(), // pipe name 
 		GENERIC_READ |  // read and write access 
 		GENERIC_WRITE, 
 		0,              // no sharing 

Modified: box/trunk/lib/server/WinNamedPipeStream.h
===================================================================
--- box/trunk/lib/server/WinNamedPipeStream.h	2007-10-17 12:47:37 UTC (rev 1876)
+++ box/trunk/lib/server/WinNamedPipeStream.h	2007-10-17 12:48:05 UTC (rev 1877)
@@ -27,10 +27,10 @@
 	~WinNamedPipeStream();
 
 	// server side - create the named pipe and listen for connections
-	void Accept(const wchar_t* Name);
+	void Accept(const std::string& rName);
 
 	// client side - connect to a waiting server
-	void Connect(const wchar_t* Name);
+	void Connect(const std::string& rName);
 
 	// both sides
 	virtual int Read(void *pBuffer, int NBytes, 
@@ -61,6 +61,8 @@
 	bool mWriteClosed;
 	bool mIsServer;
 	bool mIsConnected;
+
+	static std::string sPipeNamePrefix;
 };
 
 #endif // WINNAMEDPIPESTREAM__H