diff options
Diffstat (limited to 'src/ipc/capnp/protocol.cpp')
-rw-r--r-- | src/ipc/capnp/protocol.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/ipc/capnp/protocol.cpp b/src/ipc/capnp/protocol.cpp index 37b57a9525..4b67a5bd1e 100644 --- a/src/ipc/capnp/protocol.cpp +++ b/src/ipc/capnp/protocol.cpp @@ -23,6 +23,8 @@ #include <mutex> #include <optional> #include <string> +#include <sys/socket.h> +#include <system_error> #include <thread> namespace ipc { @@ -30,7 +32,7 @@ namespace capnp { namespace { void IpcLogFn(bool raise, std::string message) { - LogPrint(BCLog::IPC, "%s\n", message); + LogDebug(BCLog::IPC, "%s\n", message); if (raise) throw Exception(message); } @@ -51,11 +53,20 @@ public: startLoop(exe_name); return mp::ConnectStream<messages::Init>(*m_loop, fd); } - void serve(int fd, const char* exe_name, interfaces::Init& init) override + void listen(int listen_fd, const char* exe_name, interfaces::Init& init) override + { + startLoop(exe_name); + if (::listen(listen_fd, /*backlog=*/5) != 0) { + throw std::system_error(errno, std::system_category()); + } + mp::ListenConnections<messages::Init>(*m_loop, listen_fd, init); + } + void serve(int fd, const char* exe_name, interfaces::Init& init, const std::function<void()>& ready_fn = {}) override { assert(!m_loop); mp::g_thread_context.thread_name = mp::ThreadName(exe_name); m_loop.emplace(exe_name, &IpcLogFn, &m_context); + if (ready_fn) ready_fn(); mp::ServeStream<messages::Init>(*m_loop, fd, init); m_loop->loop(); m_loop.reset(); |