Skip to content

Commit

Permalink
Do not expect a new line, rather buffer up the response in IPC
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Feb 9, 2017
1 parent b508aac commit 5396c76
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
32 changes: 14 additions & 18 deletions test/RPCSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
/** @file RPCSession.cpp
* @author Dimtiry Khokhlov <[email protected]>
* @author Alex Beregszaszi
* @date 2016
*/

Expand Down Expand Up @@ -91,18 +92,17 @@ string IPCSocket::sendRequest(string const& _req)
if (!fSuccess)
BOOST_FAIL("WriteFile to pipe failed");

DWORD cbRead;
TCHAR chBuf[c_buffsize];
DWORD cbRead;

// Read from the pipe.
fSuccess = ReadFile(
m_socket, // pipe handle
chBuf, // buffer to receive reply
c_buffsize,// size of buffer
&cbRead, // number of bytes read
NULL); // not overlapped
m_socket, // pipe handle
m_readBuf, // buffer to receive reply
sizeof(m_readBuf), // size of buffer
&cbRead, // number of bytes read
NULL); // not overlapped

returnStr += chBuf;
returnStr += m_readBuf;

if (!fSuccess)
BOOST_FAIL("ReadFile from pipe failed");
Expand All @@ -112,16 +112,12 @@ string IPCSocket::sendRequest(string const& _req)
if (send(m_socket, _req.c_str(), _req.length(), 0) != (ssize_t)_req.length())
BOOST_FAIL("Writing on IPC failed");

char c;
string response;
while (recv(m_socket, &c, 1, 0) == 1)
{
if (c != '\n')
response += c;
else
break;
}
return response;
ssize_t ret = recv(m_socket, m_readBuf, sizeof(m_readBuf), 0);

if (ret < 0)
BOOST_FAIL("Reading on IPC failed");

return string(m_readBuf, m_readBuf + ret);
#endif
}

Expand Down
5 changes: 3 additions & 2 deletions test/RPCSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include <boost/test/unit_test.hpp>

#if defined(_WIN32)
const int c_buffsize = 5120000; //because windows pipe is broken and wont work as in examples. use larger buffer limit to receive whole package in one call
class IPCSocket : public boost::noncopyable
{
public:
Expand All @@ -47,7 +46,8 @@ class IPCSocket : public boost::noncopyable

private:
std::string m_path;
HANDLE m_socket;
HANDLE m_socket;
TCHAR m_readBuf[512000];
};
#else
class IPCSocket: public boost::noncopyable
Expand All @@ -62,6 +62,7 @@ class IPCSocket: public boost::noncopyable
private:
std::string m_path;
int m_socket;
char m_readBuf[512000];
};
#endif

Expand Down

0 comments on commit 5396c76

Please sign in to comment.