Horizon Official Technical Documentation
Horizon::Networking::Session< SocketType, SessionType > Class Template Referenceabstract

A Session object that handles a single socket. Sockets are moved into the thread by SocketMgr, once accepted or connected. Once started, the object blocks to handle I/O events and requires explicit stopping. More...

#include <Session.hpp>

+ Inheritance diagram for Horizon::Networking::Session< SocketType, SessionType >:
+ Collaboration diagram for Horizon::Networking::Session< SocketType, SessionType >:

Public Member Functions

 Session (uint64_t uid)
 
virtual ~Session ()
 
std::shared_ptr< SocketType > get_socket ()
 Get the socket. More...
 
void set_socket (std::weak_ptr< SocketType > socket)
 Set the socket. More...
 
virtual void update (uint32_t diff)=0
 
virtual void initialize ()=0
 
bool is_initialized ()
 Called to verify if the session is initialized. More...
 
void set_initialized (bool initialized)
 Set whether the session is initialized or not. More...
 
uint64_t get_session_id ()
 Get the unique id of the session. More...
 
ThreadSafeQueue< ByteBuffer > & get_recv_queue ()
 Receive queue of the buffer received by the socket. More...
 

Private Attributes

ThreadSafeQueue< ByteBuffer_buffer_recv_queue
 
std::weak_ptr< SocketType > _socket
 
bool _is_initialized { false }
 
uint64_t _uid { 0 }
 

Detailed Description

template<class SocketType, class SessionType>
class Horizon::Networking::Session< SocketType, SessionType >

A Session object that handles a single socket. Sockets are moved into the thread by SocketMgr, once accepted or connected. Once started, the object blocks to handle I/O events and requires explicit stopping.

Template Parameters
SocketTypeThe type of socket to use.
SessionTypeThe type of session to use.
Parameters
uidThe unique id of the session.
socketThe socket to use.
is_initializedWhether the session is initialized or not.
_uidThe unique id of the session.
_socketThe socket to use.

Constructor & Destructor Documentation

◆ Session()

template<class SocketType , class SessionType >
Horizon::Networking::Session< SocketType, SessionType >::Session ( uint64_t  uid)
inline
58 : _uid(uid)
59 {
60 //
61 }
uint64_t _uid
Definition: Session.hpp:106

◆ ~Session()

template<class SocketType , class SessionType >
virtual Horizon::Networking::Session< SocketType, SessionType >::~Session ( )
inlinevirtual
64 {
65 //
66 }

Member Function Documentation

◆ get_recv_queue()

template<class SocketType , class SessionType >
ThreadSafeQueue< ByteBuffer > & Horizon::Networking::Session< SocketType, SessionType >::get_recv_queue ( )
inline

Receive queue of the buffer received by the socket.

Returns
Queue of ByteBuffer type.
101{ return _buffer_recv_queue; }
ThreadSafeQueue< ByteBuffer > _buffer_recv_queue
Definition: Session.hpp:103

References Horizon::Networking::Session< SocketType, SessionType >::_buffer_recv_queue.

◆ get_session_id()

template<class SocketType , class SessionType >
uint64_t Horizon::Networking::Session< SocketType, SessionType >::get_session_id ( )
inline

Get the unique id of the session.

Returns
int64_t
97{ return _uid; }

References Horizon::Networking::Session< SocketType, SessionType >::_uid.

◆ get_socket()

template<class SocketType , class SessionType >
std::shared_ptr< SocketType > Horizon::Networking::Session< SocketType, SessionType >::get_socket ( )
inline

Get the socket.

Returns
The socket.
70{ return _socket.lock(); }
std::weak_ptr< SocketType > _socket
Definition: Session.hpp:104

References Horizon::Networking::Session< SocketType, SessionType >::_socket.

◆ initialize()

template<class SocketType , class SessionType >
virtual void Horizon::Networking::Session< SocketType, SessionType >::initialize ( )
pure virtual

Called when the session is started. Virtual method that must be implmented by the derived class. Typically used to initialize the session.

Returns
void

Implemented in Horizon::Char::CharSession, Horizon::Zone::ZoneSession, and Horizon::Auth::AuthSession.

◆ is_initialized()

template<class SocketType , class SessionType >
bool Horizon::Networking::Session< SocketType, SessionType >::is_initialized ( )
inline

Called to verify if the session is initialized.

Returns
bool
88{ return _is_initialized; }
bool _is_initialized
Definition: Session.hpp:105

References Horizon::Networking::Session< SocketType, SessionType >::_is_initialized.

◆ set_initialized()

template<class SocketType , class SessionType >
void Horizon::Networking::Session< SocketType, SessionType >::set_initialized ( bool  initialized)
inline

Set whether the session is initialized or not.

Parameters
initializedWhether the session is initialized or not.
Returns
void
93{ _is_initialized = initialized; }

References Horizon::Networking::Session< SocketType, SessionType >::_is_initialized.

◆ set_socket()

template<class SocketType , class SessionType >
void Horizon::Networking::Session< SocketType, SessionType >::set_socket ( std::weak_ptr< SocketType >  socket)
inline

Set the socket.

Parameters
socketThe socket.
Returns
void
74{ _socket.swap(socket); }

References Horizon::Networking::Session< SocketType, SessionType >::_socket.

◆ update()

template<class SocketType , class SessionType >
virtual void Horizon::Networking::Session< SocketType, SessionType >::update ( uint32_t  diff)
pure virtual

Called when the session is started. Virtual method that must be implmented by the derived class. Typically used to update the session and process packets.

Returns
void

Implemented in Horizon::Char::CharSession, Horizon::Zone::ZoneSession, and Horizon::Auth::AuthSession.

Member Data Documentation

◆ _buffer_recv_queue

template<class SocketType , class SessionType >
ThreadSafeQueue<ByteBuffer> Horizon::Networking::Session< SocketType, SessionType >::_buffer_recv_queue
private

◆ _is_initialized

template<class SocketType , class SessionType >
bool Horizon::Networking::Session< SocketType, SessionType >::_is_initialized { false }
private

◆ _socket

template<class SocketType , class SessionType >
std::weak_ptr<SocketType> Horizon::Networking::Session< SocketType, SessionType >::_socket
private

◆ _uid

template<class SocketType , class SessionType >
uint64_t Horizon::Networking::Session< SocketType, SessionType >::_uid { 0 }
private

The documentation for this class was generated from the following file: