2 * Copyright Andrey Semashev 2016.
3 * Distributed under the Boost Software License, Version 1.0.
4 * (See accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt)
10 #include <boost/log/utility/ipc/reliable_message_queue.hpp>
11 #include <boost/log/utility/ipc/object_name.hpp>
12 #include <boost/log/utility/open_mode.hpp>
14 namespace logging
= boost::log
;
15 namespace keywords
= boost::log::keywords
;
17 //[ example_util_ipc_reliable_mq_writer
20 typedef logging::ipc::reliable_message_queue queue_t
;
22 // Create a message_queue_type object that is associated with the interprocess
23 // message queue named "ipc_message_queue".
26 keywords::name
= logging::ipc::object_name(logging::ipc::object_name::user
, "ipc_message_queue"),
27 keywords::open_mode
= logging::open_mode::open_or_create
, /*< create the queue, if not yet created >*/
28 keywords::capacity
= 256, /*< if the queue has to be created, allocate 256 blocks... >*/
29 keywords::block_size
= 1024, /*< ... of 1 KiB each for messages >*/
30 keywords::overflow_policy
= queue_t::fail_on_overflow
/*< if the queue is full, return error to the writer >*/
33 // Send a message through the queue
34 std::string message
= "Hello, Viewer!";
35 queue_t::operation_result result
= queue
.send(message
.data(), message
.size());
37 // See if the message was sent
40 case queue_t::operation_result::succeeded
:
41 std::cout
<< "Message sent successfully" << std::endl
;
44 case queue_t::operation_result::no_space
:
45 std::cout
<< "Message could not be sent because the queue is full" << std::endl
;
48 case queue_t::operation_result::aborted
:
49 // This can happen is overflow_policy is block_on_overflow
50 std::cout
<< "Message sending operation has been interrupted" << std::endl
;