blob: 74d7064f7ac2209217eaa0c63090d50fc44a4e6e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#pragma once
#include <boost/algorithm/string.hpp>
#include <boost/beast/core.hpp>
#include <boost/beast/http.hpp>
#include <boost/beast/websocket.hpp>
#include <boost/beast/websocket/ssl.hpp>
#include <boost/beast/ssl.hpp>
#include <boost/beast/version.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/buffers_iterator.hpp>
#include <boost/asio/connect.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/ssl/error.hpp>
#include <boost/asio/ssl/stream.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <functional>
#include <memory>
#include <mutex>
#include <string>
class WebsocketServerProcess
{
// shared data between Unix processes
struct shared_data_t {
std::mutex mutex; // for synchronization between processes (!)
char subprotocol[1024]{}; // instead of std::string since std::string allocates data on heap
char target[1024]{};
};
public:
WebsocketServerProcess();
~WebsocketServerProcess();
bool is_running();
void start();
void stop();
std::string subprotocol();
std::string target();
private:
void do_session(boost::asio::ip::tcp::socket socket);
private:
int m_pid{};
int m_count{};
std::unique_ptr<shared_data_t, std::function<void(shared_data_t*)>> m_shared;
}; // class WebsocketServerProcess
|