7#include <ipc/capnp/init.capnp.h>
8#include <ipc/capnp/init.capnp.proxy.h>
26#include <sys/socket.h>
27#include <system_error>
50mp::Log GetRequestedIPCLogLevel()
65class CapnpProtocol :
public Protocol
68 ~CapnpProtocol() noexcept(true)
74 std::unique_ptr<interfaces::Init> connect(
int fd,
const char* exe_name)
override
77 return mp::ConnectStream<messages::Init>(*
m_loop, fd);
82 if (::listen(listen_fd, 5) != 0) {
83 throw std::system_error(errno, std::system_category());
85 mp::ListenConnections<messages::Init>(*
m_loop, listen_fd,
init);
87 void serve(
int fd,
const char* exe_name,
interfaces::Init&
init,
const std::function<
void()>& ready_fn = {})
override
93 .log_level = GetRequestedIPCLogLevel()
96 if (ready_fn) ready_fn();
97 mp::ServeStream<messages::Init>(*
m_loop, fd,
init);
102 void disconnectIncoming()
override
112 void addCleanup(std::type_index type,
void* iface, std::function<
void()> cleanup)
override
116 Context& context()
override {
return m_context; }
117 void startLoop(
const char* exe_name)
120 std::promise<void> promise;
125 .log_level = GetRequestedIPCLogLevel()
133 promise.get_future().wait();
Initial interface created when a process is first started, and used to give and get access to other i...
Object holding network & rpc state associated with either an incoming server connection,...
std::thread m_loop_thread
mp::Connection * m_parent_connection
Connection to parent, if this is a child process spawned by a parent process.
std::optional< mp::EventLoop > m_loop
EventLoop object which manages I/O events for all connections.
std::optional< mp::EventLoopRef > m_loop_ref
Reference to the same EventLoop.
#define LogPrintLevel(category, level,...)
static bool LogAcceptCategory(BCLog::LogFlags category, BCLog::Level level)
Return true if log accepts specified category, at the specified level.
std::unique_ptr< Protocol > MakeCapnpProtocol()
std::string ThreadName(const char *exe_name)
Format current thread name as "{exe_name}-{$pid}/{thread_name}-{$tid}".
thread_local ThreadContext g_thread_context
Log
Log flags. Update stringify function if changed!
void ThreadRename(const std::string &)
Rename a thread both in terms of an internal (in-memory) name as well as its system thread name.
Log level
The severity level of this message.
std::string message
Message to be logged.
LogFn log_fn
External logging callback.
std::string thread_name
Identifying string for debug.