]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/interprocess/example/comp_doc_message_queueB.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / interprocess / example / comp_doc_message_queueB.cpp
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2006-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 //[doc_message_queueB
12 #include <boost/interprocess/ipc/message_queue.hpp>
13 #include <iostream>
14 #include <vector>
15
16 using namespace boost::interprocess;
17
18 int main ()
19 {
20 try{
21 //Open a message queue.
22 message_queue mq
23 (open_only //only create
24 ,"message_queue" //name
25 );
26
27 unsigned int priority;
28 message_queue::size_type recvd_size;
29
30 //Receive 100 numbers
31 for(int i = 0; i < 100; ++i){
32 int number;
33 mq.receive(&number, sizeof(number), recvd_size, priority);
34 if(number != i || recvd_size != sizeof(number))
35 return 1;
36 }
37 }
38 catch(interprocess_exception &ex){
39 message_queue::remove("message_queue");
40 std::cout << ex.what() << std::endl;
41 return 1;
42 }
43 message_queue::remove("message_queue");
44 return 0;
45 }
46 //]
47 #include <boost/interprocess/detail/config_end.hpp>