]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ////////////////////////////////////////////////////////////////////////////// | |
1e59de90 | 10 | |
7c673cae FG |
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 | { | |
1e59de90 | 20 | BOOST_TRY{ |
7c673cae FG |
21 | //Open a message queue. |
22 | message_queue mq | |
1e59de90 | 23 | (open_only //only open |
7c673cae FG |
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 | } | |
1e59de90 | 38 | BOOST_CATCH(interprocess_exception &ex){ |
7c673cae FG |
39 | message_queue::remove("message_queue"); |
40 | std::cout << ex.what() << std::endl; | |
41 | return 1; | |
1e59de90 | 42 | } BOOST_CATCH_END |
7c673cae FG |
43 | message_queue::remove("message_queue"); |
44 | return 0; | |
45 | } | |
46 | //] | |
1e59de90 | 47 |