connect() returns a boolean

This commit is contained in:
Florent Le Coz
2013-12-24 14:03:40 +01:00
parent 2ecb637f0c
commit 983477084c
4 changed files with 9 additions and 7 deletions
+3 -2
View File
@@ -20,7 +20,7 @@ SocketHandler::SocketHandler():
throw std::runtime_error("Could not create socket"); 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); log_info("Trying to connect to " << address << ":" << port);
struct addrinfo hints; struct addrinfo hints;
@@ -47,13 +47,14 @@ void SocketHandler::connect(const std::string& address, const std::string& port)
{ {
log_info("Connection success."); log_info("Connection success.");
this->on_connected(); this->on_connected();
return ; return true;
} }
log_info("Connection failed:"); log_info("Connection failed:");
perror("connect"); perror("connect");
} }
log_error("All connection attempts failed."); log_error("All connection attempts failed.");
this->close(); this->close();
return false;
} }
void SocketHandler::set_poller(Poller* poller) void SocketHandler::set_poller(Poller* poller)
+1 -1
View File
@@ -21,7 +21,7 @@ public:
/** /**
* Connect to the remote server, and call on_connected() if this succeeds * 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. * Set the pointer to the given Poller, to communicate with it.
*/ */
+2 -2
View File
@@ -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) void XmppComponent::send_stanza(const Stanza& stanza)
+3 -2
View File
@@ -25,9 +25,10 @@ public:
void parse_in_buffer() override final; 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 * Serialize the stanza and add it to the out_buf to be sent to the
* server. * server.