Flow-IPC 3.0.0
Flow-IPC project: Full implementation reference.
blob_stream_mq.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
23
24namespace ipc::transport
25{
26
27// Types.
28
29/**
30 * Base of Blob_stream_mq_sender and Blob_stream_mq_receiver containing certain `static` facilities, particularly
31 * for post-abort persistent resource cleanup. As of this writing this type stores no data.
32 *
33 * @tparam Persistent_mq_handle
34 * See Persistent_mq_handle concept doc header.
35 */
36template<typename Persistent_mq_handle>
38{
39public:
40 // Methods.
41
42 /**
43 * Removes the Blob_stream_mq_sender and/or Blob_stream_mq_receiver persistent resources associated with
44 * a Persistent_mq_handle with the given name. Please see Cleanup in Blob_stream_mq_sender doc header for
45 * context; and note it applies equally to Blob_stream_mq_receiver. In short: Those classes gracefully
46 * clean up by themselves, via their dtors; but an abort (or two) may prevent this from occurring -- in which
47 * case one should do one of the following:
48 * - If the name of the potentially-leaked MQ is known: Call this function, remove_persistent().
49 * - If not, but you used a name-prefix-based scheme: Call
50 * `remove_each_persistent_with_name_prefix<Blob_stream_mq_base>()`, providing the applicable name prefix.
51 * It will invoke remove_persistent() (and for_each_persistent()) internally as needed.
52 *
53 * Trying to remove a non-existent name *is* an error; but typically one should ignore any error, since the
54 * function is meant for best-effort cleanup in case a leak occurred earlier due to abort(s).
55 *
56 * Logs INFO message.
57 *
58 * ### Rationale ###
59 * Why does this exist, when Persistent_mq_handle::remove_persistent() is available? Answer:
60 * Blob_stream_mq_base sub-classes require certain internal resources (tiny SHM pools as of this writing)
61 * to ensure a single sender and single receiver per MQ (a limitation not imposed by the lower-level
62 * Persistent_mq_handle construct).
63 *
64 * @param logger_ptr
65 * Logger to use for subsequently logging.
66 * @param name
67 * Absolute name at which the persistent MQ (fed to Blob_stream_mq_sender and/or
68 * Blob_stream_mq_receiver ctor) lives.
69 * @param err_code
70 * See `flow::Error_code` docs for error reporting semantics. #Error_code generated:
71 * various.
72 */
73 static void remove_persistent(flow::log::Logger* logger_ptr, const Shared_name& name,
74 Error_code* err_code = nullptr);
75
76 /**
77 * Forwards to Persistent_mq_handle::for_each_persistent(). In practice this exists merely to enable
78 * templates remove_each_persistent_with_name_prefix() and remove_each_persistent_if() to work with
79 * Blob_stream_mq_base.
80 *
81 * @tparam Handle_name_func
82 * See Persistent_mq_handle::for_each_persistent().
83 * @param handle_name_func
84 * See Persistent_mq_handle::for_each_persistent().
85 */
86 template<typename Handle_name_func>
87 static void for_each_persistent(const Handle_name_func& handle_name_func);
88}; // class Blob_stream_mq_base
89
90/// Similar to Blob_stream_mq_base but contains non-class-template-parameter-dependent Blob_stream_mq_receiver items.
92{
93public:
94 // Types.
95
96 /**
97 * Implements Blob_receiver::Blob_batch_in and sync_io::Blob_receiver::Blob_batch_in concept API.
98 *
99 * @internal
100 * Impl-wise: As there is no native batch-receiving support for any of the Persistent_mq_handle concrete
101 * impls in any relevant OS, that we know of as of this writing, the proper/only choice for
102 * `Blob_batch_in` is Generic_msg_batch_in. It is a Msg_batch_in concept impl as required but essentially
103 * just stores a `vector` of target-message slots into which a `*this` can place results message-by-message
104 * via a series of single-message receives. E.g., sync_io::Native_socket_stream_impl does the same thing,
105 * when the OS does not provide native batch-receiving (or we choose to disable it at compile-time).
106 */
107 template<typename Msg_resource>
109}; // class Blob_stream_mq_receiver_base
110
111// Template implementations.
112
113template<typename Persistent_mq_handle>
114void Blob_stream_mq_base<Persistent_mq_handle>::remove_persistent(flow::log::Logger* logger_ptr, // Static.
115 const Shared_name& name, Error_code* err_code)
116{
118}
119
120template<typename Persistent_mq_handle>
121template<typename Handle_name_func>
122void // Static.
124{
126}
127
128} // namespace ipc::transport
static void for_each_persistent(const Handle_name_func &handle_name_func)
See Blob_stream_mq_base counterpart.
static void remove_persistent(flow::log::Logger *logger_ptr, const Shared_name &name, Error_code *err_code)
See Blob_stream_mq_base counterpart.
Base of Blob_stream_mq_sender and Blob_stream_mq_receiver containing certain static facilities,...
static void for_each_persistent(const Handle_name_func &handle_name_func)
Forwards to Persistent_mq_handle::for_each_persistent().
static void remove_persistent(flow::log::Logger *logger_ptr, const Shared_name &name, Error_code *err_code=nullptr)
Removes the Blob_stream_mq_sender and/or Blob_stream_mq_receiver persistent resources associated with...
Similar to Blob_stream_mq_base but contains non-class-template-parameter-dependent Blob_stream_mq_rec...
Straightforward Msg_batch_in concept implementation (as taken by API {Blob|Native_handle}_receiver::a...
Definition: batch.hpp:88
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...
flow::Error_code Error_code
Short-hand for flow::Error_code which is very common.
Definition: common.hpp:313