1 ////////////////////////////////////////////////////////////////////////////// 2 // 3 // (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost 4 // Software License, Version 1.0. (See accompanying file 5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 // 7 // See http://www.boost.org/libs/interprocess for documentation. 8 // 9 ////////////////////////////////////////////////////////////////////////////// 10 11 #include <boost/config.hpp> 12 13 #ifdef BOOST_WINDOWS 14 15 //Force user-defined get_shared_dir 16 #define BOOST_INTERPROCESS_SHARED_DIR_FUNC 17 #include <boost/interprocess/detail/shared_dir_helpers.hpp> 18 #include <string> 19 20 #include "get_process_id_name.hpp" 21 22 namespace boost { 23 namespace interprocess { 24 namespace ipcdetail { 25 26 static bool dir_created = false; 27 get_shared_dir(std::string & shared_dir)28inline void get_shared_dir(std::string &shared_dir) 29 { 30 shared_dir = boost::interprocess::ipcdetail::get_temporary_path(); 31 shared_dir += "/boostipctest_"; 32 shared_dir += boost::interprocess::test::get_process_id_name(); 33 if(!dir_created) 34 ipcdetail::create_directory(shared_dir.c_str()); 35 dir_created = true; 36 } 37 38 }}} //namespace boost::interprocess::ipcdetail 39 40 #include <boost/interprocess/shared_memory_object.hpp> 41 #include <iostream> 42 main()43int main () 44 { 45 using namespace boost::interprocess; 46 const char *const shm_name = "test_shm"; 47 std::string shared_dir; 48 ipcdetail::get_shared_dir(shared_dir); 49 50 std::string shm_path(shared_dir); 51 shm_path += "/"; 52 shm_path += shm_name; 53 54 int ret = 0; 55 shared_memory_object::remove(shm_name); 56 { 57 { 58 shared_memory_object shm(create_only, shm_name, read_write); 59 } 60 61 ret = ipcdetail::invalid_file() == ipcdetail::open_existing_file(shm_path.c_str(), read_only) ? 62 1 : 0; 63 if(ret) 64 { 65 std::cerr << "Error opening user get_shared_dir()/shm file" << std::endl; 66 } 67 } 68 shared_memory_object::remove(shm_name); 69 ipcdetail::remove_directory(shared_dir.c_str()); 70 71 return ret; 72 } 73 74 #else 75 main()76int main() 77 { 78 return 0; 79 } 80 81 #endif //#ifdef BOOST_WINDOWS 82