Horizon Official Technical Documentation
|
|
Socket Manager for Accepted Sockets. More...
#include <AcceptSocketMgr.hpp>
Public Member Functions | |
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< SocketType > sock) |
Sets a socket for removal on the next session update call. More... | |
void | set_socket_for_management (std::shared_ptr< SocketType > sock) |
void | manage_sockets (uint32_t time) |
Updates every session in the socket map and removes ones in the removal queue. More... | |
SocketMap & | get_sockets () |
![]() | |
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< SocketType > | 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_map & | get_thread_map () |
Private Types | |
typedef std::map< uint32_t, std::shared_ptr< SocketType > > | SocketMap |
typedef SocketMgr< SocketType, NetworkThreadType > | BaseSocketMgr |
Private Attributes | |
std::unique_ptr< AsyncAcceptor > | _acceptor |
unique pointer to an AsyncAcceptor object. More... | |
SocketMap | _socket_map |
std::map of all connected and handled sockets. More... | |
ThreadSafeQueue< std::pair< bool, std::shared_ptr< SocketType > > > | _socket_management_queue |
std::atomic< bool > | _is_initialized |
Socket Manager for Accepted Sockets.
Deals with client sockets that were accepted by the server.
|
private |
|
private |
|
inline |
References Horizon::Networking::AcceptSocketMgr< SocketType, NetworkThreadType >::_socket_map.
|
inline |
Updates every session in the socket map and removes ones in the removal queue.
[in] | diff |
References Horizon::Networking::AcceptSocketMgr< SocketType, NetworkThreadType >::_socket_management_queue, Horizon::Networking::AcceptSocketMgr< SocketType, NetworkThreadType >::_socket_map, and ThreadSafeQueue< T >::try_pop().
|
inline |
On Socket Open / Start Event.
Called as a callback from an Acceptor on successful socket acceptance. Moves the socket ownership from the caller to a network thread.
[in] | socket | shared pointer. |
[in] | thread_index | index of the thread that the socket is being moved from. |
References Horizon::Networking::SocketMgr< SocketType, NetworkThreadType >::on_socket_open(), and Horizon::Networking::AcceptSocketMgr< SocketType, NetworkThreadType >::set_socket_for_management().
|
inline |
References Horizon::Networking::AcceptSocketMgr< SocketType, NetworkThreadType >::_socket_management_queue, and ThreadSafeQueue< T >::push().
Referenced by Horizon::Networking::AcceptSocketMgr< SocketType, NetworkThreadType >::on_socket_open().
|
inline |
Sets a socket for removal on the next session update call.
[in] | sock | socket to be removed. |
References Horizon::Networking::AcceptSocketMgr< SocketType, NetworkThreadType >::_socket_management_queue, and ThreadSafeQueue< T >::push().
|
inlinevirtual |
Initialize and start accepting connections asynchronously.
This method also starts the networking threads for accepted sockets.
[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] | port | port number for the acceptor to bind on. |
[in] | threads | number of network acceptor threads to start and run. |
Reimplemented in Horizon::Zone::ClientSocketMgr, Horizon::Auth::ClientSocketMgr, and Horizon::Char::ClientSocketMgr.
References Horizon::Networking::AcceptSocketMgr< SocketType, NetworkThreadType >::_acceptor, Horizon::Networking::SocketMgr< SocketType, NetworkThreadType >::get_new_socket(), HLog, and Horizon::Networking::SocketMgr< SocketType, NetworkThreadType >::StartNetworkThreads().
|
inlineoverridevirtual |
Stop the Acceptor network and clear the client socket map.
Reimplemented from Horizon::Networking::SocketMgr< SocketType, NetworkThreadType >.
References Horizon::Networking::AcceptSocketMgr< SocketType, NetworkThreadType >::_acceptor, and Horizon::Networking::SocketMgr< SocketType, NetworkThreadType >::stop_network().
|
private |
unique pointer to an AsyncAcceptor object.
Referenced by Horizon::Networking::AcceptSocketMgr< SocketType, NetworkThreadType >::start(), and Horizon::Networking::AcceptSocketMgr< SocketType, NetworkThreadType >::stop_network().
|
private |
|
private |
Referenced by Horizon::Networking::AcceptSocketMgr< SocketType, NetworkThreadType >::manage_sockets(), Horizon::Networking::AcceptSocketMgr< SocketType, NetworkThreadType >::set_socket_for_management(), and Horizon::Networking::AcceptSocketMgr< SocketType, NetworkThreadType >::set_socket_for_removal().
|
private |
std::map of all connected and handled sockets.
Referenced by Horizon::Networking::AcceptSocketMgr< SocketType, NetworkThreadType >::get_sockets(), and Horizon::Networking::AcceptSocketMgr< SocketType, NetworkThreadType >::manage_sockets().