Horizon Official Technical Documentation
Horizon::Char::CharNetworkThread Class Reference

#include <ClientSocketMgr.hpp>

+ Inheritance diagram for Horizon::Char::CharNetworkThread:
+ Collaboration diagram for Horizon::Char::CharNetworkThread:

Public Member Functions

 CharNetworkThread ()
 
bool start (int segment_number=1)
 Initializes the network thread and runs. More...
 
void run () override
 Run the I/O Service loop within this network thread. More...
 
void update () override
 Updates the network thread and schedules a recursive call to itself. More...
 
virtual void initialize (int segment_number=1) override
 
virtual void finalize () override
 
virtual bool is_initialized () override
 
virtual bool is_finalized () override
 
ResourceManagerget_resource_manager ()
 
- Public Member Functions inherited from KernelComponent
 KernelComponent (Kernel *kernel, Horizon::System::runtime_module_type module_type)
 
virtual void initialize (int segment_number=1)
 
virtual void finalize ()
 
virtual bool is_initialized ()
 
virtual bool is_finalized ()
 
void set_segment_number (int64_t segment_number)
 
int64_t get_segment_number ()
 
void system_routine_queue_push (std::shared_ptr< Horizon::System::RuntimeContext > context)
 
void system_routine_queue_push (std::shared_ptr< Horizon::System::RuntimeContextChain > context)
 
void system_routine_process_queue ()
 
void system_routine_register (Horizon::System::runtime_module_type module_t, Horizon::System::runtime_synchronization_method sync_t, std::shared_ptr< Horizon::System::RuntimeContext > context)
 
const std::string get_uuid_string ()
 
const std::string get_type_string ()
 
Horizon::System::SystemRoutineManagerget_system_routine_manager ()
 
Kernelget_kernel ()
 
void set_thread_cpu_id (int cpu_id)
 
int get_thread_cpu_id ()
 
void set_thread_update_rate (double rate)
 
double get_thread_update_rate ()
 
void set_total_execution_time (int time)
 
int get_total_execution_time ()
 
void calculate_and_set_cpu_load ()
 
- Public Member Functions inherited from Horizon::Networking::NetworkThread< CharSocket >
 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< CharSocket > 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 Types

using PrimaryResource = SharedPriorityResourceMedium< s_segment_storage< uint64_t, std::shared_ptr< CharSocket > > >
 
using ResourceManager = SharedPriorityResourceManager< PrimaryResource >
 

Protected Member Functions

void on_socket_removed (std::shared_ptr< CharSocket > socket) override
 
void on_socket_added (std::shared_ptr< CharSocket > socket) override
 
- Protected Member Functions inherited from Horizon::Networking::NetworkThread< CharSocket >
virtual void run ()
 Run the I/O Service loop within this network thread. More...
 
virtual void on_socket_removed (std::shared_ptr< CharSocket > sock)=0
 
