diff options
Diffstat (limited to 'boost/interprocess/windows_shared_memory.hpp')
-rw-r--r-- | boost/interprocess/windows_shared_memory.hpp | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/boost/interprocess/windows_shared_memory.hpp b/boost/interprocess/windows_shared_memory.hpp index 9a8b3f47dd..76601bb363 100644 --- a/boost/interprocess/windows_shared_memory.hpp +++ b/boost/interprocess/windows_shared_memory.hpp @@ -72,26 +72,26 @@ class windows_shared_memory windows_shared_memory(open_or_create_t, const char *name, mode_t mode, std::size_t size, const permissions& perm = permissions()) { this->priv_open_or_create(ipcdetail::DoOpenOrCreate, name, mode, size, perm); } - //!Tries to open a shared memory object with name "name", with the access mode "mode". + //!Tries to open a shared memory object with name "name", with the access mode "mode". //!If the file does not previously exist, it throws an error. windows_shared_memory(open_only_t, const char *name, mode_t mode) { this->priv_open_or_create(ipcdetail::DoOpen, name, mode, 0, permissions()); } - //!Moves the ownership of "moved"'s shared memory object to *this. - //!After the call, "moved" does not represent any shared memory object. + //!Moves the ownership of "moved"'s shared memory object to *this. + //!After the call, "moved" does not represent any shared memory object. //!Does not throw windows_shared_memory(BOOST_RV_REF(windows_shared_memory) moved) : m_handle(0) { this->swap(moved); } //!Moves the ownership of "moved"'s shared memory to *this. - //!After the call, "moved" does not represent any shared memory. + //!After the call, "moved" does not represent any shared memory. //!Does not throw windows_shared_memory &operator=(BOOST_RV_REF(windows_shared_memory) moved) - { + { windows_shared_memory tmp(boost::move(moved)); this->swap(tmp); - return *this; + return *this; } //!Swaps to shared_memory_objects. Does not throw @@ -129,21 +129,21 @@ class windows_shared_memory /// @cond -inline windows_shared_memory::windows_shared_memory() +inline windows_shared_memory::windows_shared_memory() : m_handle(0) {} -inline windows_shared_memory::~windows_shared_memory() +inline windows_shared_memory::~windows_shared_memory() { this->priv_close(); } inline const char *windows_shared_memory::get_name() const { return m_name.c_str(); } inline void windows_shared_memory::swap(windows_shared_memory &other) -{ +{ std::swap(m_handle, other.m_handle); std::swap(m_mode, other.m_mode); - m_name.swap(other.m_name); + m_name.swap(other.m_name); } inline mapping_handle_t windows_shared_memory::get_mapping_handle() const @@ -157,22 +157,26 @@ inline bool windows_shared_memory::priv_open_or_create { m_name = filename ? filename : ""; - unsigned long file_map_access = 0; + unsigned long protection = 0; unsigned long map_access = 0; switch(mode) { + //"protection" is for "create_file_mapping" + //"map_access" is for "open_file_mapping" + //Add section query (strange that read or access does not grant it...) + //to obtain the size of the mapping. copy_on_write is equal to section_query. case read_only: - file_map_access |= winapi::page_readonly; - map_access |= winapi::file_map_read; + protection |= winapi::page_readonly; + map_access |= winapi::file_map_read | winapi::section_query; break; case read_write: - file_map_access |= winapi::page_readwrite; - map_access |= winapi::file_map_write; + protection |= winapi::page_readwrite; + map_access |= winapi::file_map_write | winapi::section_query; break; case copy_on_write: - file_map_access |= winapi::page_writecopy; - map_access |= winapi::file_map_copy; + protection |= winapi::page_writecopy; + map_access |= winapi::file_map_copy; break; default: { @@ -184,16 +188,13 @@ inline bool windows_shared_memory::priv_open_or_create switch(type){ case ipcdetail::DoOpen: - m_handle = winapi::open_file_mapping - (map_access, filename); + m_handle = winapi::open_file_mapping(map_access, filename); break; case ipcdetail::DoCreate: case ipcdetail::DoOpenOrCreate: { - __int64 s = size; - unsigned long high_size(s >> 32), low_size((boost::uint32_t)s); m_handle = winapi::create_file_mapping - ( winapi::invalid_handle_value, file_map_access, high_size, low_size, filename + ( winapi::invalid_handle_value, protection, size, filename , (winapi::interprocess_security_attributes*)perm.get_permissions()); } break; |