Files
bitcoin/doc/usage.md
Ryan Ofsky a334bbe9b7 Squashed 'src/ipc/libmultiprocess/' changes from 1b8d4a6f1e54..13424cf2ecc1
13424cf2ecc1 Merge bitcoin-core/libmultiprocess#205: cmake: check for Cap'n Proto / Clang / C++20 incompatibility
72dce118649b Merge bitcoin-core/libmultiprocess#200: event loop: add LogOptions struct and reduce the log size
85003409f964 eventloop: add `LogOptions` struct
657d80622f81 cmake: capnproto pkg missing helpful error
d314057775a5 cmake: check for Cap'n Proto / Clang / C++20 incompatibility
878e84dc3030 Merge bitcoin-core/libmultiprocess#203: cmake: search capnproto in package mode only
1a85da5873c2 Merge bitcoin-core/libmultiprocess#202: doc: correct the build instructions for the example
df01873e1ecb Merge bitcoin-core/libmultiprocess#197: ci: Add freebsd and macos build
3bee07ab3367 cmake: search capnproto in package mode only
b6d3dc44194c doc: correct the build instructions for example
fa1ac3000055 ci: Add macos and freebsd task

git-subtree-dir: src/ipc/libmultiprocess
git-subtree-split: 13424cf2ecc1e5eadc85556cf1f4c65e915f702a
2025-09-05 15:43:16 -04:00

3.5 KiB

libmultiprocess Usage

Overview

libmultiprocess is a library and code generator that allows calling C++ class interfaces across different processes. For an interface to be available from other processes, it needs two definitions:

The *.capnp data definition files are consumed by the libmultiprocess code generator and each X.capnp file generates X.capnp.c++, X.capnp.h, X.capnp.proxy-client.c++, X.capnp.proxy-server.c++, X.capnp.proxy-types.c++, X.capnp.proxy-types.h, and X.capnp.proxy.h output files. The generated files include mp::ProxyClient<Interface> and mp::ProxyServer<Interface> class specializations for all the interfaces in the .capnp files. These allow methods on C++ objects in one process to be called from other processes over IPC sockets.

The ProxyServer objects help translate IPC requests from a socket to method calls on a local object. The ProxyServer objects are just used internally by the mp::ServeStream(loop, socket, wrapped_object) and mp::ListenConnections(loop, socket, wrapped_object) functions, and aren't exposed externally. The ProxyClient classes are exposed, and returned from the mp::ConnectStream(loop, socket) function and meant to be used directly. The classes implement methods described in .capnp definitions, and whenever any method is called, a request with the method arguments is sent over the associated IPC connection, and the corresponding wrapped_object method on the other end of the connection is called, with the ProxyClient method blocking until it returns and forwarding back any return value to the ProxyClient method caller.

Example

A simple interface description can be found at test/mp/test/foo.capnp, implementation in test/mp/test/foo.h, and usage in test/mp/test/test.cpp.

A more complete example can be found in example and run with:

mkdir build
cd build
cmake ..
make mpexamples
example/mpexample