M src/network/socket_handler.cpp => src/network/socket_handler.cpp +3 -2
@@ 20,7 20,7 @@ SocketHandler::SocketHandler():
throw std::runtime_error("Could not create socket");
}
-void SocketHandler::connect(const std::string& address, const std::string& port)
+bool SocketHandler::connect(const std::string& address, const std::string& port)
{
log_info("Trying to connect to " << address << ":" << port);
struct addrinfo hints;
@@ 47,13 47,14 @@ void SocketHandler::connect(const std::string& address, const std::string& port)
{
log_info("Connection success.");
this->on_connected();
- return ;
+ return true;
}
log_info("Connection failed:");
perror("connect");
}
log_error("All connection attempts failed.");
this->close();
+ return false;
}
void SocketHandler::set_poller(Poller* poller)
M src/network/socket_handler.hpp => src/network/socket_handler.hpp +1 -1
@@ 21,7 21,7 @@ public:
/**
* Connect to the remote server, and call on_connected() if this succeeds
*/
- void connect(const std::string& address, const std::string& port);
+ bool connect(const std::string& address, const std::string& port);
/**
* Set the pointer to the given Poller, to communicate with it.
*/
M src/xmpp/xmpp_component.cpp => src/xmpp/xmpp_component.cpp +2 -2
@@ 46,9 46,9 @@ XmppComponent::~XmppComponent()
{
}
-void XmppComponent::start()
+bool XmppComponent::start()
{
- this->connect("127.0.0.1", "5347");
+ return this->connect("127.0.0.1", "5347");
}
void XmppComponent::send_stanza(const Stanza& stanza)
M src/xmpp/xmpp_component.hpp => src/xmpp/xmpp_component.hpp +3 -2
@@ 25,9 25,10 @@ public:
void parse_in_buffer() override final;
/**
- * Connect to the XMPP server
+ * Connect to the XMPP server.
+ * Returns false if we failed to connect
*/
- void start();
+ bool start();
/**
* Serialize the stanza and add it to the out_buf to be sent to the
* server.