Flow-IPC 1.0.2
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 // Constructors/destructor.
54
55 /**
56 * Default ctor: Creates a peer object in NULL (neither connected nor connecting) state.
57 *
58 * All notes from sync_io::Native_handle_sender apply.
59 */
61
62 /**
63 * Move-constructs from `src`; `src` becomes as-if default-cted (therefore in NULL state).
64 * All notes from sync_io::Native_handle_sender apply.
65 *
66 * @param src
67 * See above.
68 */
70
71 /// Disallow copying.
72 Blob_sender(const Blob_sender&) = delete;
73
74 /**
75 * Destroys this peer endpoint which will end the conceptual outgoing-direction pipe (in PEER state, and if it's
76 * still active) and return resources to OS as applicable.
77 *
78 * All notes from sync_io::Native_handle_sender apply.
79 */
81
82 // Methods.
83
84 /**
85 * Move-assigns from `src`; `*this` acts as if destructed; `src` becomes as-if default-cted (therefore in NULL state).
86 * No-op if `&src == this`.
87 *
88 * All notes from sync_io::Native_handle_sender apply.
89 *
90 * @param src
91 * See above.
92 * @return `*this`.
93 */
95 // Methods.
96
97 /// Disallow copying.
99
100 // `sync_io`-pattern API.
101
102 /**
103 * Coincides with sync_io::Native_handle_sender concept counterpart. All notes apply.
104 *
105 * @tparam Create_ev_wait_hndl_func
106 * See above.
107 * @param create_ev_wait_hndl_func
108 * See above.
109 * @return See above.
110 */
111 template<typename Create_ev_wait_hndl_func>
112 bool replace_event_wait_handles(const Create_ev_wait_hndl_func& create_ev_wait_hndl_func);
113
114 /**
115 * All notes from sync_io::Native_handle_sender::start_send_native_handle_ops() apply.
116 *
117 * @tparam Event_wait_func_t
118 * See above.
119 * @param ev_wait_func
120 * See above.
121 * @return See above.
122 */
123 template<typename Event_wait_func_t>
124 bool start_send_blob_ops(Event_wait_func_t&& ev_wait_func);
125
126 // General API (mirrors transport:: counterpart).
127
128 /**
129 * All notes from sync_io::Native_handle_sender apply.
130 *
131 * @return See above.
132 */
133 size_t send_blob_max_size() const;
134
135 /**
136 * In PEER state: Synchronously, non-blockingly sends one discrete message, reliably and in-order, to the opposing
137 * peer; the message consists of the provided binary blob (of length at least 1 byte). Providing a null blob
138 * results in undefined behavior (assertion may trip).
139 *
140 * Otherwise all notes from sync_io::Native_handle_sender::send_native_handle() apply.
141 *
142 * @param blob
143 * A binary blob to send; behavior undefined unless `blob.size() >= 1`.
144 * @param err_code
145 * See above.
146 * @return See above.
147 */
148 bool send_blob(const util::Blob_const& blob, Error_code* err_code = 0);
149
150 /**
151 * Equivalent to send_blob() but sends a graceful-close message instead of the usual payload.
152 * All notes from sync_io::Native_handle_sender apply.
153 *
154 * @tparam Task_err
155 * See above.
156 * @param sync_err_code
157 * See above.
158 * Do realize error::Code::S_SYNC_IO_WOULD_BLOCK *is* still an error, so if this pointer is null, then
159 * would-block *will* make this throw.
160 * @param on_done_func
161 * See above.
162 * @return See above.
163 */
164 template<typename Task_err>
165 bool async_end_sending(Error_code* sync_err_code, Task_err&& on_done_func);
166
167 /**
168 * Equivalent to `async_end_sending(F)` wherein `F()` does nothing.
169 *
170 * All notes from sync_io::Native_handle_sender apply.
171 *
172 * @return See above.
173 */
175
176 /**
177 * In PEER state: Irreversibly enables periodic auto-pinging of opposing receiver with low-level messages that
178 * are ignored except that they reset any opposing idle timer.
179 *
180 * All notes from sync_io::Native_handle_sender apply.
181 *
182 * @param period
183 * See above.
184 * @return See above.
185 */
186 bool auto_ping();
187}; // class Blob_sender
188
189/**
190 * A documentation-only *concept*: what transport::Blob_receiver is to transport::Native_handle_receiver (namely a
191 * degenerate version thereof), this is to sync_io::Native_handle_receiver.
192 *
193 * The concept is exactly identical to Native_handle_receiver except that in the latter each message consists
194 * of 0-1 native handles and 0-1 binary blobs; whereas here it is always exactly 1 of the latter. More precisely,
195 * each message contains 1 binary blob, whose length must be at least 1 byte.
196 *
197 * Therefore we keep the documentation very light, only pointing out the differences against
198 * sync_io::Native_handle_receiver -- which are summarized in the preceding paragraph. All other notes from
199 * sync_io::Native_handle_receiver apply here.
200 *
201 * @see sync_io::Native_handle_receiver, an identical concept with 1 feature (native handle transmission) added.
202 */
204{
205public:
206 // Constants.
207
208 /// Same notes as for transport::Blob_receiver.
210
211 /// Same notes as for transport::Blob_receiver.
212 static constexpr bool S_BLOB_UNDERFLOW_ALLOWED = value;
213
214 // Constructors/destructor.
215
216 /**
217 * Default ctor: Creates a peer object in NULL (neither connected nor connecting) state.
218 *
219 * All notes from sync_io::Native_handle_receiver apply.
220 */
222
223 /**
224 * Move-constructs from `src`; `src` becomes as-if default-cted (therefore in NULL state).
225 * All notes from sync_io::Native_handle_receiver apply.
226 *
227 * @param src
228 * See above.
229 */
231
232 /// Disallow copying.
233 Blob_receiver(const Blob_receiver&) = delete;
234
235 /**
236 * Destroys this peer endpoint which will end the conceptual outgoing-direction pipe (in PEER state, and if it's
237 * still active) and return resources to OS as applicable.
238 *
239 * All notes from sync_io::Native_handle_receiver apply.
240 */
242
243 // Methods.
244
245 /**
246 * Move-assigns from `src`; `*this` acts as if destructed; `src` becomes as-if default-cted (therefore in NULL state).
247 * No-op if `&src == this`.
248 *
249 * All notes from sync_io::Native_handle_receiver apply.
250 *
251 * @param src
252 * See above.
253 * @return `*this`.
254 */
256
257 /// Disallow copying.
259
260 // `sync_io`-pattern API.
261
262 /**
263 * Coincides with sync_io::Native_handle_receiver concept counterpart. All notes apply.
264 *
265 * @tparam Create_ev_wait_hndl_func
266 * See above.
267 * @param create_ev_wait_hndl_func
268 * See above.
269 * @return See above.
270 */
271 template<typename Create_ev_wait_hndl_func>
272 bool replace_event_wait_handles(const Create_ev_wait_hndl_func& create_ev_wait_hndl_func);
273
274 /**
275 * All notes from sync_io::Native_handle_receiver::start_receive_native_handle_ops() apply.
276 *
277 * @tparam Event_wait_func_t
278 * See above.
279 * @param ev_wait_func
280 * See above.
281 * @return See above.
282 */
283 template<typename Event_wait_func_t>
284 bool start_receive_blob_ops(Event_wait_func_t&& ev_wait_func);
285
286 // General API (mirrors transport:: counterpart).
287
288 /**
289 * All notes from sync_io::Native_handle_receiver::receive_meta_blob_max_size() apply.
290 *
291 * @return See above.
292 */
293 size_t receive_blob_max_size() const;
294
295 /**
296 * In PEER state: Possibly-asynchronously awaits one discrete message -- as sent by the opposing peer -- and
297 * receives it into the given target locations, reliably and in-order.
298 *
299 * Otherwise all notes from sync_io::Native_handle_receiver::async_receive_native_handle() apply.
300 *
301 * @tparam Task_err_sz
302 * See above.
303 * @param target_blob
304 * `target_blob.data()...` shall be written to before `on_done_func()` is executed with a falsy
305 * code, bytes numbering `N`, where `N` is passed to that callback. `N` shall not exceed
306 * `target_blob.size()`. See "Error semantics" (there is an `Error_code` regarding
307 * overflowing the user's memory area).
308 * @param sync_err_code
309 * See above.
310 * Do realize error::Code::S_SYNC_IO_WOULD_BLOCK *is* still an error, so if this pointer is null, then
311 * would-block *will* make this throw.
312 * @param sync_sz
313 * See above. If null behavior undefined (assertion may trip).
314 * @param on_done_func
315 * See above.
316 * @return See above.
317 */
318 template<typename Task_err_sz>
319 bool async_receive_blob(const util::Blob_mutable& target_blob,
320 Error_code* sync_err_code, size_t* sync_sz,
321 Task_err_sz&& on_done_func);
322
323 /**
324 * In PEER state: Irreversibly enables a conceptual idle timer whose potential side effect is, once at least
325 * the specified time has passed since the last received low-level traffic (or this call, whichever most
326 * recently occurred), to emit the pipe-hosing error error::Code::S_RECEIVER_IDLE_TIMEOUT.
327 *
328 * All notes from sync_io::Native_handle_receiver apply.
329 *
330 * @param timeout
331 * See above.
332 * @return See above.
333 */
335}; // class Blob_receiver
336
337} // namespace ipc::transport::sync_io
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).
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 outgoing-direction pipe (in PEER state,...
bool idle_timer_run(util::Fine_duration timeout)
In PEER state: Irreversibly enables a conceptual idle timer whose potential side effect is,...
Blob_receiver()
Default ctor: Creates a peer object in NULL (neither connected nor connecting) state.
Blob_receiver(const Blob_receiver &)=delete
Disallow copying.
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...
static const Shared_name S_RESOURCE_TYPE_ID
Same notes as for transport::Blob_sender.
bool end_sending()
Equivalent to async_end_sending(F) wherein F() does nothing.
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.
bool auto_ping()
In PEER state: Irreversibly enables periodic auto-pinging of opposing receiver with low-level message...
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(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 an mutable blob somewhere in memory, stored as exactly a void* and a size_t.
Definition: util_fwd.hpp:140
flow::Fine_duration Fine_duration
Short-hand for Flow's Fine_duration.
Definition: util_fwd.hpp:117
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:134
flow::Error_code Error_code
Short-hand for flow::Error_code which is very common.
Definition: common.hpp:298