Fabcoin Core  0.16.2
P2P Digital Currency
WinPipeServer.cpp
Go to the documentation of this file.
1 /*
2 This file is part of cpp-ethereum.
3 
4 cpp-ethereum is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8 
9 cpp-ethereum is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
22 #if defined(_WIN32)
23 
24 #include "WinPipeServer.h"
25 #include <windows.h>
26 #include <libdevcore/Guards.h>
27 
28 using namespace std;
29 using namespace jsonrpc;
30 using namespace dev;
31 
32 int const c_bufferSize = 1024;
33 
34 WindowsPipeServer::WindowsPipeServer(string const& _appId):
35  IpcServerBase("\\\\.\\pipe\\" + _appId + ".ipc")
36 {
37 }
38 
39 void WindowsPipeServer::CloseConnection(HANDLE _socket)
40 {
41  ::CloseHandle(_socket);
42 }
43 
44 size_t WindowsPipeServer::Write(HANDLE _connection, std::string const& _data)
45 {
46  DWORD written = 0;
47  ::WriteFile(_connection, _data.data(), _data.size(), &written , nullptr);
48  return written;
49 }
50 
51 size_t WindowsPipeServer::Read(HANDLE _connection, void* _data, size_t _size)
52 {
53  DWORD read;
54  ::ReadFile(_connection, _data, _size, &read, nullptr);
55  return read;
56 }
57 
58 void WindowsPipeServer::Listen()
59 {
60  while (m_running)
61  {
62  HANDLE socket = CreateNamedPipe(
63  m_path.c_str(),
64  PIPE_ACCESS_DUPLEX,
65  PIPE_READMODE_BYTE |
66  PIPE_WAIT,
67  PIPE_UNLIMITED_INSTANCES,
70  0,
71  nullptr);
72 
73  DEV_GUARDED(x_sockets)
74  m_sockets.insert(socket);
75 
76  if (ConnectNamedPipe(socket, nullptr) != 0)
77  {
78  std::thread handler([this, socket](){ GenerateResponse(socket); });
79  handler.detach();
80  }
81  else
82  {
83  DEV_GUARDED(x_sockets)
84  m_sockets.erase(socket);
85  }
86  }
87 }
88 
89 #endif
bool(* handler)(HTTPRequest *req, const std::string &strReq)
Definition: rest.cpp:624
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
std::hash for asio::adress
Definition: Common.h:323
bool read(const std::string &s, Value &value)
if(a.IndicesBefore(b, len, lenIndices))
Definition: equihash.cpp:243
#define DEV_GUARDED(MUTEX)
Simple block guard.
Definition: Guards.h:144
int const c_bufferSize