Flow-IPC 1.0.0
Flow-IPC project: Full implementation reference.
blob_transport.hpp
Go to the documentation of this file.
1/* Flow-IPC: Core
2 * Copyright 2023 Akamai Technologies, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the
5 * "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in
12 * writing, software distributed under the License is
13 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14 * CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing
16 * permissions and limitations under the License. */
17
18/// @file
19
20// Not compiled: for documentation only. Contains concept docs as of this writing.
21#ifndef IPC_DOXYGEN_ONLY
22# error "As of this writing this is a documentation-only "header" (the "source" is for humans and Doxygen only)."
23#else // ifdef IPC_DOXYGEN_ONLY
24
25namespace ipc::transport
26{
27
28// Types.
29
30/**
31 * A documentation-only *concept* defining the behavior of an object capable of reliably/in-order *sending* of
32 * discrete messages, each containing a binary blob. This is paired with
33 * the Blob_receiver concept which defines reception of such messages.
34 *
35 * The concept is exactly identical to Native_handle_sender except that in the latter each message consists
36 * of 0-1 native handles and 0-1 binary blobs; whereas here it is always exactly 1 of the latter. More precisely,
37 * each message contains 1 binary blob, whose length must be at least 1 byte. You may interpret notes in common-sense
38 * fashion; for example send_blob_max_size() here corresponds to `send_meta_blob_max_size()` there.
39 *
40 * Therefore we keep the documentation very light, only pointing out the differences against Native_handle_sender --
41 * which are summarized in the preceding paragraph. All other notes from Native_handle_sender apply here.
42 *
43 * @see Native_handle_sender, an identical concept with 1 feature (native handle transmission) added.
44 */
46{
47public:
48 // Constants.
49
50 /// Shared_name relative-folder fragment (no separators) identifying this resource type. Equals `_receiver`'s.
52
53 // Constructors/destructor.
54
55 /**
56 * Default ctor: Creates a peer object in NULL (neither connected nor connecting) state.
57 *
58 * All notes from Native_handle_sender() default ctor doc header apply.
59 */
61
62 /**
63 * `sync_io`-core-adopting ctor: Creates a peer object in PEER state by subsuming a `sync_io` core in that state.
64 *
65 * @param sync_io_core_in_peer_state_moved
66 * See Native_handle_sender concept.
67 */
68 Blob_sender(sync_io::Blob_sender&& sync_io_core_in_peer_state_moved);
69
70 /**
71 * Move-constructs from `src`; `src` becomes as-if default-cted (therefore in NULL state).
72 *
73 * @param src
74 * Source object. For reasonable uses of `src` after this ctor returns: see default ctor doc header.
75 */
77
78 /// Disallow copying.
79 Blob_sender(const Blob_sender&) = delete;
80
81 /**
82 * Destroys this peer endpoint which will end the conceptual outgoing-direction pipe (in PEER state, and if it
83 * is still active) and cancels any pending completion handlers by invoking them ASAP with
84 * error::Code::S_OBJECT_SHUTDOWN_ABORTED_COMPLETION_HANDLER.
85 *
86 * All notes from ~Native_handle_sender() doc header apply.
87 */
89
90 // Methods.
91
92 /**
93 * Move-assigns from `src`; `*this` acts as if destructed; `src` becomes as-if default-cted (therefore in NULL state).
94 * No-op if `&src == this`.
95 *
96 * @see ~Blob_sender().
97 *
98 * @param src
99 * Source object. For reasonable uses of `src` after this ctor returns: see default ctor doc header.
100 * @return `*this`.
101 */
103 // Methods.
104
105 /// Disallow copying.
107
108 /**
109 * In PEER state: Returns max `blob.size()` such that send_blob() shall not fail due to too-long
110 * payload with error::Code::S_INVALID_ARGUMENT. Always the same value once in PEER state. The opposing
111 * Native_handle_receiver::receive_blob_max_size()` shall return the same value (in the opposing object potentially
112 * in a different process).
113 *
114 * If `*this` is not in PEER state (in particular if it is default-cted or moved-from), returns zero; else
115 * a positive value.
116 *
117 * @return See above.
118 */
119 size_t send_blob_max_size() const;
120
121 /**
122 * In PEER state: Synchronously, non-blockingly sends one discrete message, reliably and in-order, to the opposing
123 * peer; the message consists of the provided binary blob (of length at least 1 byte). Providing a null blob
124 * results in undefined behavior (assertion may trip).
125 *
126 * All notes from Native_handle_sender::send_native_handle() doc header apply.
127 *
128 * @param blob
129 * A binary blob to send; behavior undefined unless `blob.size() >= 1`.
130 * @param err_code
131 * See above.
132 * @return See above.
133 */
134 bool send_blob(const util::Blob_const& blob, Error_code* err_code = 0);
135
136 /**
137 * Equivalent to send_blob() but sends a graceful-close message instead of the usual payload; the opposing
138 * peer's Blob_receiver shall receive it reliably and in-order via Blob_receiver::async_receive_blob() in the form of
139 * #Error_code = error::Code::S_RECEIVES_FINISHED_CANNOT_RECEIVE.
140 *
141 * All notes from Native_handle_sender::async_end_sending() doc header apply.
142 *
143 * @tparam Task_err
144 * See above.
145 * @param on_done_func
146 * See above.
147 * @return See above.
148 */
149 template<typename Task_err>
150 bool async_end_sending(Task_err&& on_done_func);
151
152 /**
153 * Equivalent to `async_end_sending(F)` wherein `F()` does nothing.
154 *
155 * All notes from Native_handle_sender::end_sending() doc header apply.
156 *
157 * @return See above.
158 */
160
161 /**
162 * In PEER state: Irreversibly enables periodic auto-pinging of opposing receiver with low-level messages that
163 * are ignored except that they reset any idle timer as enabled via Blob_receiver::idle_timer_run()
164 * (or similar).
165 *
166 * All notes from Native_handle_receiver::auto_ping() doc header apply.
167 *
168 * @param period
169 * See above.
170 * @return See above.
171 */
172 bool auto_ping();
173}; // class Blob_sender
174
175/**
176 * A documentation-only *concept* defining the behavior of an object capable of reliably/in-order *receiving* of
177 * discrete messages, each containing a binary blob. This is paired with
178 * the Blob_sender concept which defines sending of such messages.
179 *
180 * The concept is exactly identical to Native_handle_receiver except that in the latter each message consists
181 * of 0-1 native handles and 0-1 binary blobs; whereas here it is always exactly 1 of the latter. More precisely,
182 * each message contains 1 binary blob, whose length must be at least 1 byte. You may interpret notes in common-sense
183 * fashion; for example receive_blob_max_size() here corresponds to `receive_meta_blob_max_size()` there.
184 *
185 * Therefore we keep the documentation very light, only pointing out the differences against Native_handle_receiver --
186 * which are summarized in the preceding paragraph. All other notes from Native_handle_receiver apply here.
187 *
188 * @see Native_handle_receiver, an identical concept with 1 feature (native handle transmission) added.
189 */
191{
192public:
193 // Constants.
194
195 /// Shared_name relative-folder fragment (no separators) identifying this resource type. Equals `_sender`'s.
197
198 /**
199 * If `false` then `blob.size() > receive_blob_max_size()` in PEER-state async_receive_blob()
200 * shall yield non-pipe-hosing error::Code::INVALID_ARGUMENT, and it shall never yield
201 * pipe-hosing error::Code::S_MESSAGE_SIZE_EXCEEDS_USER_STORAGE; else the latter may occur, while the former
202 * shall never occur for that reason.
203 *
204 * @see "Blob underflow semantics" in Native_handle_sender concept doc header; they apply equally here.
205 */
206 static constexpr bool S_BLOB_UNDERFLOW_ALLOWED = value;
207
208 // Constructors/destructor.
209
210 /**
211 * Default ctor: Creates a peer object in NULL (neither connected nor connecting) state.
212 *
213 * All notes from Native_handle_receiver() default ctor doc header apply.
214 */
216
217 /**
218 * `sync_io`-core-adopting ctor: Creates a peer object in PEER state by subsuming a `sync_io` core in that state.
219 *
220 * @param sync_io_core_in_peer_state_moved
221 * See Native_handle_sender concept.
222 */
223 Blob_receiver(sync_io::Blob_receiver&& sync_io_core_in_peer_state_moved);
224
225 /**
226 * Move-constructs from `src`; `src` becomes as-if default-cted (therefore in NULL state).
227 *
228 * @param src
229 * Source object. For reasonable uses of `src` after this ctor returns: see default ctor doc header.
230 */
232
233 /// Disallow copying.
234 Blob_receiver(const Blob_receiver&) = delete;
235
236 /**
237 * Destroys this peer endpoint which will end the conceptual incoming-direction pipe (in PEER state, and if it
238 * is still active) and cancels any pending completion handlers by invoking them ASAP with
239 * error::Code::S_OBJECT_SHUTDOWN_ABORTED_COMPLETION_HANDLER.
240 *
241 * All notes from ~Native_handle_receiver() doc header apply.
242 */
244
245 // Methods.
246
247 /**
248 * Move-assigns from `src`; `*this` acts as if destructed; `src` becomes as-if default-cted (therefore in NULL state).
249 * No-op if `&src == this`.
250 *
251 * @see ~Blob_receiver().
252 *
253 * @param src
254 * Source object. For reasonable uses of `src` after this ctor returns: see default ctor doc header.
255 * @return `*this`.
256 */
258
259 /// Disallow copying.
261
262 /**
263 * In PEER state: Returns min `target_blob.size()` such that (1) async_receive_blob() shall not fail
264 * with error::Code::S_INVALID_ARGUMENT (only if #S_BLOB_UNDERFLOW_ALLOWED is `false`; otherwise not relevant),
265 * and (2) it shall *never* fail with error::Code::S_MESSAGE_SIZE_EXCEEDS_USER_STORAGE. Please see
266 * "Blob underflow semantics" (for Native_handle_receiver, but applied in common-sense fashion to us) for
267 * explanation of these semantics.
268 *
269 * Always the same value once in PEER state. The opposing
270 * Native_handle_sender::send_blob_max_size() shall return the same value (in the opposing object potentially
271 * in a different process).
272 *
273 * If `*this` is not in PEER state (in particular if it is default-cted or moved-from), returns zero; else
274 * a positive value.
275 *
276 * @return See above.
277 */
278 size_t receive_blob_max_size() const;
279
280 /**
281 * In PEER state: Asynchronously awaits one discrete message -- as sent by the opposing peer via
282 * Blob_sender::send_blob() or `"Blob_sender::*end_sending()"` -- and
283 * receives it into the given target locations, reliably and in-order.
284 *
285 * All notes from Native_handle_receiver::async_receive_native_handle() doc header apply. In particular
286 * watch out for the semantics regarding `target_blob.size()` and potential resulting errors.
287 *
288 * @tparam Task_err_sz
289 * See above.
290 * @param target_blob
291 * `target_blob.data()...` shall be written to by the time `on_done_func()` is executed with a falsy
292 * code, bytes numbering `N`, where `N` is passed to that callback. `N` shall not exceed
293 * `target_blob.size()`. See above.
294 * @param on_done_func
295 * See above.
296 * @return See above.
297 */
298 template<typename Task_err_sz>
299 bool async_receive_blob(const util::Blob_mutable& target_blob,
300 Task_err_sz&& on_done_func);
301
302 /**
303 * In PEER state: Irreversibly enables a conceptual idle timer whose potential side effect is, once at least
304 * the specified time has passed since the last received low-level traffic (or this call, whichever most
305 * recently occurred), to emit the pipe-hosing error error::Code::S_RECEIVER_IDLE_TIMEOUT.
306 *
307 * All notes from Native_handle_receiver::idle_timer_run() doc header apply.
308 *
309 * @param timeout
310 * See above.
311 * @return See above.
312 */
314}; // class Blob_receiver
315
316} // namespace ipc::transport
A documentation-only concept defining the behavior of an object capable of reliably/in-order receivin...
Blob_receiver()
Default ctor: Creates a peer object in NULL (neither connected nor connecting) state.
Blob_receiver(const Blob_receiver &)=delete
Disallow copying.
size_t receive_blob_max_size() const
In PEER state: Returns min target_blob.size() such that (1) async_receive_blob() shall not fail with ...
Blob_receiver & operator=(const Blob_receiver &)=delete
Disallow copying.
bool idle_timer_run(util::Fine_duration timeout)
In PEER state: Irreversibly enables a conceptual idle timer whose potential side effect is,...
Blob_receiver & operator=(Blob_receiver &&src)
Move-assigns from src; *this acts as if destructed; src becomes as-if default-cted (therefore in NULL...
Blob_receiver(sync_io::Blob_receiver &&sync_io_core_in_peer_state_moved)
sync_io-core-adopting ctor: Creates a peer object in PEER state by subsuming a sync_io core in that s...
static const Shared_name S_RESOURCE_TYPE_ID
Shared_name relative-folder fragment (no separators) identifying this resource type....
bool async_receive_blob(const util::Blob_mutable &target_blob, Task_err_sz &&on_done_func)
In PEER state: Asynchronously awaits one discrete message – as sent by the opposing peer via Blob_sen...
Blob_receiver(Blob_receiver &&src)
Move-constructs from src; src becomes as-if default-cted (therefore in NULL state).
static constexpr bool S_BLOB_UNDERFLOW_ALLOWED
If false then blob.size() > receive_blob_max_size() in PEER-state async_receive_blob() shall yield no...
~Blob_receiver()
Destroys this peer endpoint which will end the conceptual incoming-direction pipe (in PEER state,...
A documentation-only concept defining the behavior of an object capable of reliably/in-order sending ...
Blob_sender()
Default ctor: Creates a peer object in NULL (neither connected nor connecting) state.
bool end_sending()
Equivalent to async_end_sending(F) wherein F() does nothing.
Blob_sender(sync_io::Blob_sender &&sync_io_core_in_peer_state_moved)
sync_io-core-adopting ctor: Creates a peer object in PEER state by subsuming a sync_io core in that s...
bool async_end_sending(Task_err &&on_done_func)
Equivalent to send_blob() but sends a graceful-close message instead of the usual payload; the opposi...
Blob_sender(Blob_sender &&src)
Move-constructs from src; src becomes as-if default-cted (therefore in NULL state).
Blob_sender & operator=(const Blob_sender &)=delete
Disallow copying.
bool send_blob(const util::Blob_const &blob, Error_code *err_code=0)
In PEER state: Synchronously, non-blockingly sends one discrete message, reliably and in-order,...
~Blob_sender()
Destroys this peer endpoint which will end the conceptual outgoing-direction pipe (in PEER state,...
Blob_sender & operator=(Blob_sender &&src)
Move-assigns from src; *this acts as if destructed; src becomes as-if default-cted (therefore in NULL...
bool auto_ping()
In PEER state: Irreversibly enables periodic auto-pinging of opposing receiver with low-level message...
static const Shared_name S_RESOURCE_TYPE_ID
Shared_name relative-folder fragment (no separators) identifying this resource type....
size_t send_blob_max_size() const
In PEER state: Returns max blob.size() such that send_blob() shall not fail due to too-long payload w...
Blob_sender(const Blob_sender &)=delete
Disallow copying.
A documentation-only concept: what transport::Blob_receiver is to transport::Native_handle_receiver (...
A documentation-only concept: what transport::Blob_sender is to transport::Native_handle_sender (name...
String-wrapping abstraction representing a name uniquely distinguishing a kernel-persistent entity fr...
Flow-IPC module providing transmission of structured messages and/or low-level blobs (and more) betwe...
boost::asio::mutable_buffer Blob_mutable
Short-hand for an mutable blob somewhere in memory, stored as exactly a void* and a size_t.
Definition: util_fwd.hpp:134
flow::Fine_duration Fine_duration
Short-hand for Flow's Fine_duration.
Definition: util_fwd.hpp:111
boost::asio::const_buffer Blob_const
Short-hand for an immutable blob somewhere in memory, stored as exactly a void const * and a size_t.
Definition: util_fwd.hpp:128
flow::Error_code Error_code
Short-hand for flow::Error_code which is very common.
Definition: common.hpp:297