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
11//[doc_message_queueB
12#include <boost/interprocess/ipc/message_queue.hpp>
13#include <iostream>
14#include <vector>
15
16using namespace boost::interprocess;
17
18int main ()
19{
20 BOOST_TRY{
21 //Open a message queue.
22 message_queue mq
23 (open_only //only open
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(buffer: &number, buffer_size: sizeof(number), recvd_size, priority);
34 if(number != i || recvd_size != sizeof(number))
35 return 1;
36 }
37 }
38 BOOST_CATCH(interprocess_exception &ex){
39 message_queue::remove(name: "message_queue");
40 std::cout << ex.what() << std::endl;
41 return 1;
42 } BOOST_CATCH_END
43 message_queue::remove(name: "message_queue");
44 return 0;
45}
46//]
47
48

source code of boost/libs/interprocess/example/comp_doc_message_queueB.cpp