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_PATH boost::interprocess::ipcdetail::get_temporary_path() |
17 | #define BOOST_INTERPROCESS_SHARED_DIR_WPATH boost::interprocess::ipcdetail::get_temporary_wpath() |
18 | #include <string> |
19 | |
20 | #include "get_process_id_name.hpp" |
21 | |
22 | #include <boost/interprocess/shared_memory_object.hpp> |
23 | #include <iostream> |
24 | |
25 | int main () |
26 | { |
27 | using namespace boost::interprocess; |
28 | |
29 | int ret = 0; |
30 | |
31 | { |
32 | std::string pname= boost::interprocess::test::get_process_id_name(); |
33 | const char *const shm_name = pname.c_str(); |
34 | |
35 | shared_memory_object::remove(shm_name); |
36 | std::string shared_dir; |
37 | ipcdetail::get_shared_dir(shared_dir); |
38 | |
39 | std::string shm_path(shared_dir); |
40 | shm_path += "/" ; |
41 | shm_path += shm_name; |
42 | { |
43 | shared_memory_object shm(create_only, shm_name, read_write); |
44 | } |
45 | |
46 | ret = ipcdetail::invalid_file() == ipcdetail::open_existing_file(shm_path.c_str(), read_only) ? |
47 | 1 : 0; |
48 | if(ret) |
49 | { |
50 | std::cerr << "Error opening user get_shared_dir()/shm file" << std::endl; |
51 | return ret; |
52 | } |
53 | |
54 | shared_memory_object::remove(shm_name); |
55 | } |
56 | { |
57 | std::wstring wpname= boost::interprocess::test::get_process_id_wname(); |
58 | const wchar_t *const wshm_name = wpname.c_str(); |
59 | |
60 | shared_memory_object::remove(wshm_name); |
61 | std::wstring wshared_dir; |
62 | ipcdetail::get_shared_dir(wshared_dir); |
63 | |
64 | shared_memory_object::remove(wshm_name); |
65 | std::wstring wshm_path(wshared_dir); |
66 | wshm_path += L"/" ; |
67 | wshm_path += wshm_name; |
68 | { |
69 | shared_memory_object shm(create_only, wshm_name, read_write); |
70 | } |
71 | ret = ipcdetail::invalid_file() == ipcdetail::open_existing_file(wshm_path.c_str(), read_only) ? |
72 | 1 : 0; |
73 | if(ret) |
74 | { |
75 | std::cerr << "Error opening user get_shared_dir()/wshm file" << std::endl; |
76 | return ret; |
77 | } |
78 | shared_memory_object::remove(wshm_name); |
79 | } |
80 | |
81 | return ret; |
82 | } |
83 | |
84 | #else |
85 | |
86 | int main() |
87 | { |
88 | return 0; |
89 | } |
90 | |
91 | #endif //#ifdef BOOST_WINDOWS |
92 | |