]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/log/example/doc/sinks_ipc_receiver.cpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / log / example / doc / sinks_ipc_receiver.cpp
CommitLineData
7c673cae
FG
1/*
2 * Copyright Lingxi Li 2015.
3 * Copyright Andrey Semashev 2016.
4 * Distributed under the Boost Software License, Version 1.0.
5 * (See accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
7 */
8
9#include <iostream>
10#include <string>
11#include <exception>
12#include <boost/log/utility/ipc/reliable_message_queue.hpp>
13#include <boost/log/utility/ipc/object_name.hpp>
14#include <boost/log/utility/open_mode.hpp>
15
16namespace logging = boost::log;
17namespace keywords = boost::log::keywords;
18
19//[ example_sinks_ipc_receiver
20int main()
21{
22 try
23 {
24 typedef logging::ipc::reliable_message_queue queue_t;
25
26 // Create a message_queue_type object that is associated with the interprocess
27 // message queue named "ipc_message_queue".
28 queue_t queue
29 (
30 keywords::name = logging::ipc::object_name(logging::ipc::object_name::user, "ipc_message_queue"),
31 keywords::open_mode = logging::open_mode::open_or_create,
32 keywords::capacity = 256,
33 keywords::block_size = 1024,
34 keywords::overflow_policy = queue_t::block_on_overflow
35 );
36
37 std::cout << "Viewer process running..." << std::endl;
38
39 // Keep reading log messages from the associated message queue and print them on the console.
40 // queue.receive() will block if the queue is empty.
41 std::string message;
42 while (queue.receive(message) == queue_t::succeeded)
43 {
44 std::cout << message << std::endl;
45
46 // Clear the buffer for the next message
47 message.clear();
48 }
49 }
50 catch (std::exception& e)
51 {
52 std::cout << "Failure: " << e.what() << std::endl;
53 }
54
55 return 0;
56}
57//]