7 #include "server/connection/isubscriber.h" 8 #include "server/channel/channels_manager.h" 9 #include "protocol/protocol.h" 10 #include "server/log/logger.h" 24 explicit Connection(boost::asio::ip::tcp::socket&& _socket, database_ptr _db):
25 socket(std::move(_socket)),
30 BOOST_LOG_TRIVIAL(info) <<
"new connection from " << socket.remote_endpoint().address().to_string()
31 <<
":" << socket.remote_endpoint().port();
38 void reuse(boost::asio::ip::tcp::socket&& _socket)
override;
44 BOOST_LOG_TRIVIAL(info) <<
"Connection start read_request_header().";
45 read_request_header();
52 virtual void sendme(text_response_ptr response)
override;
68 virtual const std::string&
get_login()
const override {
return login; }
70 virtual bool is_busy()
const noexcept
override {
return busy; }
71 virtual void set_busy(
bool flag =
true) noexcept
override { busy = flag; }
73 virtual void free_connection()
override;
80 boost::asio::ip::tcp::socket socket;
82 std::deque<response_ptr> packets_to_client;
84 identifier_t client_id;
89 std::atomic<bool> busy;
97 void read_request_header();
102 void read_request_body(registr_request_ptr);
107 void read_request_body(autor_request_ptr);
112 void read_request_body(text_request_ptr);
117 void read_request_body(join_room_request_ptr);
124 void send_response_header();
129 void send_response_data();
136 identifier_t generate_client_id() {
137 static identifier_t
id = 0;
142 using connection_ptr = std::shared_ptr<Connection>;
144 #endif // CONNECTION_H virtual void start() override
Entry point to handle incoming requests.
Definition: connection.h:43
void reuse(boost::asio::ip::tcp::socket &&_socket) override
reuse connection for Object Pool
Definition: connection.cpp:3
Channel Subscriber Interface.
Definition: isubscriber.h:13
virtual const std::string & get_login() const override
Get the login.
Definition: connection.h:68
virtual void sendme(text_response_ptr response) override
Send response message to the client.
Definition: connection.cpp:41
Connection class.
Definition: connection.h:16
Connection(boost::asio::ip::tcp::socket &&_socket, database_ptr _db)
Construct a new Connection object.
Definition: connection.h:24
virtual identifier_t get_client_id() const override
Get the client id object.
Definition: connection.h:59