]> git.proxmox.com Git - ceph.git/blob - ceph/src/Beast/examples/websocket_echo.cpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / Beast / examples / websocket_echo.cpp
1 //
2 // Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7
8 #include "websocket_async_echo_server.hpp"
9 #include "websocket_sync_echo_server.hpp"
10 #include <boost/asio/io_service.hpp>
11 #include <boost/asio/signal_set.hpp>
12 #include <iostream>
13
14 /// Block until SIGINT or SIGTERM is received.
15 void
16 sig_wait()
17 {
18 boost::asio::io_service ios;
19 boost::asio::signal_set signals(
20 ios, SIGINT, SIGTERM);
21 signals.async_wait(
22 [&](boost::system::error_code const&, int)
23 {
24 });
25 ios.run();
26 }
27
28 int main()
29 {
30 using namespace beast::websocket;
31 using endpoint_type = boost::asio::ip::tcp::endpoint;
32 using address_type = boost::asio::ip::address;
33
34 beast::error_code ec;
35
36 permessage_deflate pmd;
37 pmd.client_enable = true;
38 pmd.server_enable = true;
39 pmd.compLevel = 3;
40
41 websocket::async_echo_server s1{&std::cout, 1};
42 s1.set_option(read_message_max{64 * 1024 * 1024});
43 s1.set_option(auto_fragment{false});
44 s1.set_option(pmd);
45 s1.open(endpoint_type{
46 address_type::from_string("127.0.0.1"), 6000 }, ec);
47
48 websocket::sync_echo_server s2{&std::cout};
49 s2.set_option(read_message_max{64 * 1024 * 1024});
50 s2.set_option(auto_fragment{false});
51 s2.set_option(pmd);
52 s2.open(endpoint_type{
53 address_type::from_string("127.0.0.1"), 6001 }, ec);
54
55 sig_wait();
56 }