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");
}
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)
+1 -1
View File
@@ -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.
*/