aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--test/RPCSession.cpp47
-rw-r--r--test/RPCSession.h8
2 files changed, 23 insertions, 32 deletions
diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp
index 968d77b1..b3451528 100644
--- a/test/RPCSession.cpp
+++ b/test/RPCSession.cpp
@@ -18,6 +18,7 @@
*/
/** @file RPCSession.cpp
* @author Dimtiry Khokhlov <dimitry@ethdev.com>
+ * @author Alex Beregszaszi
* @date 2016
*/
@@ -73,17 +74,13 @@ IPCSocket::IPCSocket(string const& _path): m_path(_path)
if (connect(m_socket, reinterpret_cast<struct sockaddr const*>(&saun), sizeof(struct sockaddr_un)) < 0)
BOOST_FAIL("Error connecting to IPC socket: " << _path);
-
- m_fp = fdopen(m_socket, "r");
- if (!m_fp)
- BOOST_FAIL("Error opening IPC socket: " << _path);
#endif
}
string IPCSocket::sendRequest(string const& _req)
{
#if defined(_WIN32)
- string returnStr;
+ // Write to the pipe.
DWORD cbWritten;
BOOL fSuccess = WriteFile(
m_socket, // pipe handle
@@ -92,39 +89,33 @@ string IPCSocket::sendRequest(string const& _req)
&cbWritten, // bytes written
NULL); // not overlapped
- if (!fSuccess)
+ if (!fSuccess || (_req.size() != cbWritten))
BOOST_FAIL("WriteFile to pipe failed");
- DWORD cbRead;
- TCHAR chBuf[c_buffsize];
-
// Read from the pipe.
+ DWORD cbRead;
fSuccess = ReadFile(
- m_socket, // pipe handle
- chBuf, // buffer to receive reply
- c_buffsize,// size of buffer
- &cbRead, // number of bytes read
- NULL); // not overlapped
-
- returnStr += chBuf;
+ m_socket, // pipe handle
+ m_readBuf, // buffer to receive reply
+ sizeof(m_readBuf), // size of buffer
+ &cbRead, // number of bytes read
+ NULL); // not overlapped
if (!fSuccess)
BOOST_FAIL("ReadFile from pipe failed");
- return returnStr;
+ return string(m_readBuf, m_readBuf + cbRead);
#else
- send(m_socket, _req.c_str(), _req.length(), 0);
+ 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 ((c = fgetc(m_fp)) != EOF)
- {
- if (c != '\n')
- response += c;
- else
- break;
- }
- return response;
+ ssize_t ret = recv(m_socket, m_readBuf, sizeof(m_readBuf), 0);
+
+ // Also consider closed socket an error.
+ if (ret <= 0)
+ BOOST_FAIL("Reading on IPC failed");
+
+ return string(m_readBuf, m_readBuf + ret);
#endif
}
diff --git a/test/RPCSession.h b/test/RPCSession.h
index fc166b99..f1aee6a8 100644
--- a/test/RPCSession.h
+++ b/test/RPCSession.h
@@ -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:
@@ -47,7 +46,8 @@ public:
private:
std::string m_path;
- HANDLE m_socket;
+ HANDLE m_socket;
+ TCHAR m_readBuf[512000];
};
#else
class IPCSocket: public boost::noncopyable
@@ -55,14 +55,14 @@ class IPCSocket: public boost::noncopyable
public:
IPCSocket(std::string const& _path);
std::string sendRequest(std::string const& _req);
- ~IPCSocket() { close(m_socket); fclose(m_fp); }
+ ~IPCSocket() { close(m_socket); }
std::string const& path() const { return m_path; }
private:
- FILE *m_fp;
std::string m_path;
int m_socket;
+ char m_readBuf[512000];
};
#endif