Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
pinnable_mapped_file.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <system_error>
4#include <boost/interprocess/managed_mapped_file.hpp>
5#include <boost/interprocess/sync/file_lock.hpp>
6#include <boost/filesystem.hpp>
7#include <boost/asio/io_service.hpp>
8
9namespace chainbase {
10
11namespace bip = boost::interprocess;
12namespace bfs = boost::filesystem;
13
27
28const std::error_category& chainbase_error_category();
29
30inline std::error_code make_error_code(db_error_code e) noexcept {
31 return std::error_code(static_cast<int>(e), chainbase_error_category());
32}
33
34class chainbase_error_category : public std::error_category {
35public:
36 const char* name() const noexcept override;
37 std::string message(int ev) const override;
38};
39
41 public:
42 typedef typename bip::managed_mapped_file::segment_manager segment_manager;
43
49
50 pinnable_mapped_file(const bfs::path& dir, bool writable, uint64_t shared_file_size, bool allow_dirty, map_mode mode);
56
57 segment_manager* get_segment_manager() const { return _segment_manager;}
58
59 private:
60 void set_mapped_file_db_dirty(bool);
61 void load_database_file(boost::asio::io_service& sig_ios);
62 void save_database_file();
63 bool all_zeros(char* data, size_t sz);
64 void setup_non_file_mapping();
65
66 bip::file_lock _mapped_file_lock;
67 bfs::path _data_file_path;
68 std::string _database_name;
69 bool _writable;
70
71 bip::file_mapping _file_mapping;
72 bip::mapped_region _file_mapped_region;
73 void* _non_file_mapped_mapping = nullptr;
74 size_t _non_file_mapped_mapping_size = 0;
75
76#ifdef _WIN32
77 bip::permissions _db_permissions;
78#else
79 bip::permissions _db_permissions{S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH};
80#endif
81
82 segment_manager* _segment_manager = nullptr;
83
84 constexpr static unsigned _db_size_multiple_requirement = 1024*1024; //1MB
85};
86
87std::istream& operator>>(std::istream& in, pinnable_mapped_file::map_mode& runtime);
88std::ostream& operator<<(std::ostream& osm, pinnable_mapped_file::map_mode m);
89
90}
const char * name() const noexcept override
segment_manager * get_segment_manager() const
bip::managed_mapped_file::segment_manager segment_manager
pinnable_mapped_file & operator=(pinnable_mapped_file &&)
pinnable_mapped_file & operator=(const pinnable_mapped_file &)=delete
pinnable_mapped_file(const pinnable_mapped_file &)=delete
pinnable_mapped_file(const bfs::path &dir, bool writable, uint64_t shared_file_size, bool allow_dirty, map_mode mode)
std::error_code make_error_code(db_error_code e) noexcept
DataStream & operator<<(DataStream &ds, const oid< OidType > &oid)
const std::error_category & chainbase_error_category()
DataStream & operator>>(DataStream &ds, oid< OidType > &oid)
unsigned __int64 uint64_t
Definition stdint.h:136