28 :
public std::enable_shared_from_this<socketio_server_connection>
38 void send_text(
const std::string& msg);
39 void send_text(
const char* data, std::size_t sz);
40 void send_binary(std::string_view msg);
43 boost::asio::ip::tcp::socket& tcp_socket();
44 const std::string& sid()
const {
return m_config.sid; }
48 void on_read_http(boost::beast::error_code ec, std::size_t bytes);
51 void handle_polling_get(
52 boost::beast::http::request<boost::beast::http::string_body>& req);
53 void handle_polling_post(
54 boost::beast::http::request<boost::beast::http::string_body>& req);
55 void handle_new_connection(
56 boost::beast::http::request<boost::beast::http::string_body>& req);
57 void send_http_response(
58 unsigned version, boost::beast::http::status status,
59 const std::string& body,
const std::string& content_type =
"text/plain");
63 boost::beast::http::request<boost::beast::http::string_body> req);
64 void on_accept_ws(boost::beast::error_code ec);
66 void on_read_ws(boost::beast::error_code ec, std::size_t bytes);
69 void start_ping_timer();
70 void on_ping_timer(boost::beast::error_code ec);
73 void process_engineio_message(std::string_view data);
74 void dispatch_socketio_message(std::string_view data);
76 static std::string generate_sid();
78 boost::beast::websocket::stream<boost::beast::tcp_stream> m_ws;
79 boost::beast::flat_buffer m_buffer;
80 boost::beast::http::request<boost::beast::http::string_body> m_http_req;
81 boost::asio::steady_timer m_ping_timer;
86 std::vector<std::string> m_poll_buffer;
88 bool m_is_websocket{
false};
89 bool m_handshake_done{
false};
90 bool m_upgraded{
false};
105 void listen(uint16_t port)
override;
107 void stop()
override;
108 void close(ws_connection_handle hdl)
override;
110 void set_open_handler(ws_open_handler h)
override;
111 void set_close_handler(ws_close_handler h)
override;
112 void set_message_handler(ws_server_message_handler h)
override;
114 std::string get_remote_ip(
const ws_connection_handle& hdl)
override;
115 std::string get_remote_endpoint(
const ws_connection_handle& hdl)
override;
116 std::string get_local_ip(
const ws_connection_handle& hdl)
override;
118 void send_message(ws_connection_handle hdl,
const std::string&
message)
override;
119 void send_message(ws_connection_handle hdl,
const server_reply&
message)
override;
121 send_message(ws_connection_handle hdl,
const rapidjson::StringBuffer&
message)
override;
122 void send_binary_message(ws_connection_handle hdl, std::string_view
message)
override;
126 void on_accept(boost::beast::error_code ec, boost::asio::ip::tcp::socket socket);
127 void add_connection(std::shared_ptr<socketio_server_connection> conn);
128 void remove_connection(std::shared_ptr<socketio_server_connection> conn);
136 ossia::net::network_context_ptr m_context;
137 boost::asio::ip::tcp::acceptor m_acceptor;
138 std::set<std::shared_ptr<socketio_server_connection>> m_connections;
139 std::mutex m_connections_mutex;
141 ws_open_handler m_on_open;
142 ws_close_handler m_on_close;
143 ws_server_message_handler m_on_message;