-
Notifications
You must be signed in to change notification settings - Fork 1
/
http_connection_impl.hpp
66 lines (44 loc) · 1.84 KB
/
http_connection_impl.hpp
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
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once
#include "http_connection.hpp"
#include <boost/asio.hpp>
#include <boost/beast.hpp>
#include <memory>
#include <deque>
namespace http {
using http_request_ptr = std::shared_ptr<boost::beast::http::request<boost::beast::http::string_body>>;
using http_response_ptr = std::shared_ptr<boost::beast::http::response<boost::beast::http::string_body>>;
class connection_impl : public connection, public std::enable_shared_from_this<connection_impl> {
public:
~connection_impl() override = default;
connection_impl(
boost::asio::io_service& ioc,
const uint32_t index,
const std::shared_ptr<boost::asio::ip::tcp::socket> &tcp,
const close_cb &on_socket_closed,
const std::string& detected_devices_json);
void start() override;
void stop() override;
uint32_t index() const override { return m_index; }
bool got_quit() const override { return m_got_quit; }
private:
void write(boost::beast::http::response<boost::beast::http::string_body> const &response);
void handle_write(const boost::system::error_code &ec, std::size_t bytes_transferred, http_response_ptr const &rp);
void read();
void handle_read(
const boost::system::error_code &ec,
std::size_t bytes_transferred,
std::shared_ptr<boost::beast::flat_buffer> const &flat_buffer,
http_request_ptr const &request);
void close_socket();
void handle_request(const http_request_ptr& request);
const uint32_t m_index;
boost::asio::io_service& m_io_service;
boost::asio::io_service::strand m_strand;
boost::asio::deadline_timer m_disconnect_timer;
close_cb m_on_socket_closed;
std::shared_ptr<boost::asio::ip::tcp::socket> m_tcp;
bool m_closed = false;
std::string m_detected_devices_json;
bool m_got_quit = false;
};
}