7#include <ipc/capnp/init.capnp.h>
8#include <ipc/capnp/init.capnp.proxy.h>
27#include <sys/socket.h>
28#include <system_error>
46 switch (message.
level) {
64 throw Exception(message.
message);
72class CapnpProtocol :
public Protocol
85 return mp::ConnectStream<messages::Init>(*m_loop, std::move(
stream));
91 throw std::system_error(
errno, std::system_category());
93 mp::ListenConnections<messages::Init>(*m_loop,
listen_fd,
init, max_connections);
103 m_loop.emplace(m_exe_name, std::move(opts), &m_context);
109 void disconnectIncoming()
override
116 std::erase_if(
m_loop->m_incoming_connections, [
this](
mp::Connection&
c) { return &c != m_parent_connection; });
124 void addCleanup(std::type_index type,
void*
iface, std::function<
void()> cleanup)
override
139 m_loop.emplace(m_exe_name, std::move(opts), &m_context);
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 LogTrace(category,...)
#define LogDebug(category,...)
std::unique_ptr< Protocol > MakeCapnpProtocol(const char *exe_name)
Stream MakeStream(EventLoop &loop, SocketId socket)
Wrap a socket file descriptor as an async stream, taking ownership of the fd.
ThreadContext & CurrentThread()
Return the current thread's ThreadContext.
std::string ThreadName(const char *exe_name)
Format current thread name as "{exe_name}-{$pid}/{thread_name}-{$tid}".
kj::Own< kj::AsyncIoStream > Stream
Log
Log flags. Update stringify function if changed!
bool ShouldDebugLog(Category)
Return whether messages with specified category should be debug logged.
bool ShouldTraceLog(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.
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.