aboutsummaryrefslogtreecommitdiffstats
path: root/test/RPCSession.cpp
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-02-10 17:37:43 +0800
committerGitHub <noreply@github.com>2017-02-10 17:37:43 +0800
commitaf8e31b023723bfc6baa224931ef6570cd8d9a32 (patch)
treef3d54f05cf0f03e81772a6ac96a4c9233f3fb51f /test/RPCSession.cpp
parenta0bc064d5299219fe454ed639a392fc2059b8b78 (diff)
parent95f8c5bcdb69ab4cba835f8bc06ab89da4768db8 (diff)
downloaddexon-solidity-af8e31b023723bfc6baa224931ef6570cd8d9a32.tar.gz
dexon-solidity-af8e31b023723bfc6baa224931ef6570cd8d9a32.tar.zst
dexon-solidity-af8e31b023723bfc6baa224931ef6570cd8d9a32.zip
Merge pull request #1669 from ethereum/ipc-cleanup
Don't rely on new lines in IPC RPC (soltest)
Diffstat (limited to 'test/RPCSession.cpp')
-rw-r--r--test/RPCSession.cpp47
1 files changed, 19 insertions, 28 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
}