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 | |
28 | inline 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::open_or_create_shared_directory(shared_dir.c_str()); |
35 | dir_created = true; |
36 | } |
37 | |
38 | inline void get_shared_dir(std::wstring &shared_dir) |
39 | { |
40 | shared_dir = boost::interprocess::ipcdetail::get_temporary_wpath(); |
41 | shared_dir += L"/boostipctest_" ; |
42 | shared_dir += boost::interprocess::test::get_process_id_wname(); |
43 | if(!dir_created) |
44 | ipcdetail::open_or_create_shared_directory(shared_dir.c_str()); |
45 | dir_created = true; |
46 | } |
47 | |
48 | }}} //namespace boost::interprocess::ipcdetail |
49 | |
50 | #include <boost/interprocess/shared_memory_object.hpp> |
51 | #include <iostream> |
52 | |
53 | int main () |
54 | { |
55 | using namespace boost::interprocess; |
56 | const char *const shm_name = "test_shm" ; |
57 | std::string shared_dir; |
58 | ipcdetail::get_shared_dir(shared_dir); |
59 | |
60 | std::string shm_path(shared_dir); |
61 | shm_path += "/" ; |
62 | shm_path += shm_name; |
63 | |
64 | int ret = 0; |
65 | shared_memory_object::remove(shm_name); |
66 | { |
67 | { |
68 | shared_memory_object shm(create_only, shm_name, read_write); |
69 | } |
70 | |
71 | ret = ipcdetail::invalid_file() == ipcdetail::open_existing_file(shm_path.c_str(), read_only) ? |
72 | 1 : 0; |
73 | if(ret) |
74 | { |
75 | std::cerr << "Error opening user get_shared_dir()/shm file" << std::endl; |
76 | } |
77 | } |
78 | shared_memory_object::remove(shm_name); |
79 | ipcdetail::remove_directory(shared_dir.c_str()); |
80 | |
81 | return ret; |
82 | } |
83 | |
84 | #else |
85 | |
86 | int main() |
87 | { |
88 | return 0; |
89 | } |
90 | |
91 | #endif //#ifdef BOOST_WINDOWS |
92 | |