Simplify the Windows IPC code

This commit is contained in:
Alex Beregszaszi 2017-02-09 13:06:48 +00:00
parent f9a818eaf8
commit f2cafd4974

View File

@ -80,7 +80,7 @@ IPCSocket::IPCSocket(string const& _path): m_path(_path)
string IPCSocket::sendRequest(string const& _req) string IPCSocket::sendRequest(string const& _req)
{ {
#if defined(_WIN32) #if defined(_WIN32)
string returnStr; // Write to the pipe.
DWORD cbWritten; DWORD cbWritten;
BOOL fSuccess = WriteFile( BOOL fSuccess = WriteFile(
m_socket, // pipe handle m_socket, // pipe handle
@ -92,9 +92,8 @@ string IPCSocket::sendRequest(string const& _req)
if (!fSuccess) if (!fSuccess)
BOOST_FAIL("WriteFile to pipe failed"); BOOST_FAIL("WriteFile to pipe failed");
DWORD cbRead;
// Read from the pipe. // Read from the pipe.
DWORD cbRead;
fSuccess = ReadFile( fSuccess = ReadFile(
m_socket, // pipe handle m_socket, // pipe handle
m_readBuf, // buffer to receive reply m_readBuf, // buffer to receive reply
@ -102,12 +101,10 @@ string IPCSocket::sendRequest(string const& _req)
&cbRead, // number of bytes read &cbRead, // number of bytes read
NULL); // not overlapped NULL); // not overlapped
returnStr += m_readBuf;
if (!fSuccess) if (!fSuccess)
BOOST_FAIL("ReadFile from pipe failed"); BOOST_FAIL("ReadFile from pipe failed");
return returnStr; return string(m_readBuf, m_readBuf + cbRead);
#else #else
if (send(m_socket, _req.c_str(), _req.length(), 0) != (ssize_t)_req.length()) if (send(m_socket, _req.c_str(), _req.length(), 0) != (ssize_t)_req.length())
BOOST_FAIL("Writing on IPC failed"); BOOST_FAIL("Writing on IPC failed");