30 const char*
what() const noexcept
override {
return "Server shutdown requested"; }
88 virtual void release(
int client_id,
size_t message_size) = 0;
97 virtual bool send(
int client_id,
const void*
data,
size_t len) = 0;
165 auto request =
receive(client_id);
166 if (request.empty()) {
171 auto response = handler(client_id, request);
172 if (!response.empty()) {
173 send(client_id, response.data(), response.size());
177 release(client_id, request.size());
180 release(client_id, request.size());
195 size_t request_ring_size =
static_cast<size_t>(1024 * 1024),
196 size_t response_ring_size =
static_cast<size_t>(1024 * 1024));
Abstract interface for IPC server.
virtual int accept()
Accept a new client connection (optional for some transports)
IpcServer(const IpcServer &)=delete
virtual int wait_for_data(uint64_t timeout_ns)=0
Wait for data from any connected client.
virtual void close()=0
Close the server and all client connections.
static std::unique_ptr< IpcServer > create_socket(const std::string &socket_path, int max_clients)
IpcServer & operator=(IpcServer &&)=delete
static std::unique_ptr< IpcServer > create_shm(const std::string &base_name, size_t request_ring_size=static_cast< size_t >(1024 *1024), size_t response_ring_size=static_cast< size_t >(1024 *1024))
virtual bool send(int client_id, const void *data, size_t len)=0
Send a message to a specific client.
virtual void wakeup_all()
Wake all blocked threads (for graceful shutdown)
std::function< std::vector< uint8_t >(int client_id, std::span< const uint8_t > request)> Handler
High-level request handler function type.
virtual bool listen()=0
Start listening for client connections.
virtual ~IpcServer()=default
virtual void release(int client_id, size_t message_size)=0
Release/consume the previously received message.
virtual std::span< const uint8_t > receive(int client_id)=0
Receive next message from a specific client.
virtual void request_shutdown()
Request graceful shutdown.
IpcServer(IpcServer &&)=delete
std::atomic< bool > shutdown_requested_
IpcServer & operator=(const IpcServer &)=delete
virtual void run(const Handler &handler)
Run server event loop with handler.
Exception thrown by handler to signal graceful shutdown.
ShutdownRequested(std::vector< uint8_t > response)
const std::vector< uint8_t > & response() const
const char * what() const noexcept override
std::vector< uint8_t > response_
const std::vector< MemoryValue > data
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept