Do not expect a new line, rather buffer up the response in IPC

This commit is contained in:
Alex Beregszaszi 2017-02-07 14:10:43 +00:00
parent b508aac64a
commit 5396c7692b
2 changed files with 17 additions and 20 deletions

View File

@ -18,6 +18,7 @@
*/ */
/** @file RPCSession.cpp /** @file RPCSession.cpp
* @author Dimtiry Khokhlov <dimitry@ethdev.com> * @author Dimtiry Khokhlov <dimitry@ethdev.com>
* @author Alex Beregszaszi
* @date 2016 * @date 2016
*/ */
@ -91,18 +92,17 @@ string IPCSocket::sendRequest(string const& _req)
if (!fSuccess) if (!fSuccess)
BOOST_FAIL("WriteFile to pipe failed"); BOOST_FAIL("WriteFile to pipe failed");
DWORD cbRead; DWORD cbRead;
TCHAR chBuf[c_buffsize];
// Read from the pipe. // Read from the pipe.
fSuccess = ReadFile( fSuccess = ReadFile(
m_socket, // pipe handle m_socket, // pipe handle
chBuf, // buffer to receive reply m_readBuf, // buffer to receive reply
c_buffsize,// size of buffer sizeof(m_readBuf), // size of buffer
&cbRead, // number of bytes read &cbRead, // number of bytes read
NULL); // not overlapped NULL); // not overlapped
returnStr += chBuf; returnStr += m_readBuf;
if (!fSuccess) if (!fSuccess)
BOOST_FAIL("ReadFile from pipe failed"); BOOST_FAIL("ReadFile from pipe failed");
@ -112,16 +112,12 @@ string IPCSocket::sendRequest(string const& _req)
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");
char c; ssize_t ret = recv(m_socket, m_readBuf, sizeof(m_readBuf), 0);
string response;
while (recv(m_socket, &c, 1, 0) == 1) if (ret < 0)
{ BOOST_FAIL("Reading on IPC failed");
if (c != '\n')
response += c; return string(m_readBuf, m_readBuf + ret);
else
break;
}
return response;
#endif #endif
} }

View File

@ -35,7 +35,6 @@
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#if defined(_WIN32) #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 class IPCSocket : public boost::noncopyable
{ {
public: public:
@ -47,7 +46,8 @@ public:
private: private:
std::string m_path; std::string m_path;
HANDLE m_socket; HANDLE m_socket;
TCHAR m_readBuf[512000];
}; };
#else #else
class IPCSocket: public boost::noncopyable class IPCSocket: public boost::noncopyable
@ -62,6 +62,7 @@ public:
private: private:
std::string m_path; std::string m_path;
int m_socket; int m_socket;
char m_readBuf[512000];
}; };
#endif #endif