Horizon Official Technical Documentation
ZoneSocket.hpp
Go to the documentation of this file.
1/***************************************************
2 * _ _ _ *
3 * | | | | (_) *
4 * | |_| | ___ _ __ _ _______ _ __ *
5 * | _ |/ _ \| '__| |_ / _ \| '_ \ *
6 * | | | | (_) | | | |/ / (_) | | | | *
7 * \_| |_/\___/|_| |_/___\___/|_| |_| *
8 ***************************************************
9 * This file is part of Horizon (c).
10 *
11 * Copyright (c) 2019 Sagun K. (sagunxp@gmail.com).
12 * Copyright (c) 2019 Horizon Dev Team.
13 *
14 * Base Author - Sagun K. (sagunxp@gmail.com)
15 *
16 * This library is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this library. If not, see <http://www.gnu.org/licenses/>.
28 **************************************************/
29
30#ifndef HORIZON_ZONE_ZONESOCKET_HPP
31#define HORIZON_ZONE_ZONESOCKET_HPP
32
34
35using boost::asio::ip::tcp;
36
37namespace Horizon
38{
39namespace Zone
40{
41class ZoneSession;
42class ZoneSocket : public Horizon::Networking::Socket<ZoneSocket>
43{
44 typedef Socket<ZoneSocket> BaseSocket;
45public:
46 ZoneSocket(uint64_t uid, std::shared_ptr<tcp::socket> socket);
48 /* */
49 void start() override;
50 bool update() override;
51
52 /* */
53 std::shared_ptr<ZoneSession> get_session();
54 void set_session(std::shared_ptr<ZoneSession> session);
55protected:
56 void read_handler() override;
57 void on_close() override;
58 void on_error() override;
59
60 std::shared_ptr<ZoneSession> _session;
61};
62}
63}
64#endif //HORIZON_ZONE_ZONESOCKET_HPP
A Socket object that handles a single connection.
Definition: Socket.hpp:82
declared to avoid recursive inclusion of header files.
Definition: ZoneSocket.hpp:43
std::shared_ptr< ZoneSession > get_session()
Session dependency.
Definition: ZoneSocket.cpp:48
void start() override
Initial method invoked once from the network thread that handles the ZoneSocket.
Definition: ZoneSocket.cpp:54
std::shared_ptr< ZoneSession > _session
Definition: ZoneSocket.hpp:60
void on_error() override
Socket error handler.
Definition: ZoneSocket.cpp:88
~ZoneSocket()
Definition: ZoneSocket.hpp:47
Socket< ZoneSocket > BaseSocket
Definition: ZoneSocket.hpp:44
bool update() override
Asynchronous update method periodically called from network threads.
Definition: ZoneSocket.cpp:101
ZoneSocket(uint64_t uid, std::shared_ptr< tcp::socket > socket)
Definition: ZoneSocket.cpp:37
void set_session(std::shared_ptr< ZoneSession > session)
Definition: ZoneSocket.cpp:49
void on_close() override
Socket cleanup method on connection closure.
Definition: ZoneSocket.cpp:74
void read_handler() override
Incoming buffer read handler.
Definition: ZoneSocket.cpp:109
Definition: Element.hpp:7