From 4305ecb0e7bca7f64324e0804df9543c4775aa6f Mon Sep 17 00:00:00 2001 From: chriseth Date: Sat, 25 Feb 2017 00:11:26 +0100 Subject: [PATCH] Try reading multiple times from IPC. --- test/RPCSession.cpp | 39 +++++++++++++++++++++++++-------------- test/RPCSession.h | 10 ++++++++-- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index ff00d7833..57829ff5c 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -16,19 +16,20 @@ The Implementation originally from https://msdn.microsoft.com/en-us/library/windows/desktop/aa365592(v=vs.85).aspx */ -/** @file RPCSession.cpp - * @author Dimtiry Khokhlov - * @author Alex Beregszaszi - * @date 2016 - */ +/// @file RPCSession.cpp +/// Low-level IPC communication between the test framework and the Ethereum node. + +#include "RPCSession.h" + +#include + +#include +#include #include #include #include -#include -#include -#include -#include "RPCSession.h" +#include using namespace std; using namespace dev; @@ -107,13 +108,23 @@ string IPCSocket::sendRequest(string const& _req) return string(m_readBuf, m_readBuf + cbRead); #else 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."); - ssize_t ret = recv(m_socket, m_readBuf, sizeof(m_readBuf), 0); + auto start = chrono::steady_clock::now(); + ssize_t ret; + do + { + 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."); + } while ( + ret == 0 && + chrono::duration_cast(chrono::steady_clock::now() - start).count() < m_readTimeOutMS + ); - // Also consider closed socket an error. - if (ret <= 0) - BOOST_FAIL("Reading on IPC failed"); + if (ret == 0) + BOOST_FAIL("Timeout reading on IPC."); return string(m_readBuf, m_readBuf + ret); #endif diff --git a/test/RPCSession.h b/test/RPCSession.h index 414db3232..843036e14 100644 --- a/test/RPCSession.h +++ b/test/RPCSession.h @@ -28,11 +28,13 @@ #include #endif +#include + +#include + #include #include #include -#include -#include #if defined(_WIN32) class IPCSocket : public boost::noncopyable @@ -60,8 +62,12 @@ public: std::string const& path() const { return m_path; } private: + std::string m_path; int m_socket; + /// Socket read timeout in milliseconds. Needs to be large because the key generation routine + /// might take long. + unsigned static constexpr m_readTimeOutMS = 15000; char m_readBuf[512000]; }; #endif