Flow-IPC 3.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
22static_assert(false, "As of this writing this is a documentation-only \"header\" "
23 "(the \"source\" is for humans and Doxygen only).");
24#else // ifdef IPC_DOXYGEN_ONLY
25
27{
28
29// Types.
30
31/**
32 * A documentation-only *concept*: what transport::Blob_sender is to transport::Native_handle_sender (namely a
33 * degenerate version thereof), this is to sync_io::Native_handle_sender.
34 *
35 * The concept is exactly identical to sync_io::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.
38 *
39 * Therefore we keep the documentation very light, only pointing out the differences against
40 * sync_io::Native_handle_sender -- which are summarized in the preceding paragraph. All other notes from
41 * sync_io::Native_handle_sender apply here.
42 *
43 * @see sync_io::Native_handle_sender, an identical concept with 1 feature (native handle transmission) added.
44 */
46{
47public:
48 // Constants.
49
50 /// Same notes as for transport::Blob_sender.
52
53 // Types.
54
55 /**
56 * Return type, typically a `struct`, for blob_send_stats().
57 *
58 * All notes from transport::Blob_sender::Blob_snd_stats doc header apply verbatim.
59 */
60 using Blob_snd_stats = value;
61
62 // Constructors/destructor.
63
64 /**
65 * Default ctor: Creates a peer object in NULL (neither connected nor connecting) state.
66 *
67 * All notes from sync_io::Native_handle_sender apply.
68 */
70
71 /**
72 * Move-constructs from `src`; `src` becomes as-if default-cted (therefore in NULL state).
73 * All notes from sync_io::Native_handle_sender apply.
74 *
75 * @param src
76 * See above.
77 */
79
80 /// Disallow copying.
81 Blob_sender(const Blob_sender&) = delete;
82
83 /**
84 * Destroys this peer endpoint which will end the conceptual outgoing-direction pipe (in PEER state, and if it's
85 * still active) and return resources to OS as applicable.
86 *
87 * All notes from sync_io::Native_handle_sender apply.
88 */
90
91 // Methods.
92
93 /**
94 * Move-assigns from `src`; `*this` acts as if destructed; `src` becomes as-if default-cted (therefore in NULL state).
95 * No-op if `&src == this`.
96 *
97 * All notes from sync_io::Native_handle_sender apply.
98 *
99 * @param src
100 * See above.
101 * @return `*this`.
102 */
104
105 /// Disallow copying.
107
108 // `sync_io`-pattern API.
109
110 /**
111 * Coincides with sync_io::Native_handle_sender concept counterpart. All notes apply.
112 *
113 * @tparam Create_ev_wait_hndl_func
114 * See above.
115 * @param create_ev_wait_hndl_func
116 * See above.
117 * @return See above.
118 */
119 template<typename Create_ev_wait_hndl_func>
120 bool replace_event_wait_handles(const Create_ev_wait_hndl_func& create_ev_wait_hndl_func);
121
122 /**
123 * All notes from sync_io::Native_handle_sender::start_send_native_handle_ops() apply.
124 *
125 * @tparam Event_wait_func_t
126 * See above.
127 * @param ev_wait_func
128 * See above.
129 * @return See above.
130 */
131 template<typename Event_wait_func_t>
132 bool start_send_blob_ops(Event_wait_func_t&& ev_wait_func);
133
134 // General API (mirrors transport:: counterpart).
135
136 /**
137 * All notes from sync_io::Native_handle_sender apply.
138 *
139 * @return See above.
140 */
141 size_t send_blob_max_size() const;
142
143 /**
144 * In PEER state: Synchronously, non-blockingly sends one discrete message, reliably and in-order, to the opposing
145 * peer; the message consists of the provided binary blob (of length at least 1 byte). Providing a null blob
146 * results in undefined behavior (assertion may trip).
147 *
148 * Otherwise all notes from sync_io::Native_handle_sender::send_native_handle() apply.
149 *
150 * @param blob
151 * A binary blob to send; behavior undefined unless `blob.size() >= 1`.
152 * @param err_code
153 * See above.
154 * @return See above.
155 */
156 bool send_blob(const util::Blob_const& blob, Error_code* err_code = nullptr);
157
158 /**
159 * Equivalent to send_blob() but sends a graceful-close message instead of the usual payload.
160 * All notes from sync_io::Native_handle_sender apply.
161 *
162 * @tparam Task_err
163 * See above.
164 * @param sync_err_code
165 * See above.
166 * Do realize error::Code::S_SYNC_IO_WOULD_BLOCK *is* still an error, so if this pointer is null, then
167 * would-block *will* make this throw.
168 * @param on_done_func
169 * See above.
170 * @return See above.
171 */
172 template<typename Task_err>
173 bool async_end_sending(Error_code* sync_err_code, Task_err&& on_done_func);
174
175 /**
176 * Equivalent to `async_end_sending(&E, F)` wherein `F()` does nothing, and `E` is some `Error_code` "sink"
177 * ignored by the caller.
178 *
179 * All notes from sync_io::Native_handle_sender apply.
180 *
181 * @return See above.
182 */
184
185 /**
186 * In PEER state: Irreversibly enables periodic auto-pinging of opposing receiver with low-level messages that
187 * are ignored except that they reset any opposing idle timer.
188 *
189 * All notes from sync_io::Native_handle_sender apply.
190 *
191 * @param period
192 * See above.
193 * @return See above.
194 */
195 bool auto_ping(util::Fine_duration period = default_value);
196
197 /**
198 * Returns the accumulated transport statistics as of this call.
199 * If not in PEER state returns a zeroed-out stats object.
200 *
201 * All notes from sync_io::Native_handle_sender apply.
202 *
203 * @return See above.
204 */
206
207 /**
208 * Resets the transport statistics as of this call. The formal meaning of a reset is discussed in
209 * `flow::util::stat` doc header. If not in PEER state this is a no-op.
210 */
212}; // class Blob_sender
213
214/**
215 * A documentation-only *concept*: what transport::Blob_receiver is to transport::Native_handle_receiver (namely a
216 * degenerate version thereof), this is to sync_io::Native_handle_receiver.
217 *
218 * The concept is exactly identical to Native_handle_receiver except that in the latter each message consists
219 * of 0-1 native handles and 0-1 binary blobs; whereas here it is always exactly 1 of the latter. More precisely,
220 * each message contains 1 binary blob, whose length must be at least 1 byte.
221 *
222 * Therefore we keep the documentation very light, only pointing out the differences against
223 * sync_io::Native_handle_receiver -- which are summarized in the preceding paragraph. All other notes from
224 * sync_io::Native_handle_receiver apply here.
225 *
226 * @see sync_io::Native_handle_receiver, an identical concept with 1 feature (native handle transmission) added.
227 */
229{
230public:
231 // Constants.
232
233 /// Same notes as for transport::Blob_receiver.
235
236 /// Same notes as for transport::Blob_receiver.
237 static constexpr bool S_BLOB_UNDERFLOW_ALLOWED = value;
238
239 /// Same notes as for transport::Blob_receiver.
240 static constexpr size_t S_RCV_BLOB_BATCH_SZ_RECOMMENDATION = value;
241
242 // Types.
243
244 /// See `async_receive_*_batch()` argument `batch`.
245 template<typename Msg_resource>
247
248 /**
249 * Return type, typically a `struct`, for blob_receive_stats().
250 *
251 * All notes from transport::Blob_receiver::Blob_rcv_stats doc header apply verbatim.
252 */
253 using Blob_rcv_stats = value;
254
255 // Constructors/destructor.
256
257 /**
258 * Default ctor: Creates a peer object in NULL (neither connected nor connecting) state.
259 *
260 * All notes from sync_io::Native_handle_receiver apply.
261 */
263
264 /**
265 * Move-constructs from `src`; `src` becomes as-if default-cted (therefore in NULL state).
266 * All notes from sync_io::Native_handle_receiver apply.
267 *
268 * @param src
269 * See above.
270 */
272
273 /// Disallow copying.
274 Blob_receiver(const Blob_receiver&) = delete;
275
276 /**
277 * Destroys this peer endpoint which will end the conceptual incoming-direction pipe (in PEER state, and if it's
278 * still active) and return resources to OS as applicable.
279 *
280 * All notes from sync_io::Native_handle_receiver apply.
281 */
283
284 // Methods.
285
286 /**
287 * Move-assigns from `src`; `*this` acts as if destructed; `src` becomes as-if default-cted (therefore in NULL state).
288 * No-op if `&src == this`.
289 *
290 * All notes from sync_io::Native_handle_receiver apply.
291 *
292 * @param src
293 * See above.
294 * @return `*this`.
295 */
297
298 /// Disallow copying.
300
301 // `sync_io`-pattern API.
302
303 /**
304 * Coincides with sync_io::Native_handle_receiver concept counterpart. All notes apply.
305 *
306 * @tparam Create_ev_wait_hndl_func
307 * See above.
308 * @param create_ev_wait_hndl_func
309 * See above.
310 * @return See above.
311 */
312 template<typename Create_ev_wait_hndl_func>
313 bool replace_event_wait_handles(const Create_ev_wait_hndl_func& create_ev_wait_hndl_func);
314
315 /**
316 * All notes from sync_io::Native_handle_receiver::start_receive_native_handle_ops() apply.
317 *
318 * @tparam Event_wait_func_t
319 * See above.
320 * @param ev_wait_func
321 * See above.
322 * @return See above.
323 */
324 template<typename Event_wait_func_t>
325 bool start_receive_blob_ops(Event_wait_func_t&& ev_wait_func);
326
327 // General API (mirrors transport:: counterpart).
328
329 /**
330 * All notes from sync_io::Native_handle_receiver::receive_meta_blob_max_size() apply.
331 *
332 * @return See above.
333 */
334 size_t receive_blob_max_size() const;
335
336 /**
337 * In PEER state: Possibly-asynchronously awaits one discrete message -- as sent by the opposing peer -- and
338 * receives it into the given target locations, reliably and in-order.
339 *
340 * Otherwise all notes from sync_io::Native_handle_receiver::async_receive_native_handle() apply.
341 *
342 * @tparam Task_err_sz
343 * See above.
344 * @param target_blob
345 * `target_blob.data()...` shall be written to before `on_done_func()` is executed with a falsy
346 * code, bytes numbering `N`, where `N` is passed to that callback. `N` shall not exceed
347 * `target_blob.size()`. See "Error semantics" (there is an `Error_code` regarding
348 * overflowing the user's memory area).
349 * @param sync_err_code
350 * See above.
351 * Do realize error::Code::S_SYNC_IO_WOULD_BLOCK *is* still an error, so if this pointer is null, then
352 * would-block *will* make this throw.
353 * @param sync_sz
354 * See above. If null behavior undefined (assertion may trip).
355 * @param on_done_func
356 * See above.
357 * @return See above.
358 */
359 template<typename Task_err_sz>
360 bool async_receive_blob(const util::Blob_mutable& target_blob,
361 Error_code* sync_err_code, size_t* sync_sz,
362 Task_err_sz&& on_done_func);
363
364 /**
365 * In PEER state: Identical to sync_io::Native_handle_receiver::async_receive_native_handle_batch(); except that
366 * since `Msg_batch_in<..., true>` (note the `true`) is the type of `*batch`, only blobs (not `Native_handle`s)
367 * can be received.
368 *
369 * @tparam Msg_resource
370 * See above.
371 * @tparam Task_err
372 * See above.
373 * @param batch
374 * See above.
375 * @param assume_would_block
376 * See above.
377 * @param sync_err_code
378 * See above.
379 * Do realize error::Code::S_SYNC_IO_WOULD_BLOCK *is* still an error, so if this pointer is null, then
380 * would-block *will* make this throw.
381 * @param on_done_func
382 * See above.
383 * @return See above.
384 */
385 template<typename Msg_resource, typename Task_err>
386 bool async_receive_blob_batch(Blob_batch_in<Msg_resource>* batch, bool assume_would_block,
387 Error_code* sync_err_code, Task_err&& on_done_func);
388
389 /**
390 * In PEER state: Irreversibly enables a conceptual idle timer whose potential side effect is, once at least
391 * the specified time has passed since the last received low-level traffic (or this call, whichever most
392 * recently occurred), to emit the pipe-hosing error error::Code::S_RECEIVER_IDLE_TIMEOUT.
393 *
394 * All notes from sync_io::Native_handle_receiver apply.
395 *
396 * @param timeout
397 * See above.
398 * @return See above.
399 */
400 bool idle_timer_run(util::Fine_duration timeout = default_value);
401
402 /**
403 * Returns the accumulated transport statistics as of this call.
404 * If not in PEER state returns a zeroed-out stats object.
405 *
406 * All notes from sync_io::Native_handle_receiver apply.
407 *
408 * @return See above.
409 */
411
412 /**
413 * Resets the transport statistics as of this call. The formal meaning of a reset is discussed in
414 * `flow::util::stat` doc header. If not in PEER state this is a no-op.
415 */
417}; // class Blob_receiver
418
419} // namespace ipc::transport::sync_io
420
421#endif // ifdef IPC_DOXYGEN_ONLY
A documentation-only concept defining the behavior of an object that is a key aspect of batch-receivi...
A documentation-only concept: what transport::Blob_receiver is to transport::Native_handle_receiver (...
Blob_receiver(Blob_receiver &&src)
Move-constructs from src; src becomes as-if default-cted (therefore in NULL state).
void blob_receive_stats_reset()
Resets the transport statistics as of this call.
value Blob_rcv_stats
Return type, typically a struct, for blob_receive_stats().
bool replace_event_wait_handles(const Create_ev_wait_hndl_func &create_ev_wait_hndl_func)
Coincides with sync_io::Native_handle_receiver concept counterpart.
static const Shared_name S_RESOURCE_TYPE_ID
Same notes as for transport::Blob_receiver.
~Blob_receiver()
Destroys this peer endpoint which will end the conceptual incoming-direction pipe (in PEER state,...
Blob_receiver()
Default ctor: Creates a peer object in NULL (neither connected nor connecting) state.
Blob_receiver(const Blob_receiver &)=delete
Disallow copying.
bool idle_timer_run(util::Fine_duration timeout=default_value)
In PEER state: Irreversibly enables a conceptual idle timer whose potential side effect is,...
static constexpr size_t S_RCV_BLOB_BATCH_SZ_RECOMMENDATION
Same notes as for transport::Blob_receiver.
bool async_receive_blob_batch(Blob_batch_in< Msg_resource > *batch, bool assume_would_block, Error_code *sync_err_code, Task_err &&on_done_func)
In PEER state: Identical to sync_io::Native_handle_receiver::async_receive_native_handle_batch(); exc...
Blob_rcv_stats blob_receive_stats() const
Returns the accumulated transport statistics as of this call.
static constexpr bool S_BLOB_UNDERFLOW_ALLOWED
Same notes as for transport::Blob_receiver.
size_t receive_blob_max_size() const
All notes from sync_io::Native_handle_receiver::receive_meta_blob_max_size() apply.
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 & operator=(const Blob_receiver &)=delete
Disallow copying.
bool async_receive_blob(const util::Blob_mutable &target_blob, Error_code *sync_err_code, size_t *sync_sz, Task_err_sz &&on_done_func)
In PEER state: Possibly-asynchronously awaits one discrete message – as sent by the opposing peer – a...
bool start_receive_blob_ops(Event_wait_func_t &&ev_wait_func)
All notes from sync_io::Native_handle_receiver::start_receive_native_handle_ops() apply.
A documentation-only concept: what transport::Blob_sender is to transport::Native_handle_sender (name...
bool replace_event_wait_handles(const Create_ev_wait_hndl_func &create_ev_wait_hndl_func)
Coincides with sync_io::Native_handle_sender concept counterpart.
Blob_sender & operator=(Blob_sender &&src)
Move-assigns from src; *this acts as if destructed; src becomes as-if default-cted (therefore in NULL...
Blob_snd_stats blob_send_stats() const
Returns the accumulated transport statistics as of this call.
bool send_blob(const util::Blob_const &blob, Error_code *err_code=nullptr)
In PEER state: Synchronously, non-blockingly sends one discrete message, reliably and in-order,...
void blob_send_stats_reset()
Resets the transport statistics as of this call.
static const Shared_name S_RESOURCE_TYPE_ID
Same notes as for transport::Blob_sender.
bool end_sending()
Equivalent to async_end_sending(&E, F) wherein F() does nothing, and E is some Error_code "sink" igno...
size_t send_blob_max_size() const
All notes from sync_io::Native_handle_sender apply.
~Blob_sender()
Destroys this peer endpoint which will end the conceptual outgoing-direction pipe (in PEER state,...
Blob_sender(Blob_sender &&src)
Move-constructs from src; src becomes as-if default-cted (therefore in NULL state).
bool async_end_sending(Error_code *sync_err_code, Task_err &&on_done_func)
Equivalent to send_blob() but sends a graceful-close message instead of the usual payload.
bool start_send_blob_ops(Event_wait_func_t &&ev_wait_func)
All notes from sync_io::Native_handle_sender::start_send_native_handle_ops() apply.
Blob_sender()
Default ctor: Creates a peer object in NULL (neither connected nor connecting) state.
value Blob_snd_stats
Return type, typically a struct, for blob_send_stats().
Blob_sender & operator=(const Blob_sender &)=delete
Disallow copying.
bool auto_ping(util::Fine_duration period=default_value)
In PEER state: Irreversibly enables periodic auto-pinging of opposing receiver with low-level message...
Blob_sender(const Blob_sender &)=delete
Disallow copying.
String-wrapping abstraction representing a name uniquely distinguishing a kernel-persistent entity fr...
sync_io-pattern counterparts to async-I/O-pattern object types in parent namespace ipc::transport.
boost::asio::mutable_buffer Blob_mutable
Short-hand for a mutable blob somewhere in memory, stored as exactly a void* and a size_t.
Definition: util_fwd.hpp:137
flow::Fine_duration Fine_duration
Short-hand for Flow's Fine_duration.
Definition: util_fwd.hpp:114
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:131
flow::Error_code Error_code
Short-hand for flow::Error_code which is very common.
Definition: common.hpp:313