IPC protocol interface for calling IPC methods over sockets.
There may be different implementations of this interface for different IPC protocols (e.g. Cap'n Proto, gRPC, JSON-RPC, or custom protocols).
Definition at line 21 of file protocol.h.
| virtual void ipc::Protocol::serve |
( |
int | fd, |
|
|
const char * | exe_name, |
|
|
interfaces::Init & | init, |
|
|
const std::function< void()> & | ready_fn = {} ) |
|
pure virtual |
Handle requests on provided socket descriptor, forwarding them to the provided Init interface. Socket communication is handled on the current thread, and this call blocks until the socket is closed.
- Note
- : If this method is called, it needs be called before connect() or listen() methods, because for ease of implementation it's inflexible and always runs the event loop in the foreground thread. It can share its event loop with the other methods but can't share an event loop that was created by them. This isn't really a problem because serve() is only called by spawned child processes that call it immediately to communicate back with parent processes.
The optional ready_fn callback will be called after the event loop is created but before it is started. This can be useful in tests to trigger client connections from another thread as soon as the event loop is available, but should not be necessary in normal code which starts clients and servers independently.