Commit 98347708 authored by louiz’'s avatar louiz’

connect() returns a boolean

parent 2ecb637f
......@@ -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)
......
......@@ -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.
*/
......
......@@ -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)
......
......@@ -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.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment