123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- #ifndef BOOST_INTERPROCESS_FILE_MAPPING_HPP
- #define BOOST_INTERPROCESS_FILE_MAPPING_HPP
- #include <boost/interprocess/detail/config_begin.hpp>
- #include <boost/interprocess/detail/workaround.hpp>
- #include <boost/interprocess/interprocess_fwd.hpp>
- #include <boost/interprocess/exceptions.hpp>
- #include <boost/interprocess/detail/utilities.hpp>
- #include <boost/interprocess/creation_tags.hpp>
- #include <boost/interprocess/detail/os_file_functions.hpp>
- #include <boost/move/move.hpp>
- #include <string>
- namespace boost {
- namespace interprocess {
- class file_mapping
- {
-
- BOOST_MOVABLE_BUT_NOT_COPYABLE(file_mapping)
-
- public:
-
-
- file_mapping();
-
-
-
-
- file_mapping(const char *filename, mode_t mode);
-
-
-
- file_mapping(BOOST_RV_REF(file_mapping) moved)
- : m_handle(file_handle_t(ipcdetail::invalid_file()))
- { this->swap(moved); }
-
-
-
- file_mapping &operator=(BOOST_RV_REF(file_mapping) moved)
- {
- file_mapping tmp(boost::move(moved));
- this->swap(tmp);
- return *this;
- }
-
-
- void swap(file_mapping &other);
-
-
- mode_t get_mode() const;
-
-
- mapping_handle_t get_mapping_handle() const;
-
-
- ~file_mapping();
-
-
- const char *get_name() const;
-
-
-
-
- static bool remove(const char *filename);
-
- private:
-
- void priv_close();
- file_handle_t m_handle;
- mode_t m_mode;
- std::string m_filename;
-
- };
- inline file_mapping::file_mapping()
- : m_handle(file_handle_t(ipcdetail::invalid_file()))
- {}
- inline file_mapping::~file_mapping()
- { this->priv_close(); }
- inline const char *file_mapping::get_name() const
- { return m_filename.c_str(); }
- inline void file_mapping::swap(file_mapping &other)
- {
- std::swap(m_handle, other.m_handle);
- std::swap(m_mode, other.m_mode);
- m_filename.swap(other.m_filename);
- }
- inline mapping_handle_t file_mapping::get_mapping_handle() const
- { return ipcdetail::mapping_handle_from_file_handle(m_handle); }
- inline mode_t file_mapping::get_mode() const
- { return m_mode; }
- inline file_mapping::file_mapping
- (const char *filename, mode_t mode)
- : m_filename(filename)
- {
-
- if (mode != read_write && mode != read_only){
- error_info err = other_error;
- throw interprocess_exception(err);
- }
-
- m_handle = ipcdetail::open_existing_file(filename, mode);
-
- if(m_handle == ipcdetail::invalid_file()){
- error_info err = system_error_code();
- this->priv_close();
- throw interprocess_exception(err);
- }
- m_mode = mode;
- }
- inline bool file_mapping::remove(const char *filename)
- { return ipcdetail::delete_file(filename); }
- inline void file_mapping::priv_close()
- {
- if(m_handle != ipcdetail::invalid_file()){
- ipcdetail::close_file(m_handle);
- m_handle = ipcdetail::invalid_file();
- }
- }
- class remove_file_on_destroy
- {
- const char * m_name;
- public:
- remove_file_on_destroy(const char *name)
- : m_name(name)
- {}
- ~remove_file_on_destroy()
- { ipcdetail::delete_file(m_name); }
- };
- }
- }
- #include <boost/interprocess/detail/config_end.hpp>
- #endif
|