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