Horizon Official Technical Documentation
CharSocket.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_CHAR_CHARSOCKET_HPP
31#define HORIZON_CHAR_CHARSOCKET_HPP
32
34
35#include <memory>
36#include <cstdio>
37#include <boost/asio/ip/tcp.hpp>
38
39using boost::asio::ip::tcp;
40
41namespace Horizon
42{
43namespace Char
44{
45class CharSession;
46class CharSocket : public Horizon::Networking::Socket<CharSocket>
47{
48 typedef Socket<CharSocket> BaseSocket;
49public:
50 explicit CharSocket(uint64_t uid, std::shared_ptr<tcp::socket> socket);
52
53 /* */
54 void start() override;
55 bool update() override;
56
57 /* Auth Session */
58 std::shared_ptr<CharSession> get_session();
59 void set_session(std::shared_ptr<CharSession> session);
60
61 void update_session(uint32_t diff);
62
63protected:
64 void read_handler() override;
65 void on_close() override;
66 void on_error() override;
67 /* */
68private:
69 std::shared_ptr<CharSession> _session;
70};
71}
72}
73
74#endif //HORIZON_CHAR_CHARSOCKET_HPP
Definition: CharSocket.hpp:47
void start() override
Initial method invoked once from the network thread that handles the CharSocket.
Definition: CharSocket.cpp:60
std::shared_ptr< CharSession > _session
Definition: CharSocket.hpp:69
void set_session(std::shared_ptr< CharSession > session)
Definition: CharSocket.cpp:55
bool update() override
Asynchronous update method periodically called from network threads.
Definition: CharSocket.cpp:94
Socket< CharSocket > BaseSocket
Definition: CharSocket.hpp:48
CharSocket(uint64_t uid, std::shared_ptr< tcp::socket > socket)
Definition: CharSocket.cpp:40
void on_close() override
Socket cleanup method on connection closure.
Definition: CharSocket.cpp:77
void update_session(uint32_t diff)
Definition: CharSocket.cpp:138
~CharSocket()
Definition: CharSocket.cpp:46
void read_handler() override
Incoming buffer read handler.
Definition: CharSocket.cpp:105
std::shared_ptr< CharSession > get_session()
@thread created by network thread and called from main thread / client-sockt-mgr for update().
Definition: CharSocket.cpp:54
void on_error() override
Definition: CharSocket.cpp:85
A Socket object that handles a single connection.
Definition: Socket.hpp:82
Definition: Element.hpp:7