Horizon Official Technical Documentation
|
|
A Network Thread object that handles a number of sockets. More...
#include <NetworkThread.hpp>
Public Member Functions | |
NetworkThread () | |
virtual | ~NetworkThread () |
Destructor of the network thread, performs a clean network finalisation routine before deleting. More... | |
virtual void | finalize () |
Halts the IO Service and marks the network thread as stopped. More... | |
void | join () |
virtual bool | start (int segment_number=1) |
Initializes the network thread and runs. More... | |
virtual void | add_socket (std::shared_ptr< SocketType > sock) |
Adds a new socket to a queue that is processed frequently within this network thread. More... | |
std::shared_ptr< tcp::socket > | get_new_socket () |
Gets a socket for a new connection. More... | |
int32_t | connection_count () const |
Gets the total number of network connections or sockets handled by this network thread. More... | |
bool | is_finalizing () |
Issues the status of network thread whether it is finalizing or not. More... | |
Protected Member Functions | |
virtual void | run () |
Run the I/O Service loop within this network thread. More... | |
virtual void | on_socket_removed (std::shared_ptr< SocketType > sock)=0 |
virtual void | on_socket_added (std::shared_ptr< SocketType > sock)=0 |
virtual void | update () |
Updates the network thread and schedules a recursive call to itself. More... | |
virtual void | add_new_sockets () |
Processess the new socket queue. More... | |
Protected Attributes | |
SocketContainer | _active_sockets |
Private Types | |
typedef std::vector< std::shared_ptr< SocketType > > | SocketContainer |
Private Attributes | |
int | _segment_number {1} |
std::atomic< int32_t > | _connections |
std::atomic< bool > | _finalizing |
std::unique_ptr< std::thread > | _thread |
SocketContainer | _new_socket_queue |
std::mutex | _new_socket_queue_lock |
boost::asio::io_context | _io_context |
boost::asio::deadline_timer | _update_timer |
A Network Thread object that handles a number of sockets.
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.
|
private |
|
inline |
|
inlinevirtual |
Destructor of the network thread, performs a clean network finalisation routine before deleting.
References Horizon::Networking::NetworkThread< SocketType >::finalize().
|
inlineprotectedvirtual |
Processess the new socket queue.
This method is responsible for - 1) Processing the entire list of new sockets and clearing it on every call. 2) removing / closing new sockets that are not open. 3) Starting the new socket once added to the container. (
References HLog.
Referenced by Horizon::Networking::NetworkThread< SocketType >::update().
|
inlinevirtual |
Adds a new socket to a queue that is processed frequently within this network thread.
The method update() is called regularly to add new sockets to the thread's active socket list.
References Horizon::Networking::NetworkThread< SocketType >::_new_socket_queue, and Horizon::Networking::NetworkThread< SocketType >::_new_socket_queue_lock.
|
inline |
Gets the total number of network connections or sockets handled by this network thread.
References Horizon::Networking::NetworkThread< SocketType >::_connections.
|
inlinevirtual |
Halts the IO Service and marks the network thread as stopped.
Reimplemented in Horizon::Auth::AuthNetworkThread, Horizon::Char::CharNetworkThread, and Horizon::Zone::ZoneNetworkThread.
References Horizon::Networking::NetworkThread< SocketType >::_finalizing.
Referenced by Horizon::Auth::AuthNetworkThread::finalize(), Horizon::Char::CharNetworkThread::finalize(), Horizon::Zone::ZoneNetworkThread::finalize(), and Horizon::Networking::NetworkThread< SocketType >::~NetworkThread().
|
inline |
Gets a socket for a new connection.
This method is used as a socket factory in AsyncAcceptor and Connector classes. Once a socket is accepted or connected, its ownership is moved into a network thread.
References Horizon::Networking::NetworkThread< SocketType >::_io_context.
|
inline |
Issues the status of network thread whether it is finalizing or not.
References Horizon::Networking::NetworkThread< SocketType >::_finalizing.
|
inline |
References Horizon::Networking::NetworkThread< SocketType >::_thread, and HLog.
|
protectedpure virtual |
|
protectedpure virtual |
|
inlineprotectedvirtual |
Run the I/O Service loop within this network thread.
Before running, this method gives the I/O service some work by asynchronously running a deadline timer on
Reimplemented in Horizon::Auth::AuthNetworkThread, Horizon::Char::CharNetworkThread, and Horizon::Zone::ZoneNetworkThread.
References Horizon::Networking::NetworkThread< SocketType >::_active_sockets, Horizon::Networking::NetworkThread< SocketType >::_io_context, Horizon::Networking::NetworkThread< SocketType >::_new_socket_queue, and Horizon::Networking::NetworkThread< SocketType >::_update_timer.
Referenced by Horizon::Auth::AuthNetworkThread::run(), Horizon::Char::CharNetworkThread::run(), Horizon::Zone::ZoneNetworkThread::run(), and Horizon::Networking::NetworkThread< SocketType >::start().
|
inlinevirtual |
Initializes the network thread and runs.
Reimplemented in Horizon::Auth::AuthNetworkThread, Horizon::Char::CharNetworkThread, and Horizon::Zone::ZoneNetworkThread.
References Horizon::Networking::NetworkThread< SocketType >::_segment_number, Horizon::Networking::NetworkThread< SocketType >::_thread, and Horizon::Networking::NetworkThread< SocketType >::run().
|
inlineprotectedvirtual |
Updates the network thread and schedules a recursive call to itself.
This method is responsible for the following tasks - 1) Issuing a routine to process the new sockets queue. 2) Closes sockets that cannot be updated.
Reimplemented in Horizon::Auth::AuthNetworkThread, Horizon::Char::CharNetworkThread, and Horizon::Zone::ZoneNetworkThread.
References Horizon::Networking::NetworkThread< SocketType >::_active_sockets, Horizon::Networking::NetworkThread< SocketType >::_update_timer, and Horizon::Networking::NetworkThread< SocketType >::add_new_sockets().
Referenced by Horizon::Auth::AuthNetworkThread::update(), Horizon::Char::CharNetworkThread::update(), and Horizon::Zone::ZoneNetworkThread::update().
|
protected |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Referenced by Horizon::Networking::NetworkThread< SocketType >::start().
|
private |
|
private |