virtual void on_socket_added (std::shared_ptr< CharSocket > 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

std::atomic< bool > _is_initialized {false}
 
std::atomic< bool > _is_finalized {false}
 
ResourceManager _resource_manager
 
- Protected Attributes inherited from Horizon::Networking::NetworkThread< CharSocket >
SocketContainer _active_sockets
 

Member Typedef Documentation

◆ PrimaryResource

◆ ResourceManager

Constructor & Destructor Documentation

◆ CharNetworkThread()

Horizon::Char::CharNetworkThread::CharNetworkThread ( )
inline
67 _resource_manager(PrimaryResource(RESOURCE_PRIORITY_PRIMARY, std::make_shared<s_segment_storage<uint64_t, std::shared_ptr<CharSocket>>>()))
68 {
69 }
#define sChar
Definition: Char.hpp:143
@ RESOURCE_PRIORITY_PRIMARY
Definition: Server.hpp:79
ResourceManager _resource_manager
Definition: ClientSocketMgr.hpp:128
SharedPriorityResourceMedium< s_segment_storage< uint64_t, std::shared_ptr< CharSocket > > > PrimaryResource
Definition: ClientSocketMgr.hpp:126
KernelComponent(Kernel *kernel, Horizon::System::runtime_module_type module_type)
Definition: Server.hpp:194
@ RUNTIME_NETWORKING
Definition: System.hpp:84
Definition: Server.hpp:93

Member Function Documentation

◆ finalize()

virtual void Horizon::Char::CharNetworkThread::finalize ( )
inlineoverridevirtual

Reimplemented from KernelComponent.

114 {
116 _is_finalized.exchange(true);
117 }
std::atomic< bool > _is_finalized
Definition: ClientSocketMgr.hpp:123
virtual void finalize()
Halts the IO Service and marks the network thread as stopped.
Definition: NetworkThread.hpp:76

References _is_finalized, and Horizon::Networking::NetworkThread< SocketType >::finalize().

+ Here is the call graph for this function:

◆ get_resource_manager()

ResourceManager & Horizon::Char::CharNetworkThread::get_resource_manager ( )
inline
130{ return _resource_manager; }

References _resource_manager.

Referenced by on_socket_added(), and on_socket_removed().

+ Here is the caller graph for this function:

◆ initialize()

virtual void Horizon::Char::CharNetworkThread::initialize ( int  segment_number = 1)
inlineoverridevirtual

Reimplemented from KernelComponent.

108 {
109 _is_initialized.exchange(true);
110 set_segment_number(segment_number);
111 }
std::atomic< bool > _is_initialized
Definition: ClientSocketMgr.hpp:122
void set_segment_number(int64_t segment_number)
Definition: Server.hpp:206

References _is_initialized, and KernelComponent::set_segment_number().

Referenced by start().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_finalized()

virtual bool Horizon::Char::CharNetworkThread::is_finalized ( )
inlineoverridevirtual

Reimplemented from KernelComponent.

120{ return _is_finalized.load(); }

References _is_finalized.

◆ is_initialized()

virtual bool Horizon::Char::CharNetworkThread::is_initialized ( )
inlineoverridevirtual

Reimplemented from KernelComponent.

119{ return _is_initialized.load(); }

References _is_initialized.

◆ on_socket_added()

void Horizon::Char::CharNetworkThread::on_socket_added ( std::shared_ptr< CharSocket socket)
inlineoverrideprotected
61 {
62 get_resource_manager().add<RESOURCE_PRIORITY_PRIMARY>(socket->get_socket_id(), socket);
63 }
ResourceManager & get_resource_manager()
Definition: ClientSocketMgr.hpp:130
void add(Key key, Value value)
Definition: Server.hpp:157

References SharedPriorityResourceManager< SharedPriorityResourceMediums >::add(), get_resource_manager(), and RESOURCE_PRIORITY_PRIMARY.

+ Here is the call graph for this function:

◆ on_socket_removed()

void Horizon::Char::CharNetworkThread::on_socket_removed ( std::shared_ptr< CharSocket socket)
inlineoverrideprotected
56 {
57 get_resource_manager().remove<RESOURCE_PRIORITY_PRIMARY>(socket->get_socket_id());
58 }
void remove(Key key)
Definition: Server.hpp:163

References get_resource_manager(), SharedPriorityResourceManager< SharedPriorityResourceMediums >::remove(), and RESOURCE_PRIORITY_PRIMARY.

+ Here is the call graph for this function:

◆ run()

void Horizon::Char::CharNetworkThread::run ( )
inlineoverridevirtual

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

See also
update()

Reimplemented from Horizon::Networking::NetworkThread< CharSocket >.

81 {
83 }
virtual void run()
Run the I/O Service loop within this network thread.
Definition: NetworkThread.hpp:143

References Horizon::Networking::NetworkThread< SocketType >::run().

+ Here is the call graph for this function:

◆ start()

bool Horizon::Char::CharNetworkThread::start ( int  segment_number = 1)
inlinevirtual

Initializes the network thread and runs.

Returns
true on success, false if thread is a nullptr.

Reimplemented from Horizon::Networking::NetworkThread< CharSocket >.

72 {
74 return false;
75
76 initialize(segment_number);
77 return true;
78 }
virtual void initialize(int segment_number=1) override
Definition: ClientSocketMgr.hpp:107
virtual bool start(int segment_number=1)
Initializes the network thread and runs.
Definition: NetworkThread.hpp:94

References initialize().

Referenced by update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update()

void Horizon::Char::CharNetworkThread::update ( )
inlineoverridevirtual

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.

See also
Socket<SocketType>::update()

Reimplemented from Horizon::Networking::NetworkThread< CharSocket >.

86 {
87 std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now();
89
91#if WIN32
92 DWORD cpu = GetCurrentProcessorNumber();
93 if (get_thread_cpu_id() != (int) cpu)
95#elif __linux__
96 int cpu = sched_getcpu();
97 if (get_thread_cpu_id() != cpu)
99#endif
100
102 std::chrono::high_resolution_clock::time_point end = std::chrono::high_resolution_clock::now();
103 std::chrono::nanoseconds time_span = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start);
104 set_total_execution_time(time_span.count());
105 }
bool start(int segment_number=1)
Initializes the network thread and runs.
Definition: ClientSocketMgr.hpp:71
virtual void update()
Updates the network thread and schedules a recursive call to itself.
Definition: NetworkThread.hpp:163
void process_queue()
Definition: System.hpp:676
void set_thread_cpu_id(int cpu_id)
Definition: Server.hpp:239
Horizon::System::SystemRoutineManager & get_system_routine_manager()
Definition: Server.hpp:235
void set_total_execution_time(int time)
Definition: Server.hpp:245
void calculate_and_set_cpu_load()
Definition: Server.hpp:257
int get_thread_cpu_id()
Definition: Server.hpp:240

References KernelComponent::calculate_and_set_cpu_load(), KernelComponent::get_system_routine_manager(), KernelComponent::get_thread_cpu_id(), Horizon::System::SystemRoutineManager::process_queue(), KernelComponent::set_thread_cpu_id(), KernelComponent::set_total_execution_time(), start(), and Horizon::Networking::NetworkThread< SocketType >::update().

+ Here is the call graph for this function:

Member Data Documentation

◆ _is_finalized

std::atomic<bool> Horizon::Char::CharNetworkThread::_is_finalized {false}
protected

Referenced by finalize(), and is_finalized().

◆ _is_initialized

std::atomic<bool> Horizon::Char::CharNetworkThread::_is_initialized {false}
protected

Referenced by initialize(), and is_initialized().

◆ _resource_manager

ResourceManager Horizon::Char::CharNetworkThread::_resource_manager
protected

Referenced by get_resource_manager().


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