windows_shared_memory_test.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #include <boost/interprocess/detail/config_begin.hpp>
  11. #include <boost/interprocess/detail/workaround.hpp>
  12. #ifdef BOOST_INTERPROCESS_WINDOWS
  13. #include <boost/interprocess/windows_shared_memory.hpp>
  14. #include <boost/interprocess/detail/managed_open_or_create_impl.hpp>
  15. #include <boost/interprocess/exceptions.hpp>
  16. #include "named_creation_template.hpp"
  17. #include <cstring> //for strcmp, memset
  18. #include <iostream> //for cout
  19. #include <string> //for string
  20. #include "get_process_id_name.hpp"
  21. using namespace boost::interprocess;
  22. static const char *name_initialization_routine()
  23. {
  24. static std::string process_name;
  25. test::get_process_id_name(process_name);
  26. return process_name.c_str();
  27. }
  28. static const std::size_t ShmSize = 1000;
  29. typedef ipcdetail::managed_open_or_create_impl
  30. <windows_shared_memory, 0, false, false> windows_shared_memory_t;
  31. //This wrapper is necessary to have a common constructor
  32. //in generic named_creation_template functions
  33. class shared_memory_creation_test_wrapper
  34. : public windows_shared_memory_t
  35. {
  36. public:
  37. shared_memory_creation_test_wrapper(create_only_t)
  38. : windows_shared_memory_t(create_only, name_initialization_routine(), ShmSize, read_write, 0, permissions())
  39. {}
  40. shared_memory_creation_test_wrapper(open_only_t)
  41. : windows_shared_memory_t(open_only, name_initialization_routine(), read_write, 0)
  42. {}
  43. shared_memory_creation_test_wrapper(open_or_create_t)
  44. : windows_shared_memory_t(open_or_create, name_initialization_routine(), ShmSize, read_write, 0, permissions())
  45. {}
  46. };
  47. int main ()
  48. {
  49. try{
  50. test::test_named_creation<shared_memory_creation_test_wrapper>();
  51. }
  52. catch(std::exception &ex){
  53. std::cout << ex.what() << std::endl;
  54. return 1;
  55. }
  56. return 0;
  57. }
  58. #else
  59. int main()
  60. {
  61. return 0;
  62. }
  63. #endif //#ifdef BOOST_INTERPROCESS_WINDOWS
  64. #include <boost/interprocess/detail/config_end.hpp>