24#include <flow/error/error.hpp>
25#include <flow/common.hpp>
26#include <boost/interprocess/exceptions.hpp>
33template<
typename Func>
39 using flow::error::Runtime_error;
40 using bipc::interprocess_exception;
41 using boost::system::system_category;
43 if (flow::error::exec_void_and_throw_on_error
52 FLOW_LOG_SET_CONTEXT(logger_ptr, Log_component::S_UTIL);
58 catch (
const interprocess_exception& exc)
66 const auto native_code_raw = exc.get_native_error();
67 const auto bipc_err_code_enum = exc.get_error_code();
68 FLOW_LOG_WARNING(
"bipc threw interprocess_exception; will emit some hopefully suitable Flow-IPC Error_code; "
69 "but here are all the details of the original exception: native code int "
70 "[" << native_code_raw <<
"]; bipc error_code_t enum->int "
71 "[" <<
int(bipc_err_code_enum) <<
"]; message = [" << exc.what() <<
"]; "
72 "context = [" << context <<
"].");
74 if (native_code_raw != 0)
76 const auto& sys_err_code = *err_code =
Error_code(native_code_raw, system_category());
77 FLOW_ERROR_SYS_ERROR_LOG_WARNING();
82 *err_code = misc_bipc_lib_error;
89template<
typename Handle_name_func>
92 using fs::directory_iterator;
94 assert(persistent_obj_dev_dir_path.is_absolute() &&
"Expecting absolute path like /dev/shm (by contract).");
101 for (
const auto& dir_entry : directory_iterator(persistent_obj_dev_dir_path, sink))
115 static_assert(
false,
"We rely on Linux /dev/... (etc.) semantics, where the object-mapped files "
116 "are classified as regular files.");
119 const auto dir_entry_status = dir_entry.status(err_code);
120 if (err_code || !fs::is_regular_file(dir_entry_status))
126 handle_name_func(
Shared_name::ct(dir_entry.path().filename().native()));
130template<
typename Handle_name_func>
134 static_assert(
false,
"This method relies on/has been tested only with Linux /dev/shm semantics.");
static Shared_name ct(const Source &src)
Copy-constructs from a char-sequence container (including string, util::String_view,...
Flow-IPC module containing miscellaneous general-use facilities that ubiquitously used by ~all Flow-I...
void for_each_persistent_impl(const fs::path &persistent_obj_dev_dir_path, const Handle_name_func &handle_name_func)
Implementation of Persistent_object::for_each_persistent(); for example see shm::classic::Pool_arena:...
void for_each_persistent_shm_pool(const Handle_name_func &handle_name_func)
Equivalent to shm::classic::Pool_arena::for_each_persistent().
void op_with_possible_bipc_exception(flow::log::Logger *logger_ptr, Error_code *err_code, const Error_code &misc_bipc_lib_error, String_view context, const Func &func)
Internal (to ipc) utility that invokes the given function that invokes a boost.interprocess operation...
flow::util::String_view String_view
Short-hand for Flow's String_view.
flow::Error_code Error_code
Short-hand for flow::Error_code which is very common.