7#include <ipc/capnp/init.capnp.h>
8#include <ipc/capnp/init.capnp.proxy.h>
26#include <sys/socket.h>
27#include <system_error>
34mp::Log GetRequestedIPCLogLevel()
45 switch (message.
level) {
63 throw Exception(message.
message);
71class CapnpProtocol :
public Protocol
74 CapnpProtocol(
const char* exe_name) :
m_exe_name{exe_name} {}
75 ~CapnpProtocol() noexcept(true)
81 std::unique_ptr<interfaces::Init> connect(
mp::Stream stream)
override
84 return mp::ConnectStream<messages::Init>(*
m_loop, std::move(stream));
89 if (::listen(listen_fd, 5) != 0) {
90 throw std::system_error(errno, std::system_category());
92 mp::ListenConnections<messages::Init>(*
m_loop, listen_fd,
init);
100 .log_level = GetRequestedIPCLogLevel()
103 mp::ServeStream<messages::Init>(*
m_loop, make_stream(),
init);
108 void disconnectIncoming()
override
123 void addCleanup(std::type_index type,
void* iface, std::function<
void()> cleanup)
override
127 Context& context()
override {
return m_context; }
131 std::promise<void> promise;
136 .log_level = GetRequestedIPCLogLevel()
144 promise.get_future().wait();
160std::unique_ptr<Protocol>
MakeCapnpProtocol(
const char* exe_name) {
return std::make_unique<CapnpProtocol>(exe_name); }
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.
std::thread thread
Thread variable should be after other struct members so the thread does not start until the other mem...
#define LogTrace(category,...)
#define LogDebug(category,...)
std::unique_ptr< Protocol > MakeCapnpProtocol(const char *exe_name)
ThreadContext & CurrentThread()
std::string ThreadName(const char *exe_name)
Format current thread name as "{exe_name}-{$pid}/{thread_name}-{$tid}".
Stream MakeStream(EventLoop &, SocketId socket)
Log
Log flags. Update stringify function if changed!
bool ShouldDebugLog(Category category)
Return whether messages with specified category should be debug logged.
bool ShouldTraceLog(Category category)
Return whether messages with specified category should be trace logged.
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.