Flow-IPC 1.0.1
Flow-IPC project: Public API.
|
ipc::session sub-namespace that groups together facilities for SHM-backed sessions, particularly augmenting Client_session, Server_session, and Session_server classes by providing SHM-backed zero-copy functionality. More...
Namespaces | |
namespace | arena_lend |
Bundles ipc::session::shm support for the various arena-lend-style SHM-providers, as of this writing at least ipc::session::shm::arena_lend::jemalloc. | |
namespace | classic |
Support for SHM-backed ipc::session sessions and session-servers with the SHM-classic (ipc::shm::classic::Pool_arena) provider. | |
Classes | |
struct | Arena_to_shm_session |
Implementation of Arena_to_shm_session_t. More... | |
struct | Arena_to_shm_session< ipc::shm::arena_lend::jemalloc::Ipc_arena > |
Implementation of Arena_to_shm_session_t for SHM-jemalloc arenas. More... | |
struct | Arena_to_shm_session< ipc::shm::classic::Pool_arena > |
Implementation of Arena_to_shm_session_t for SHM-classic arenas. More... | |
Typedefs | |
template<typename Arena > | |
using | Arena_to_shm_session_t = typename Arena_to_shm_session< Arena >::Type |
Alias that, given an Arena type (with Arena::construct<T>() which allocates/constructs a T ), yields a Shm_session type over which one can Shm_session::lend_object<T>() so-constructed objects. More... | |
ipc::session sub-namespace that groups together facilities for SHM-backed sessions, particularly augmenting Client_session, Server_session, and Session_server classes by providing SHM-backed zero-copy functionality.
ipc::session::shm is itself empty or almost empty; but for each possible SHM provider there is a further sub-namespace; for example ipc::session::shm::classic.
ipc::shm provides SHM facilities, including ipc::shm::classic and ipc::shm::arena_lend::jemalloc, that can be used stand-alone, without ipc::session. As with ipc::transport, though, this is not very convenient. ipc::session is well integrated with ipc::shm in that it provides certain pre-made arenas and simplifies transmission of handles to SHM-constructed objects and allows to place transport::struc::Channel out-messages into SHM instead of heap – achieving full zero-copy if desired. ipc::session::shm is where this support lives.
If you want these features, everything in the "Overview of relevant APIs" section (of ipc::session doc header) still applies identically, except you shall choose different types rather than Client_session, Server_session, Session_server. Firstly decide which SHM-provider; as of this writing ipc::shm::classic::Pool_arena or ipc::shm::arena_lend::jemalloc. For illustration let's assume you chose the former. Then:
We strongly recommend making yourself aliases as shown below, then from that point on obtaining all subsequent ipc::session types via aliases contained within those aliases (and then more aliases off those aliases as needed). The idea is to have only one point in the code where the SHM-backing (or no SHM backing) of the system are specified (simply by indicating the namespace of the top-level Session_server
or Client_session
type of choice), so that it can be easily changed to another, a-la generic programming.
Server-side:
Client-side:
Entering PEER state is exactly identical to the vanilla APIs (the differences are under the hood). Once in PEER state, however, the added capabilities become available; these are on top of the Session concept API, in the form added members including methods. A quick survey:
construct<T>(...)
on either to SHM-construct an object. Use an STL-compliant T
with Session::Allocator
and shm::stl::Arena_activator aids to store sophisticated data structures in SHM. Use shm::classic::Session_mv::lend_object() to prepare to transmit an outer SHM-handle to such a T
to the opposing shm::classic::Session. On that side use shm::classic::Session_mv::borrow_object() to recover an equivalent outer SHM-handle. The T
shall be returned to the SHM-arena once both processes are done with it. The handle acts like a cross-process-GCing shared_ptr
(and is, in fact, shared_ptr<T>
).T
in terms of "Session::Borrower_allocator"
instead of "Session::Allocator"
. (With SHM-classic they are the same type; but with arena-lending SHM providers, SHM-jemalloc at the moment, they are not.)send()
and receive it, only a small handle will be copied into and out of the IPC transport (again invisibly to you; it'll just happen). To set it up simply use transport::struc::Channel_base::Serialize_via_session_shm
-tag (or possibly Serialize_via_app_shm
-tag) ctor of struc::Channel
.That's with SHM-classic. With SHM-jemalloc it is all quite similar; basically just replace classic
with arena_lend::jemalloc
in various names above (more or less). Reminder: it is easiest and most stylish to not have to a big search/replace but rather to use the top-level alias technique shown in the above code snippets.
Further details about SHM-classic versus SHM-jemalloc (etc.) are documented elsewhere. Preview: arena_lend::jemalloc
is safer and faster (backed by the commercial-grade "jemalloc" malloc()
impl algorithm), though it does not allow app_shm()->construct()
(per-app-scope allocation) on the client side (via shm::arena_lend::jemalloc::Client_session – available only shm::arena_lend::jemalloc::Server_session); there's no such method as shm::arena_lend::jemalloc::Client_session::app_shm()
.
This is really a footnote in importance, though there's no good reason to ignore it either. A certain aspect of SHM-jemalloc (and potentially more future arena-lending-type SHM-providers) requires singleton-based (essentially, global) operation. You need not worry about it... it just works... except it (like all Flow-IPC code) logs; and thus needs to know to which Logger
to log. Since various ipc::session objects don't want to presume whose Logger
is the one to impose on this shared global guy – plus the setter is not thread-safe – we ask that you do so sometime before any ipc::session::arena_lend object creation. Namely just do this:
If SHM-jemalloc is not used, this call is harmless.
using ipc::session::shm::Arena_to_shm_session_t = typedef typename Arena_to_shm_session<Arena>::Type |
Alias that, given an Arena
type (with Arena::construct<T>()
which allocates/constructs a T
), yields a Shm_session
type over which one can Shm_session::lend_object<T>()
so-constructed objects.
Informally, for informational convenience:
Arena
. Hence they will map Arena
to itself. The Arena
object also acts as the Shm_session
.Arena
to a different dedicated Shm_session
type.Arena | SHM arena type that has method of the form shared_ptr<T> construct<T>(...) . |