30#ifndef HORIZON_NETWORKING_CONNECTOR_HPP
31#define HORIZON_NETWORKING_CONNECTOR_HPP
36#include <boost/asio.hpp>
37#include <boost/bind/bind.hpp>
41using namespace boost::asio::ip;
55 typedef std::function<void(std::string &, std::shared_ptr<tcp::socket>, uint32_t)>
ConnectorCallback;
88 for (
int i = 0; i < connections; i++) {
89 std::shared_ptr<tcp::socket> socket;
90 uint32_t network_thread_idx;
91 boost::system::error_code error;
102 if (error.value() != 0) {
104 std::this_thread::sleep_for(std::chrono::seconds(10));
111 }
while (!socket->is_open());
#define HLog(type)
Definition: Logger.hpp:122
Connector object that allows connecting to remote endpoints.
Definition: Connector.hpp:53
Server * server
Definition: Connector.hpp:123
std::function< void(std::string &, std::shared_ptr< tcp::socket >, uint32_t)> ConnectorCallback
Definition: Connector.hpp:55
std::pair< std::shared_ptr< tcp::socket >, uint32_t > default_socket_factory()
Definition: Connector.hpp:121
void set_socket_factory(std::function< std::pair< std::shared_ptr< tcp::socket >, uint32_t >()> &&func)
Sets a socket factory method that provides a socket for new connections.
Definition: Connector.hpp:118
Connector(std::string const &connection_name, Server *server, std::string const &connect_ip, uint16_t port)
Connector contructor.
Definition: Connector.hpp:64
std::function< std::pair< std::shared_ptr< tcp::socket >, uint32_t >()> _socket_factory
Definition: Connector.hpp:126
Connector()
Destructor of the object that handles joining of all socket polling threads.
Definition: Connector.hpp:73
tcp::endpoint _endpoint
Definition: Connector.hpp:125
std::string _connection_name
Definition: Connector.hpp:124
void connect_with_callback(ConnectorCallback callback, int connections=1)
Attempts connections to the remote endpoint that the object was initiated with.
Definition: Connector.hpp:86
Definition: Server.hpp:554
Definition: Element.hpp:7