[Box Backup-commit] COMMIT r1833 - box/chris/general/lib/server
boxbackup-dev@fluffy.co.uk
boxbackup-dev@fluffy.co.uk
Fri, 14 Sep 2007 22:25:42 +0100
Author: chris
Date: 2007-09-14 22:25:42 +0100 (Fri, 14 Sep 2007)
New Revision: 1833
Modified:
box/chris/general/lib/server/WinNamedPipeStream.cpp
box/chris/general/lib/server/WinNamedPipeStream.h
Log:
Prepend the system-required prefix to the named pipe name from the
configuration file.
Modified: box/chris/general/lib/server/WinNamedPipeStream.cpp
===================================================================
--- box/chris/general/lib/server/WinNamedPipeStream.cpp 2007-09-14 21:24:23 UTC (rev 1832)
+++ box/chris/general/lib/server/WinNamedPipeStream.cpp 2007-09-14 21:25:42 UTC (rev 1833)
@@ -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/chris/general/lib/server/WinNamedPipeStream.h
===================================================================
--- box/chris/general/lib/server/WinNamedPipeStream.h 2007-09-14 21:24:23 UTC (rev 1832)
+++ box/chris/general/lib/server/WinNamedPipeStream.h 2007-09-14 21:25:42 UTC (rev 1833)
@@ -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