33 : m_exe_name(exe_name), m_process_argv0(process_argv0), m_init(
init),
37 std::unique_ptr<interfaces::Init> spawnProcess(
const char* new_exe_name)
override
40 int fd = m_process->spawn(new_exe_name, m_process_argv0, pid);
41 LogDebug(::BCLog::IPC,
"Process %s pid %i launched\n", new_exe_name, pid);
42 auto init = m_protocol->connect(fd, m_exe_name);
43 Ipc::addCleanup(*
init, [
this, new_exe_name, pid] {
44 int status = m_process->waitSpawned(pid);
45 LogDebug(::BCLog::IPC,
"Process %s pid %i exited with status %i\n", new_exe_name, pid, status);
49 bool startSpawnedProcess(
int argc,
char* argv[],
int&
exit_status)
override
53 if (!m_process->checkSpawned(argc, argv, fd)) {
56 m_protocol->serve(fd, m_exe_name, m_init);
60 std::unique_ptr<interfaces::Init> connectAddress(std::string& address)
override
62 if (address.empty() || address ==
"0")
return nullptr;
64 if (address ==
"auto") {
72 }
catch (
const std::system_error& e) {
74 if (e.code() == std::errc::connection_refused || e.code() == std::errc::no_such_file_or_directory) {
82 return m_protocol->connect(fd, m_exe_name);
84 void listenAddress(std::string& address)
override
87 m_protocol->listen(fd, m_exe_name, m_init);
89 void addCleanup(std::type_index type,
void* iface, std::function<
void()> cleanup)
override
91 m_protocol->addCleanup(type, iface, std::move(cleanup));
93 Context& context()
override {
return m_protocol->context(); }
94 const char* m_exe_name;
95 const char* m_process_argv0;
97 std::unique_ptr<Protocol> m_protocol;
98 std::unique_ptr<Process> m_process;
104std::unique_ptr<Ipc>
MakeIpc(
const char* exe_name,
const char* process_argv0,
Init&
init)
106 return std::make_unique<ipc::IpcImpl>(exe_name, process_argv0,
init);
std::unique_ptr< interfaces::Init > init
fs::path GetDataDirNet() const
Get data directory path with appended network identifier.
Initial interface created when a process is first started, and used to give and get access to other i...
Interface providing access to interprocess-communication (IPC) functionality.
#define LogDebug(category,...)
std::unique_ptr< Ipc > MakeIpc(const char *exe_name, const char *process_argv0, Init &init)
Return implementation of Ipc interface.
std::unique_ptr< Protocol > MakeCapnpProtocol()
std::unique_ptr< Process > MakeProcess()
Constructor for Process interface.