aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2022-10-09 23:34:42 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2022-10-09 23:35:10 +0100
commit3f20a29a6ea7b1406751a9e68ad863ba46d78397 (patch)
tree8d7baf80ab95abfb18dd081d8f0ca008b3fce882 /src
parent0fa3836b98100607b3f6f8dc4918166ef28ffa81 (diff)
downloadrspamd-3f20a29a6ea7b1406751a9e68ad863ba46d78397.tar.gz
rspamd-3f20a29a6ea7b1406751a9e68ad863ba46d78397.zip
[Minor] Add method to extract shared memory from RAII ownership
Diffstat (limited to 'src')
-rw-r--r--src/libutil/cxx/locked_file.hxx8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libutil/cxx/locked_file.hxx b/src/libutil/cxx/locked_file.hxx
index ce25b0a5a..94561a2d4 100644
--- a/src/libutil/cxx/locked_file.hxx
+++ b/src/libutil/cxx/locked_file.hxx
@@ -112,7 +112,15 @@ struct raii_mmaped_locked_file final {
~raii_mmaped_locked_file();
static auto mmap_shared(raii_locked_file &&file, int flags) -> tl::expected<raii_mmaped_locked_file, std::string>;
static auto mmap_shared(const char *fname, int open_flags, int mmap_flags) -> tl::expected<raii_mmaped_locked_file, std::string>;
+ // Returns a constant pointer to the underlying map
auto get_map() const -> void* {return map;}
+ // Passes the ownership of the mmaped memory to the callee
+ auto steal_map() -> std::tuple<void *, std::size_t> {
+ auto ret = std::make_tuple(this->map, file.get_stat().st_size);
+ this->map = nullptr;
+ return ret;
+ }
+
auto get_size() const -> std::size_t { return file.get_stat().st_size; }
raii_mmaped_locked_file& operator=(raii_mmaped_locked_file &&other) noexcept {