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

Manager of client sockets and initialization of the packet db *. More...

#include <ClientSocketMgr.hpp>

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

Public Member Functions

bool start (boost::asio::io_context &io_context, std::string const &listen_ip, uint16_t port, uint32_t threads=1, bool minimal=false) override
 Initialize and start accepting connections asynchronously. More...
 
bool stop ()
 
void update_sessions (uint64_t time)
 
- Public Member Functions inherited from Horizon::Networking::AcceptSocketMgr< CharSocket, CharNetworkThread >
virtual bool start (boost::asio::io_context &io_context, std::string const &listen_ip, uint16_t port, uint32_t threads=1, bool minimal=false)
 Initialize and start accepting connections asynchronously. More...
 
virtual bool stop_network () override
 Stop the Acceptor network and clear the client socket map. More...
 
void on_socket_open (std::shared_ptr< tcp::socket > const &socket, uint32_t thread_index)
 On Socket Open / Start Event. More...
 
void set_socket_for_removal (std::weak_ptr< CharSocket > sock)
 Sets a socket for removal on the next session update call. More...
 
void set_socket_for_management (std::shared_ptr< CharSocket > sock)
 
void manage_sockets (uint32_t time)
 Updates every session in the socket map and removes ones in the removal queue. More...
 
SocketMapget_sockets ()
 
- Public Member Functions inherited from Horizon::Networking::SocketMgr< CharSocket, CharNetworkThread >
virtual ~SocketMgr ()
 
virtual bool StartNetworkThreads (uint32_t threads=1)
 Main function that deals with network thread initiation. More...
 
virtual bool stop_network ()
 Stops network threads and clears the thread map. More...
 
uint32_t GetNetworkThreadCount () const
 Get the current size of the thread map. More...
 
uint32_t SelectThreadWithMinConnections () const
 Select the thread with the least number of connections, for new socket additions. More...
 
std::shared_ptr< CharSocket > on_socket_open (std::shared_ptr< tcp::socket > const &socket, uint32_t thread_index)
 On Socket Open / Start Routine. More...
 
std::pair< std::shared_ptr< tcp::socket >, uint32_t > get_new_socket ()
 Get a socket from the thread for new server connection. More...
 
network_thread_mapget_thread_map ()
 

Static Public Member Functions

static ClientSocketMgrInstance ()
 

Private Types

typedef Horizon::Networking::AcceptSocketMgr< CharSocket, CharNetworkThreadBaseSocketMgr
 

Detailed Description

Manager of client sockets and initialization of the packet db *.

Singleton class

Member Typedef Documentation

◆ BaseSocketMgr

Member Function Documentation

◆ Instance()

static ClientSocketMgr * Horizon::Char::ClientSocketMgr::Instance ( )
inlinestatic
141 {
142 static ClientSocketMgr instance;
143 return &instance;
144 }

◆ start()

bool Char::ClientSocketMgr::start ( boost::asio::io_context &  io_context,
std::string const &  listen_ip,
uint16_t  port,
uint32_t  threads = 1,
bool  minimal = false 
)
overridevirtual

Initialize and start accepting connections asynchronously.

This method also starts the networking threads for accepted sockets.

Parameters
[in|out]&io_context const reference to the io_context object.
[in|out]&listen_ip const reference to the ip_address string for the acceptor to bind on.
[in]portport number for the acceptor to bind on.
[in]threadsnumber of network acceptor threads to start and run.
Returns
true on success, false on failure.

Reimplemented from Horizon::Networking::AcceptSocketMgr< CharSocket, CharNetworkThread >.

36{
37 if (!BaseSocketMgr::start(io_context, listen_ip, port, threads, minimal))
38 return false;
39 for (auto i : get_thread_map()) {
40 sChar->register_component(Horizon::System::RUNTIME_NETWORKING, (std::dynamic_pointer_cast<CharNetworkThread>(i.second)));
41 }
42 return true;
43}
#define sChar
Definition: Char.hpp:143
virtual bool start(boost::asio::io_context &io_context, std::string const &listen_ip, uint16_t port, uint32_t threads=1, bool minimal=false)
Initialize and start accepting connections asynchronously.
Definition: AcceptSocketMgr.hpp:62
network_thread_map & get_thread_map()
Definition: SocketMgr.hpp:155
@ RUNTIME_NETWORKING
Definition: System.hpp:84

References Horizon::Networking::SocketMgr< CharSocket, CharNetworkThread >::get_thread_map(), Horizon::System::RUNTIME_NETWORKING, sChar, and Horizon::Networking::AcceptSocketMgr< CharSocket, CharNetworkThread >::start().

+ Here is the call graph for this function:

◆ stop()

bool Horizon::Char::ClientSocketMgr::stop ( )
inline
149 {
150 get_sockets().clear();
151
152 for (auto i = get_thread_map().begin(); i != get_thread_map().end(); i++)
153 sChar->deregister_component(Horizon::System::RUNTIME_NETWORKING, (std::static_pointer_cast<CharNetworkThread>(i->second))->get_segment_number());
154
156 return false;
157 return true;
158 }
SocketMap & get_sockets()
Definition: AcceptSocketMgr.hpp:155
virtual bool stop_network() override
Stop the Acceptor network and clear the client socket map.
Definition: AcceptSocketMgr.hpp:91

References Horizon::Networking::AcceptSocketMgr< CharSocket, CharNetworkThread >::get_sockets(), Horizon::Networking::SocketMgr< CharSocket, CharNetworkThread >::get_thread_map(), Horizon::System::RUNTIME_NETWORKING, sChar, and Horizon::Networking::AcceptSocketMgr< CharSocket, CharNetworkThread >::stop_network().

+ Here is the call graph for this function:

◆ update_sessions()

void Horizon::Char::ClientSocketMgr::update_sessions ( uint64_t  time)
inline
161 {
162 auto socket_map = get_sockets();
163
164 for (auto s : socket_map) {
165 if (s.second->get_session() != nullptr)
166 s.second->get_session()->update(time);
167 }
168 }

References Horizon::Networking::AcceptSocketMgr< CharSocket, CharNetworkThread >::get_sockets().

+ Here is the call graph for this function:

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