Try reading multiple times from IPC.

This commit is contained in:
chriseth 2017-02-25 00:11:26 +01:00
parent d2c79bf8e9
commit 4305ecb0e7
2 changed files with 33 additions and 16 deletions

View File

@ -16,19 +16,20 @@
The Implementation originally from https://msdn.microsoft.com/en-us/library/windows/desktop/aa365592(v=vs.85).aspx The Implementation originally from https://msdn.microsoft.com/en-us/library/windows/desktop/aa365592(v=vs.85).aspx
*/ */
/** @file RPCSession.cpp /// @file RPCSession.cpp
* @author Dimtiry Khokhlov <dimitry@ethdev.com> /// Low-level IPC communication between the test framework and the Ethereum node.
* @author Alex Beregszaszi
* @date 2016 #include "RPCSession.h"
*/
#include <libdevcore/CommonData.h>
#include <json/reader.h>
#include <json/writer.h>
#include <string> #include <string>
#include <stdio.h> #include <stdio.h>
#include <thread> #include <thread>
#include <libdevcore/CommonData.h> #include <chrono>
#include <json/reader.h>
#include <json/writer.h>
#include "RPCSession.h"
using namespace std; using namespace std;
using namespace dev; using namespace dev;
@ -107,13 +108,23 @@ string IPCSocket::sendRequest(string const& _req)
return string(m_readBuf, m_readBuf + cbRead); return string(m_readBuf, m_readBuf + cbRead);
#else #else
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.");
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. // Also consider closed socket an error.
if (ret <= 0) if (ret < 0)
BOOST_FAIL("Reading on IPC failed"); BOOST_FAIL("Reading on IPC failed.");
} while (
ret == 0 &&
chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - start).count() < m_readTimeOutMS
);
if (ret == 0)
BOOST_FAIL("Timeout reading on IPC.");
return string(m_readBuf, m_readBuf + ret); return string(m_readBuf, m_readBuf + ret);
#endif #endif

View File

@ -28,11 +28,13 @@
#include <sys/un.h> #include <sys/un.h>
#endif #endif
#include <json/value.h>
#include <boost/test/unit_test.hpp>
#include <string> #include <string>
#include <stdio.h> #include <stdio.h>
#include <map> #include <map>
#include <json/value.h>
#include <boost/test/unit_test.hpp>
#if defined(_WIN32) #if defined(_WIN32)
class IPCSocket : public boost::noncopyable class IPCSocket : public boost::noncopyable
@ -60,8 +62,12 @@ public:
std::string const& path() const { return m_path; } std::string const& path() const { return m_path; }
private: private:
std::string m_path; std::string m_path;
int m_socket; 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]; char m_readBuf[512000];
}; };
#endif #endif