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