Flow-IPC 1.0.1
Flow-IPC project: Full implementation reference.
bipc_mq_handle.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#pragma once
20
22#include "ipc/util/util_fwd.hpp"
25#include <flow/log/log.hpp>
26
27namespace ipc::transport
28{
29
30// Types.
31
32/**
33 * Implements the Persistent_mq_handle concept by thinly wrapping `bipc::message_queue`, which is boost.interprocess's
34 * persistent message queue API. Internally `bipc::message_queue` maintains a boost.interprocess (classic)
35 * SHM pool which itself is a portable wrapper around a standard POSIX shared memory object.
36 *
37 * @see Persistent_mq_handle: implemented concept. Its doc header provides plenty of background for the present
38 * concrete class, since essentially that concept was inspired by `bipc::message_queue` in the first place.
39 * Therefore there is essentially no added documentation needed here.
40 *
41 * Reminder: This is available publicly in case it is useful; but it is more likely one would use a Blob_stream
42 * which provides a far more convenient boost.asio-like async-capable API. It uses class(es) like this one in
43 * its impl.
44 *
45 * @internal
46 * ### Implementation ###
47 * It is really a thin wrapper around `bipc::message_queue` as discussed above/in Persistent_mq_handle doc header.
48 * To the extent it adds its own intelligence, it's only about normalizing error reporting and adding logging.
49 */
50class Bipc_mq_handle : // Note: movable but not copyable.
51 public flow::log::Log_context
52{
53public:
54 // Constants.
55
56 /// Implements concept API.
58
59 /// Implements concept API.
60 static constexpr bool S_HAS_NATIVE_HANDLE = false;
61
62 // Constructors/destructor.
63
64 /// Implements Persistent_mq_handle API: Construct null handle.
66
67 /**
68 * Implements Persistent_mq_handle API: Construct handle to non-existing named MQ, creating it first. If it already
69 * exists, it is an error.
70 *
71 * @see Persistent_mq_handle::Persistent_mq_handle(): implemented concept.
72 *
73 * @param logger_ptr
74 * See above.
75 * @param absolute_name
76 * See above.
77 * @param mode_tag
78 * See above.
79 * @param perms
80 * See above.
81 * Reminder: Suggest the use of util::shared_resource_permissions() to translate
82 * from one of a small handful of levels of access; these apply almost always in practice.
83 * @param max_n_msg
84 * See above.
85 * @param max_msg_sz
86 * See above.
87 * @param err_code
88 * See above.
89 */
90 explicit Bipc_mq_handle(flow::log::Logger* logger_ptr, const Shared_name& absolute_name,
91 util::Create_only mode_tag, size_t max_n_msg, size_t max_msg_sz,
92 const util::Permissions& perms = util::Permissions(),
93 Error_code* err_code = 0);
94 /**
95 * Implements Persistent_mq_handle API: Construct handle to existing named MQ, or else if it does not exist creates
96 * it first and opens it (atomically).
97 *
98 * @see Persistent_mq_handle::Persistent_mq_handle(): implemented concept.
99 *
100 * @param logger_ptr
101 * See above.
102 * @param absolute_name
103 * See above.
104 * @param mode_tag
105 * See above.
106 * @param perms_on_create
107 * See above.
108 * Reminder: Suggest the use of util::shared_resource_permissions() to translate
109 * from one of a small handful of levels of access; these apply almost always in practice.
110 * @param max_n_msg_on_create
111 * See above.
112 * @param max_msg_sz_on_create
113 * See above.
114 * @param err_code
115 * See above.
116 */
117 explicit Bipc_mq_handle(flow::log::Logger* logger_ptr, const Shared_name& absolute_name,
118 util::Open_or_create mode_tag, size_t max_n_msg_on_create, size_t max_msg_sz_on_create,
119 const util::Permissions& perms_on_create = util::Permissions(),
120 Error_code* err_code = 0);
121 /**
122 * Implements Persistent_mq_handle API: Construct handle to existing named MQ. If it does not exist, it is an error.
123 *
124 * @param logger_ptr
125 * See above.
126 * @param absolute_name
127 * See above.
128 * @param mode_tag
129 * See above.
130 * @param err_code
131 * See above.
132 */
133 explicit Bipc_mq_handle(flow::log::Logger* logger_ptr, const Shared_name& absolute_name,
134 util::Open_only mode_tag, Error_code* err_code = 0);
135
136 /**
137 * Implements Persistent_mq_handle API: Constructs handle from the source handle while making the latter as-if
138 * default-cted. Reminder, informally: This is a light-weight op.
139 *
140 * @see Persistent_mq_handle::Persistent_mq_handle(): implemented concept.
141 *
142 * @param src
143 * See above.
144 */
146
147 /// Copying of handles is prohibited, per Persistent_mq_handle concept.
149
150 /**
151 * Implements Persistent_mq_handle API: Destroys this handle (or no-op if no handle was successfully constructed, or
152 * if it's a moved-from or default-cted handle). Reminder: The underlying MQ (if any) is *not* destroyed and can
153 * be attached-to by another handle.
154 *
155 * @see Persistent_mq_handle::~Persistent_mq_handle(): implemented concept.
156 */
158
159 // Methods.
160
161 /**
162 * Implements Persistent_mq_handle API: Replaces handle with the source handle while making the latter invalid as-if
163 * default-cted. Reminder, informally: this is a light-weight op.
164 *
165 * @param src
166 * See above.
167 * @return `*this`.
168 */
170
171 /// Copying of handles is prohibited, per Persistent_mq_handle concept.
173
174 /**
175 * Implements Persistent_mq_handle API: Removes the named persistent MQ. Reminder: name is removed immediately
176 * (if present -- otherwise error), but underlying MQ continues to exist until all system-wide handles to it
177 * are closed.
178 *
179 * @see Persistent_mq_handle::remove_persistent(): implemented concept.
180 *
181 * @see Reminder: see also `util::remove_each_persistent_*()`.
182 *
183 * @param logger_ptr
184 * See above.
185 * @param absolute_name
186 * See above.
187 * @param err_code
188 * See above.
189 */
190 static void remove_persistent(flow::log::Logger* logger_ptr, const Shared_name& absolute_name,
191 Error_code* err_code = 0);
192
193 /**
194 * Implements Persistent_mq_handle API. Impl note for exposition: we use the fact that, e.g., in Linux
195 * the POSIX MQ devices are listed in flat fashion in /dev/mqueue.
196 *
197 * @see Persistent_mq_handle::for_each_persistent(): implemented concept.
198 *
199 * @tparam Handle_name_func
200 * See above.
201 * @param handle_name_func
202 * See above.
203 */
204 template<typename Handle_name_func>
205 static void for_each_persistent(const Handle_name_func& handle_name_func);
206
207 /**
208 * Implements Persistent_mq_handle API: Non-blocking send: pushes copy of message to queue and returns `true`;
209 * if queue is full then no-op and returns `false`.
210 *
211 * @see Persistent_mq_handle::try_send(): implemented concept.
212 *
213 * ### INFO+ logging ###
214 * WARNING on error. (You may use the `flow::log::Config::this_thread_verbosity_override_auto()` to
215 * temporarily, in that thread only, disable/reduce logging. This is quite easy and performant.)
216 *
217 * @param blob
218 * See above.
219 * @param err_code
220 * See above.
221 * @return See above.
222 */
223 bool try_send(const util::Blob_const& blob, Error_code* err_code = 0);
224
225 /**
226 * Implements Persistent_mq_handle API: Blocking send: pushes copy of message to queue; if queue is full blocks
227 * until it is not.
228 *
229 * @see Persistent_mq_handle::send(): implemented concept.
230 *
231 * ### INFO+ logging ###
232 * WARNING on error. (You may use the `flow::log::Config::this_thread_verbosity_override_auto()`
233 * to temporarily, in that thread only, disable/reduce logging. This is quite easy and performant.)
234 *
235 * @param blob
236 * See above.
237 * @param err_code
238 * See above.
239 */
240 void send(const util::Blob_const& blob, Error_code* err_code = 0);
241
242 /**
243 * Implements Persistent_mq_handle API: Blocking timed send: pushes copy of message to queue; if queue is full
244 * blocks until it is not, or the specified time passes, whichever happens first.
245 *
246 * @see Persistent_mq_handle::timed_send(): implemented concept.
247 *
248 * ### INFO+ logging ###
249 * WARNING on error. (You may use the `flow::log::Config::this_thread_verbosity_override_auto()` to
250 * temporarily, in that thread only, disable/reduce logging. This is quite easy and performant.)
251 *
252 * @param blob
253 * See above.
254 * @param timeout_from_now
255 * See above.
256 * @param err_code
257 * See above.
258 * @return See above.
259 */
260 bool timed_send(const util::Blob_const& blob, util::Fine_duration timeout_from_now, Error_code* err_code = 0);
261
262 /**
263 * Implements Persistent_mq_handle API: Like try_send() but without the actual pushing of a message.
264 *
265 * @see Persistent_mq_handle::is_sendable(): implemented concept.
266 *
267 * ### INFO+ logging ###
268 * WARNING on error. (You may use the `flow::log::Config::this_thread_verbosity_override_auto()` to
269 * temporarily, in that thread only, disable/reduce logging. This is quite easy and performant.)
270 *
271 * @param err_code
272 * See above.
273 * @return See above.
274 */
275 bool is_sendable(Error_code* err_code = 0);
276
277 /**
278 * Implements Persistent_mq_handle API: Like send() but without the actual pushing of a message.
279 *
280 * @see Persistent_mq_handle::wait_sendable(): implemented concept.
281 *
282 * ### INFO+ logging ###
283 * WARNING on error. (You may use the `flow::log::Config::this_thread_verbosity_override_auto()` to
284 * temporarily, in that thread only, disable/reduce logging. This is quite easy and performant.)
285 *
286 * @param err_code
287 * See above.
288 */
289 void wait_sendable(Error_code* err_code = 0);
290
291 /**
292 * Implements Persistent_mq_handle API: Like timed_send() but without the actual pushing of a message.
293 *
294 * @see Persistent_mq_handle::timed_wait_sendable(): implemented concept.
295 *
296 * ### INFO+ logging ###
297 * WARNING on error. (You may use the `flow::log::Config::this_thread_verbosity_override_auto()` to
298 * temporarily, in that thread only, disable/reduce logging. This is quite easy and performant.)
299 *
300 * @param timeout_from_now
301 * See above.
302 * @param err_code
303 * See above.
304 * @return See above.
305 */
306 bool timed_wait_sendable(util::Fine_duration timeout_from_now, Error_code* err_code = 0);
307
308 /**
309 * Implements Persistent_mq_handle API: Non-blocking receive: pops copy of message from queue into buffer and
310 * returns `true`; if queue is empty then no-op and returns `false`.
311 *
312 * @see Persistent_mq_handle::try_receive(): implemented concept.
313 *
314 * ### INFO+ logging ###
315 * WARNING on error. (You may use the `flow::log::Config::this_thread_verbosity_override_auto()` to
316 * temporarily, in that thread only, disable/reduce logging. This is quite easy and performant.)
317 *
318 * @param blob
319 * See above.
320 * @param err_code
321 * See above.
322 * @return See above.
323 */
324 bool try_receive(util::Blob_mutable* blob, Error_code* err_code = 0);
325
326 /**
327 * Implements Persistent_mq_handle API: Blocking receive: pops copy of message from queue into buffer; if queue
328 * is empty blocks until it is not.
329 *
330 * @see Persistent_mq_handle::receive(): implemented concept.
331 *
332 * ### INFO+ logging ###
333 * WARNING on error. (You may use the `flow::log::Config::this_thread_verbosity_override_auto()` to
334 * temporarily, in that thread only, disable/reduce logging. This is quite easy and performant.)
335 *
336 * @param blob
337 * See above.
338 * @param err_code
339 * See above.
340 */
341 void receive(util::Blob_mutable* blob, Error_code* err_code = 0);
342
343 /**
344 * Implements Persistent_mq_handle API: Blocking timed receive: pops copy of message from queue into buffer;
345 * if queue is empty blocks until it is not, or the specified time passes, whichever happens first.
346 *
347 * @see Persistent_mq_handle::timed_receive(): implemented concept.
348 *
349 * ### INFO+ logging ###
350 * WARNING on error or timed out.
351 * (You may use the `flow::log::Config::this_thread_verbosity_override_auto()` to
352 * temporarily, in that thread only, disable/reduce logging. This is quite easy and performant.)
353 *
354 * @param blob
355 * See above.
356 * @param timeout_from_now
357 * See above.
358 * @param err_code
359 * See above.
360 * @return See above.
361 */
362 bool timed_receive(util::Blob_mutable* blob, util::Fine_duration timeout_from_now, Error_code* err_code = 0);
363
364 /**
365 * Implements Persistent_mq_handle API: Like try_receive() but without the actual popping of a message.
366 *
367 * @see Persistent_mq_handle::is_receivable(): implemented concept.
368 *
369 * ### INFO+ logging ###
370 * WARNING on error. (You may use the `flow::log::Config::this_thread_verbosity_override_auto()` to
371 * temporarily, in that thread only, disable/reduce logging. This is quite easy and performant.)
372 *
373 * @param err_code
374 * See above.
375 * @return See above.
376 */
377 bool is_receivable(Error_code* err_code = 0);
378
379 /**
380 * Implements Persistent_mq_handle API: Like receive() but without the actual popping of a message.
381 *
382 * @see Persistent_mq_handle::wait_receivable(): implemented concept.
383 *
384 * ### INFO+ logging ###
385 * WARNING on error. (You may use the `flow::log::Config::this_thread_verbosity_override_auto()` to
386 * temporarily, in that thread only, disable/reduce logging. This is quite easy and performant.)
387 *
388 * @param err_code
389 * See above.
390 */
391 void wait_receivable(Error_code* err_code = 0);
392
393 /**
394 * Implements Persistent_mq_handle API: Like timed_receive() but without the actual popping of a message.
395 *
396 * @see Persistent_mq_handle::timed_wait_receivable(): implemented concept.
397 *
398 * ### INFO+ logging ###
399 * WARNING on error or timed out. (You may use the `flow::log::Config::this_thread_verbosity_override_auto()` to
400 * temporarily, in that thread only, disable/reduce logging. This is quite easy and performant.)
401 *
402 * @param timeout_from_now
403 * See above.
404 * @param err_code
405 * See above.
406 * @return See above.
407 */
408 bool timed_wait_receivable(util::Fine_duration timeout_from_now, Error_code* err_code = 0);
409
410 /**
411 * Implements Persistent_mq_handle API:
412 * Turn on preemptive/concurrent interruption of blocking-sends and sendable-waits/polls.
413 *
414 * @see Persistent_mq_handle::interrupt_sends(): implemented concept.
415 *
416 * ### INFO+ logging ###
417 * WARNING on duplicate use, INFO otherwise.
418 *
419 * @return See above.
420 */
421 bool interrupt_sends();
422
423 /**
424 * Implements Persistent_mq_handle API:
425 * Turn off preemptive/concurrent interruption of blocking-sends and sendable-waits/polls.
426 *
427 * @see Persistent_mq_handle::allow_sends(): implemented concept.
428 *
429 * ### INFO+ logging ###
430 * WARNING on duplicate use, INFO otherwise.
431 *
432 * @return See above.
433 */
434 bool allow_sends();
435
436 /**
437 * Implements Persistent_mq_handle API:
438 * Turn on preemptive/concurrent interruption of blocking-receives and receivable-waits/polls.
439 *
440 * @see Persistent_mq_handle::interrupt_receives(): implemented concept.
441 *
442 * ### INFO+ logging ###
443 * WARNING on duplicate use, INFO otherwise.
444 *
445 * @return See above.
446 */
447 bool interrupt_receives();
448
449 /**
450 * Implements Persistent_mq_handle API:
451 * Turn off preemptive/concurrent interruption of blocking-receives and receivable-waits/polls.
452 *
453 * @see Persistent_mq_handle::allow_receives(): implemented concept.
454 *
455 * ### INFO+ logging ###
456 * WARNING on duplicate use, INFO otherwise.
457 *
458 * @return See above.
459 */
460 bool allow_receives();
461
462 /**
463 * Implements Persistent_mq_handle API: Returns name equal to `absolute_name` passed to ctor.
464 * @return See above.
465 * @see Persistent_mq_handle::absolute_name(): implemented concept.
466 */
467 const Shared_name& absolute_name() const;
468
469 /**
470 * Implements Persistent_mq_handle API: Returns the max message size of the underlying queue. Reminder:
471 * This is not required to match was was passed to `Create_only` or `Open_or_create` ctor.
472 *
473 * @return See above.
474 * @see Persistent_mq_handle::max_msg_size(): implemented concept.
475 */
476 size_t max_msg_size() const;
477
478 /**
479 * Implements Persistent_mq_handle API: Returns the max message count of the underlying queue. Reminder:
480 * This is not required to match was was passed to `Create_only` or `Open_or_create` ctor.
481 *
482 * @return See above.
483 * @see Persistent_mq_handle::max_n_msgs(): implemented concept.
484 */
485 size_t max_n_msgs() const;
486
487private:
488 // Types.
489
490 /// Specifies a variation of each set (sends, receives) of operations.
491 enum class Wait_type
492 {
493 /// Poll-type (non-blocking).
494 S_POLL,
495 /// Wait-type (blocking indefinitely).
496 S_WAIT,
497 /// Timed-wait-type (blocking until timeout).
498 S_TIMED_WAIT
499 };
500
501 // Friends.
502
503 // Friend of Bipc_mq_handle.
504 friend void swap(Bipc_mq_handle& val1, Bipc_mq_handle& val2);
505
506 // Constructors/destructor.
507
508 /**
509 * Helper ctor delegated by the 2 `public` ctors that take `Open_or_create` or `Create_only` mode.
510 *
511 * @tparam Mode_tag
512 * Either util::Open_or_create or util::Create_only.
513 * @param logger_ptr
514 * See `public` ctors.
515 * @param absolute_name
516 * See `public` ctors.
517 * @param mode_tag
518 * See `public` ctors.
519 * @param max_n_msg_on_create
520 * See `public` ctors.
521 * @param max_msg_sz_on_create
522 * See `public` ctors.
523 * @param perms_on_create
524 * See `public` ctors.
525 * @param err_code
526 * See `public` ctors.
527 */
528 template<typename Mode_tag>
529 explicit Bipc_mq_handle(Mode_tag mode_tag, flow::log::Logger* logger_ptr, const Shared_name& absolute_name,
530 size_t max_n_msg_on_create, size_t max_msg_sz_on_create,
531 const util::Permissions& perms_on_create,
532 Error_code* err_code);
533
534 // Methods.
535
536 /**
537 * Error helper: Run `func()` which will perform a `bipc::message_queue` API that might throw; if it does
538 * emit an error in the way our Flow-style APIs must (set #Error_code if not null, else throw... etc.).
539 *
540 * @tparam Func
541 * Functor that takes no args and returns nothing.
542 * @param func
543 * `func()` shall be executed synchronously.
544 * @param err_code
545 * `err_code` as-if passed to our API. `*err_code` shall be set if not null depending on success/failure;
546 * if null and no problem, won't throw; if null and problem will throw `Runtime_error` containing a truthy
547 * #Error_code. That's the usual Flow-style error emission semantics.
548 * @param context
549 * Description for logging of the op being attempted, in case there is an error. Compile-time-known strings
550 * are best, as this is not protected by a filtering macro and hence will be evaluated no matter what.
551 */
552 template<typename Func>
553 void op_with_possible_bipc_mq_exception(Error_code* err_code, util::String_view context, const Func& func);
554
555 /**
556 * Impl body for `interrupt_*()` and `allow_*()`.
557 *
558 * @tparam SND_ELSE_RCV
559 * True for `*_sendable()`, else `*_receivable()`.
560 * @tparam ON_ELSE_OFF
561 * True for `interrupt_*()`, else `allow_*()`.
562 * @return See callers.
563 */
564 template<bool SND_ELSE_RCV, bool ON_ELSE_OFF>
566
567 /**
568 * Impl body for `*_sendable()` and `*_receivable()`.
569 *
570 * @tparam WAIT_TYPE
571 * See Wait_type.
572 * @tparam SND_ELSE_RCV
573 * True for `*_sendable()`, else `*_receivable()`.
574 * @param timeout_from_now
575 * `timeout_from_now` for the `timed_*()` variations; else ignored.
576 * @param err_code
577 * See callers.
578 * @return See callers.
579 */
580 template<Wait_type WAIT_TYPE, bool SND_ELSE_RCV>
581 bool wait_impl(util::Fine_duration timeout_from_now, Error_code* err_code);
582
583 // Data.
584
585 /**
586 * Underlying MQ handle. We are a thin wrapper around this really. Null if creation fails in ctor, or if
587 * `*this` was moved-from.
588 */
589 boost::movelib::unique_ptr<bipc::message_queue> m_mq;
590
591 /// See absolute_name().
593
594 /**
595 * Starting at `false`, this is made `true` via interrupt_sends(), and back by allow_sends(); when `true`
596 * wait_impl() will return with error::Code::S_INTERRUPTED, as checked at
597 * - the start of its wait critical section;
598 * - on being awoken via condition variable during said critical section. Said condition variable is
599 * notified by the following code:
600 * - `bipc::message_queue` opposite-direction (receiving) code, when it pops a message; and
601 * - interrupt_sends() itself when transitioning #m_interrupting_snd to `true` (also sometimes spuriously
602 * for performance).
603 *
604 * Protected by the mutex associated with the aforementioned `bipc::message_queue` condition variable.
605 * See wait_impl() internals for more detail about this mutex and all of that.
606 *
607 * (Naturally it also acts as a guard against duplicately calling interrupt_sends() or allow_sends().)
608 */
610
611 /// Other-direction counterpart to #m_interrupting_snd.
613}; // class Bipc_mq_handle
614
615// Free functions: in *_fwd.hpp.
616
617// Template implementations.
618
619template<typename Handle_name_func>
620void Bipc_mq_handle::for_each_persistent(const Handle_name_func& handle_name_func) // Static.
621{
622 /* bipc does not expose what we want; but we use the knowledge (from perusing its internal source code) that
623 * it simply stores a given MQ N's stuff in a SHM pool named also N. @todo Check Boost version or something?
624 * They could change this, although it is unlikely in my opinion (ygoldfel). */
625 util::for_each_persistent_shm_pool(handle_name_func);
626 // (See that guy's doc header for why we use him and not shm::classic::Pool_arena::for_each_persistent().)
627}
628
629} // namespace ipc::transport
Implements the Persistent_mq_handle concept by thinly wrapping bipc::message_queue,...
Bipc_mq_handle()
Implements Persistent_mq_handle API: Construct null handle.
bool allow_receives()
Implements Persistent_mq_handle API: Turn off preemptive/concurrent interruption of blocking-receives...
boost::movelib::unique_ptr< bipc::message_queue > m_mq
Underlying MQ handle.
bool timed_wait_sendable(util::Fine_duration timeout_from_now, Error_code *err_code=0)
Implements Persistent_mq_handle API: Like timed_send() but without the actual pushing of a message.
Bipc_mq_handle & operator=(Bipc_mq_handle &&src)
Implements Persistent_mq_handle API: Replaces handle with the source handle while making the latter i...
Bipc_mq_handle & operator=(const Bipc_mq_handle &)=delete
Copying of handles is prohibited, per Persistent_mq_handle concept.
Bipc_mq_handle(const Bipc_mq_handle &)=delete
Copying of handles is prohibited, per Persistent_mq_handle concept.
static void for_each_persistent(const Handle_name_func &handle_name_func)
Implements Persistent_mq_handle API.
bool m_interrupting_rcv
Other-direction counterpart to m_interrupting_snd.
bool interrupt_sends()
Implements Persistent_mq_handle API: Turn on preemptive/concurrent interruption of blocking-sends and...
void send(const util::Blob_const &blob, Error_code *err_code=0)
Implements Persistent_mq_handle API: Blocking send: pushes copy of message to queue; if queue is full...
bool try_send(const util::Blob_const &blob, Error_code *err_code=0)
Implements Persistent_mq_handle API: Non-blocking send: pushes copy of message to queue and returns t...
bool timed_wait_receivable(util::Fine_duration timeout_from_now, Error_code *err_code=0)
Implements Persistent_mq_handle API: Like timed_receive() but without the actual popping of a message...
bool timed_receive(util::Blob_mutable *blob, util::Fine_duration timeout_from_now, Error_code *err_code=0)
Implements Persistent_mq_handle API: Blocking timed receive: pops copy of message from queue into buf...
const Shared_name & absolute_name() const
Implements Persistent_mq_handle API: Returns name equal to absolute_name passed to ctor.
static constexpr bool S_HAS_NATIVE_HANDLE
Implements concept API.
static const Shared_name S_RESOURCE_TYPE_ID
Implements concept API.
bool allow_sends()
Implements Persistent_mq_handle API: Turn off preemptive/concurrent interruption of blocking-sends an...
bool try_receive(util::Blob_mutable *blob, Error_code *err_code=0)
Implements Persistent_mq_handle API: Non-blocking receive: pops copy of message from queue into buffe...
Wait_type
Specifies a variation of each set (sends, receives) of operations.
void wait_receivable(Error_code *err_code=0)
Implements Persistent_mq_handle API: Like receive() but without the actual popping of a message.
bool interrupt_receives()
Implements Persistent_mq_handle API: Turn on preemptive/concurrent interruption of blocking-receives ...
bool m_interrupting_snd
Starting at false, this is made true via interrupt_sends(), and back by allow_sends(); when true wait...
bool timed_send(const util::Blob_const &blob, util::Fine_duration timeout_from_now, Error_code *err_code=0)
Implements Persistent_mq_handle API: Blocking timed send: pushes copy of message to queue; if queue i...
Bipc_mq_handle(Bipc_mq_handle &&src)
Implements Persistent_mq_handle API: Constructs handle from the source handle while making the latter...
static void remove_persistent(flow::log::Logger *logger_ptr, const Shared_name &absolute_name, Error_code *err_code=0)
Implements Persistent_mq_handle API: Removes the named persistent MQ.
void op_with_possible_bipc_mq_exception(Error_code *err_code, util::String_view context, const Func &func)
Error helper: Run func() which will perform a bipc::message_queue API that might throw; if it does em...
void receive(util::Blob_mutable *blob, Error_code *err_code=0)
Implements Persistent_mq_handle API: Blocking receive: pops copy of message from queue into buffer; i...
size_t max_n_msgs() const
Implements Persistent_mq_handle API: Returns the max message count of the underlying queue.
~Bipc_mq_handle()
Implements Persistent_mq_handle API: Destroys this handle (or no-op if no handle was successfully con...
bool interrupt_allow_impl()
Impl body for interrupt_*() and allow_*().
void wait_sendable(Error_code *err_code=0)
Implements Persistent_mq_handle API: Like send() but without the actual pushing of a message.
size_t max_msg_size() const
Implements Persistent_mq_handle API: Returns the max message size of the underlying queue.
bool wait_impl(util::Fine_duration timeout_from_now, Error_code *err_code)
Impl body for *_sendable() and *_receivable().
bool is_receivable(Error_code *err_code=0)
Implements Persistent_mq_handle API: Like try_receive() but without the actual popping of a message.
Shared_name m_absolute_name
See absolute_name().
friend void swap(Bipc_mq_handle &val1, Bipc_mq_handle &val2)
Implements Persistent_mq_handle related concept: Swaps two objects.
bool is_sendable(Error_code *err_code=0)
Implements Persistent_mq_handle API: Like try_send() but without the actual pushing of a message.
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...
bipc::permissions Permissions
Short-hand for Unix (POSIX) permissions class.
Definition: util_fwd.hpp:155
bipc::open_only_t Open_only
Tag type indicating an ideally-atomic open-if-exists-else-fail operation.
Definition: util_fwd.hpp:149
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
void for_each_persistent_shm_pool(const Handle_name_func &handle_name_func)
Equivalent to shm::classic::Pool_arena::for_each_persistent().
Definition: util.hpp:130
bipc::open_or_create_t Open_or_create
Tag type indicating an atomic open-if-exists-else-create operation.
Definition: util_fwd.hpp:146
bipc::create_only_t Create_only
Tag type indicating a create-unless-exists-else-fail operation.
Definition: util_fwd.hpp:152
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::util::String_view String_view
Short-hand for Flow's String_view.
Definition: util_fwd.hpp:109
flow::Error_code Error_code
Short-hand for flow::Error_code which is very common.
Definition: common.hpp:297