|
virtual std::shared_ptr< Connector > | start (std::string const &connection_name, Server *server, std::string const &connect_ip, uint16_t port, uint32_t connections=1, bool minimal=false) |
| Initialize and start connecting synchronously. More...
|
|
virtual bool | stop_network () override |
| Stop the Connector network and clear the connection pool. More...
|
|
void | on_socket_open (std::string const &conn_name, std::shared_ptr< tcp::socket > const &tcp_socket, uint32_t thread_index) |
| On Server Type Socket Open / Start Routine. More...
|
|
void | add_socket_to_connections (std::string const &conn_name, std::shared_ptr< SocketType > sock) |
|
std::shared_ptr< SocketType > | get_socket_from_connections (std::string const &conn_name) |
|
void | remove_socket_from_connections (std::string const &conn_name) |
|
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 () |
|
template<class SocketType, class NetworkThreadType>
class Horizon::Networking::ConnectSocketMgr< SocketType, NetworkThreadType >
Socket manager that handles sockets that were created by the connector.
template<class SocketType , class NetworkThreadType >
virtual std::shared_ptr< Connector > Horizon::Networking::ConnectSocketMgr< SocketType, NetworkThreadType >::start |
( |
std::string const & |
connection_name, |
|
|
Server * |
server, |
|
|
std::string const & |
connect_ip, |
|
|
uint16_t |
port, |
|
|
uint32_t |
connections = 1 , |
|
|
bool |
minimal = false |
|
) |
| |
|
inlinevirtual |
Initialize and start connecting synchronously.
This method also starts the networking threads for connected sockets.
- Parameters
-
| [in|out] | connection_name const reference to the connection name string. |
| [in|out] | server pointer to the server instance that issued the connection. |
| [in|out] | connect_ip const reference to the ip_address string for the connection endpoint. |
[in] | port | port number for the connection endpoint. |
[in] | connections | number of connections to create and handle. |
- Returns
- true on success, false on failure.
60 {
61 std::shared_ptr<Connector> connector;
62
63 if (!(connector = std::make_shared<Horizon::Networking::Connector>(connection_name, server, connect_ip, port))) {
64 HLog(error) <<
"ConnectSocketMgr::Start: " << connection_name <<
" failed to connect to tcp::" << connect_ip <<
"@" << port;
65 return nullptr;
66 }
67
69 HLog(error) <<
"ConnectSocketMgr::Start failed to start network threads.";
70 return nullptr;
71 }
72
73
75
76 if (minimal == false)
77 connector->connect_with_callback(
79 this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), connections);
80
81 return connector;
82 }
#define HLog(type)
Definition: Logger.hpp:122
void on_socket_open(std::string const &conn_name, std::shared_ptr< tcp::socket > const &tcp_socket, uint32_t thread_index)
On Server Type Socket Open / Start Routine.
Definition: ConnectSocketMgr.hpp:102
virtual bool StartNetworkThreads(uint32_t threads=1)
Main function that deals with network thread initiation.
Definition: SocketMgr.hpp:64
std::pair< std::shared_ptr< tcp::socket >, uint32_t > get_new_socket()
Get a socket from the thread for new server connection.
Definition: SocketMgr.hpp:149
References Horizon::Networking::SocketMgr< SocketType, NetworkThreadType >::get_new_socket(), HLog, and Horizon::Networking::SocketMgr< SocketType, NetworkThreadType >::StartNetworkThreads().