]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/log/example/doc/util_ipc_reliable_mq_writer.cpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / log / example / doc / util_ipc_reliable_mq_writer.cpp
CommitLineData
7c673cae
FG
1/*
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)
6 */
7
8#include <iostream>
9#include <string>
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>
13
14namespace logging = boost::log;
15namespace keywords = boost::log::keywords;
16
17//[ example_util_ipc_reliable_mq_writer
18int main()
19{
20 typedef logging::ipc::reliable_message_queue queue_t;
21
22 // Create a message_queue_type object that is associated with the interprocess
23 // message queue named "ipc_message_queue".
24 queue_t queue
25 (
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 >*/
31 );
32
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());
36
37 // See if the message was sent
38 switch (result)
39 {
40 case queue_t::operation_result::succeeded:
41 std::cout << "Message sent successfully" << std::endl;
42 break;
43
44 case queue_t::operation_result::no_space:
45 std::cout << "Message could not be sent because the queue is full" << std::endl;
46 break;
47
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;
51 break;
52 }
53
54 return 0;
55}
56//]