diff options
author | Bob Summerwill <bob@summerwill.net> | 2016-08-03 13:49:00 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-03 13:49:00 +0800 |
commit | 4fbe4a1cc42e6f64d5874f2a557a31ee5911f8c2 (patch) | |
tree | dd38baf0fcb620bb6b0e4008697fe0727075a532 /test/RPCSession.cpp | |
parent | b68ca9cd569e179c4209aaa2706bb962b7fc2fd0 (diff) | |
parent | 5925ae0c6a32517f3b19b095e3ed8518d021f2e7 (diff) | |
download | dexon-solidity-4fbe4a1cc42e6f64d5874f2a557a31ee5911f8c2.tar dexon-solidity-4fbe4a1cc42e6f64d5874f2a557a31ee5911f8c2.tar.gz dexon-solidity-4fbe4a1cc42e6f64d5874f2a557a31ee5911f8c2.tar.bz2 dexon-solidity-4fbe4a1cc42e6f64d5874f2a557a31ee5911f8c2.tar.lz dexon-solidity-4fbe4a1cc42e6f64d5874f2a557a31ee5911f8c2.tar.xz dexon-solidity-4fbe4a1cc42e6f64d5874f2a557a31ee5911f8c2.tar.zst dexon-solidity-4fbe4a1cc42e6f64d5874f2a557a31ee5911f8c2.zip |
Merge pull request #799 from winsvega/winpipe
Winpipe
Diffstat (limited to 'test/RPCSession.cpp')
-rw-r--r-- | test/RPCSession.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index e9df9031..c510a028 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -13,6 +13,8 @@ You should have received a copy of the GNU General Public License along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. + + The Implementation originally from https://msdn.microsoft.com/en-us/library/windows/desktop/aa365592(v=vs.85).aspx */ /** @file RPCSession.cpp * @author Dimtiry Khokhlov <dimitry@ethdev.com> @@ -32,6 +34,21 @@ using namespace dev; IPCSocket::IPCSocket(string const& _path): m_path(_path) { + m_socket = CreateFile( + m_path.c_str(), // pipe name + GENERIC_READ | // read and write access + GENERIC_WRITE, + 0, // no sharing + NULL, // default security attribute + OPEN_EXISTING, // opens existing pipe + 0, // default attributes + NULL); // no template file + + if (m_socket == INVALID_HANDLE_VALUE) + BOOST_FAIL("Error creating IPC socket object"); + +#if defined(_WIN32) +#else if (_path.length() >= sizeof(sockaddr_un::sun_path)) BOOST_FAIL("Error opening IPC: socket path is too long!"); @@ -58,10 +75,43 @@ IPCSocket::IPCSocket(string const& _path): m_path(_path) BOOST_FAIL("Error connecting to IPC socket: " << _path); m_fp = fdopen(m_socket, "r"); +#endif } string IPCSocket::sendRequest(string const& _req) { +#if defined(_WIN32) + string returnStr; + DWORD cbWritten; + BOOL fSuccess = WriteFile( + m_socket, // pipe handle + _req.c_str(), // message + _req.size(), // message length + &cbWritten, // bytes written + NULL); // not overlapped + + if (!fSuccess) + BOOST_FAIL("WriteFile to pipe failed"); + + DWORD cbRead; + TCHAR chBuf[c_buffsize]; + + // Read from the pipe. + 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; + + if (!fSuccess) + BOOST_FAIL("ReadFile from pipe failed"); + + cerr << "."; //Output for log activity + return returnStr; +#else send(m_socket, _req.c_str(), _req.length(), 0); char c; @@ -74,6 +124,7 @@ string IPCSocket::sendRequest(string const& _req) break; } return response; +#endif } RPCSession& RPCSession::instance(const string& _path) |