123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- #ifndef BOOST_INTERPROCESS_FILE_MAPPING_HPP
- #define BOOST_INTERPROCESS_FILE_MAPPING_HPP
- #ifndef BOOST_CONFIG_HPP
- # include <boost/config.hpp>
- #endif
- #
- #if defined(BOOST_HAS_PRAGMA_ONCE)
- # pragma once
- #endif
- #include <boost/interprocess/detail/config_begin.hpp>
- #include <boost/interprocess/detail/workaround.hpp>
- #if !defined(BOOST_INTERPROCESS_MAPPED_FILES)
- #error "Boost.Interprocess: This platform does not support memory mapped files!"
- #endif
- #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/interprocess/detail/simple_swap.hpp>
- #include <boost/interprocess/detail/char_wchar_holder.hpp>
- #include <boost/move/utility_core.hpp>
- namespace boost {
- namespace interprocess {
- class file_mapping
- {
- #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
- BOOST_MOVABLE_BUT_NOT_COPYABLE(file_mapping)
- #endif
- public:
-
-
- file_mapping() BOOST_NOEXCEPT;
-
-
-
-
- file_mapping(const char *filename, mode_t mode);
- #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
-
-
-
-
-
-
-
- file_mapping(const wchar_t *filename, mode_t mode);
- #endif
-
-
-
- file_mapping(BOOST_RV_REF(file_mapping) moved) BOOST_NOEXCEPT
- : m_handle(file_handle_t(ipcdetail::invalid_file()))
- , m_mode(read_only)
- { this->swap(moved); }
-
-
-
- file_mapping &operator=(BOOST_RV_REF(file_mapping) moved) BOOST_NOEXCEPT
- {
- file_mapping tmp(boost::move(moved));
- this->swap(tmp);
- return *this;
- }
-
-
- void swap(file_mapping &other) BOOST_NOEXCEPT;
-
-
- mode_t get_mode() const BOOST_NOEXCEPT;
-
-
- mapping_handle_t get_mapping_handle() const BOOST_NOEXCEPT;
-
-
- ~file_mapping();
-
-
- const char *get_name() const BOOST_NOEXCEPT;
-
-
-
-
- static bool remove(const char *filename);
- #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
-
-
-
-
-
-
-
- static bool remove(const wchar_t *filename);
- #endif
- #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
- private:
-
- void priv_close();
- file_handle_t m_handle;
- mode_t m_mode;
- char_wchar_holder m_filename;
- #endif
- };
- inline file_mapping::file_mapping() BOOST_NOEXCEPT
- : m_handle(file_handle_t(ipcdetail::invalid_file()))
- , m_mode(read_only)
- {}
- inline file_mapping::~file_mapping()
- { this->priv_close(); }
- inline const char *file_mapping::get_name() const BOOST_NOEXCEPT
- { return m_filename.getn(); }
- inline void file_mapping::swap(file_mapping &other) BOOST_NOEXCEPT
- {
- (simple_swap)(m_handle, other.m_handle);
- (simple_swap)(m_mode, other.m_mode);
- m_filename.swap(other.m_filename);
- }
- inline mapping_handle_t file_mapping::get_mapping_handle() const BOOST_NOEXCEPT
- { return ipcdetail::mapping_handle_from_file_handle(m_handle); }
- inline mode_t file_mapping::get_mode() const BOOST_NOEXCEPT
- { 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); }
- #ifdef BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES
- inline file_mapping::file_mapping
- (const wchar_t *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 wchar_t *filename)
- { return ipcdetail::delete_file(filename); }
- #endif
- #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
- 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); }
- };
- #endif
- }
- }
- #include <boost/interprocess/detail/config_end.hpp>
- #endif
|