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

Manager of client sockets. More...

#include <ClientSocketMgr.hpp>

+ Inheritance diagram for Horizon::Zone::ClientSocketMgr:
+ Collaboration diagram for Horizon::Zone::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)
 Initialize and start accepting connections asynchronously. More...
 
bool stop ()
 
void update_sessions (uint64_t time)
 
- Public Member Functions inherited from Horizon::Networking::AcceptSocketMgr< ZoneSocket, ZoneNetworkThread >
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< ZoneSocket > sock)
 Sets a socket for removal on the next session update call. More...
 
void set_socket_for_management (std::shared_ptr< ZoneSocket > 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< ZoneSocket, ZoneNetworkThread >
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< ZoneSocket > 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 ()
 

Private Types

typedef Horizon::Networking::AcceptSocketMgr< ZoneSocket, ZoneNetworkThreadBaseSocketMgr
 

Detailed Description

Manager of client sockets.

Member Typedef Documentation

◆ BaseSocketMgr

Member Function Documentation

◆ start()

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

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< ZoneSocket, ZoneNetworkThread >.

11{
12 if (!BaseSocketMgr::start(io_context, listen_ip, port, threads, minimal))
13 return false;
14
15 for (auto i : get_thread_map()) {
16 sZone->register_component(Horizon::System::RUNTIME_NETWORKING, (std::dynamic_pointer_cast<ZoneNetworkThread>(i.second)));
17 }
18
19 return true;
20}
#define sZone
Definition: Zone.hpp:247
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::System::RUNTIME_NETWORKING, and sZone.

◆ stop()

bool Horizon::Zone::ClientSocketMgr::stop ( )
23{
24 get_sockets().clear();
25
26 for (auto i = get_thread_map().begin(); i != get_thread_map().end(); i++)
27 sZone->deregister_component(Horizon::System::RUNTIME_NETWORKING, (std::static_pointer_cast<ZoneNetworkThread>(i->second))->get_segment_number());
28
30 return false;
31
32 return true;
33}
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::System::RUNTIME_NETWORKING, and sZone.

Referenced by Horizon::Zone::ZoneServer::update().

+ Here is the caller graph for this function:

◆ update_sessions()

void Horizon::Zone::ClientSocketMgr::update_sessions ( uint64_t  time)
inline
142 {
143 auto socket_map = get_sockets();
144
145 for (auto s : socket_map) {
146 if (s.second->get_session() != nullptr)
147 s.second->get_session()->update(time);
148 }
149 }

References Horizon::Networking::AcceptSocketMgr< ZoneSocket, ZoneNetworkThread >::get_sockets().

+ Here is the call graph for this function:

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