Horizon Official Technical Documentation
AuthSocket.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_SOCKET_AUTHSOCKET_HPP
31#define HORIZON_SOCKET_AUTHSOCKET_HPP
32
34
35#include <cstdio>
36#include <boost/asio/ip/tcp.hpp>
37#include <memory>
38
39using boost::asio::ip::tcp;
40
41namespace Horizon
42{
43namespace Auth
44{
45class AuthSession;
46class AuthSocket : public Horizon::Networking::Socket<AuthSocket>
47{
48 typedef Socket<AuthSocket> BaseSocket;
49public:
50 explicit AuthSocket(uint64_t uid);
51 explicit AuthSocket(uint64_t uid, std::shared_ptr<tcp::socket> socket);
53 /* */
54 virtual void start() override;
55 bool update() override;
56
57 /* Session */
58 std::shared_ptr<AuthSession> get_session();
59 void set_session(std::shared_ptr<AuthSession> 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<AuthSession> _session;
70};
71}
72}
73
74#endif /* HORIZON_SOCKET_AuthSocket_HPP */
Definition: AuthSocket.hpp:47
bool update() override
Asynchronous update method periodically called from network threads.
Definition: AuthSocket.cpp:103
~AuthSocket()
Definition: AuthSocket.cpp:48
void update_session(uint32_t diff)
Packets are processed within the session associated with this socket.
Definition: AuthSocket.cpp:156
void on_close() override
Socket cleanup method on connection closure.
Definition: AuthSocket.cpp:81
void on_error() override
Method invoked when an error occured during a read operation on the socket.
Definition: AuthSocket.cpp:93
std::shared_ptr< AuthSession > _session
Definition: AuthSocket.hpp:69
std::shared_ptr< AuthSession > get_session()
@thread created by network thread and called from main thread / client-sockt-mgr for update().
Definition: AuthSocket.cpp:56
Socket< AuthSocket > BaseSocket
Definition: AuthSocket.hpp:48
void set_session(std::shared_ptr< AuthSession > session)
Definition: AuthSocket.cpp:57
virtual void start() override
Initial method invoked once from the network thread that handles the AuthSocket.
Definition: AuthSocket.cpp:63
AuthSocket(uint64_t uid)
Definition: AuthSocket.cpp:38
void read_handler() override
Read handler for when a message is read from the network and placed within this socket's message buff...
Definition: AuthSocket.cpp:116
A Socket object that handles a single connection.
Definition: Socket.hpp:82
Definition: Element.hpp:7