Connection to servers does not block the process anymore

This commit is contained in:
Florent Le Coz
2014-02-22 21:42:24 +01:00
parent 61ca40fa0e
commit 99aba5667d
10 changed files with 111 additions and 32 deletions
+22 -1
View File
@@ -19,10 +19,15 @@ class SocketHandler
public:
explicit SocketHandler();
virtual ~SocketHandler() {}
/**
* (re-)Initialize the socket
*/
void init_socket();
/**
* Connect to the remote server, and call on_connected() if this succeeds
*/
std::pair<bool, std::string> connect(const std::string& address, const std::string& port);
void connect(const std::string& address, const std::string& port);
void connect();
/**
* Set the pointer to the given Poller, to communicate with it.
*/
@@ -53,6 +58,11 @@ public:
* Called when the connection is successful.
*/
virtual void on_connected() = 0;
/**
* Called when the connection fails. Not when it is closed later, just at
* the connect() call.
*/
virtual void on_connection_failed(const std::string& reason) = 0;
/**
* Called when we detect a disconnection from the remote host.
*/
@@ -63,6 +73,7 @@ public:
*/
virtual void parse_in_buffer() = 0;
bool is_connected() const;
bool is_connecting() const;
protected:
socket_t socket;
@@ -86,7 +97,17 @@ protected:
* (actually it is sharing our ownership with a Bridge).
*/
Poller* poller;
/**
* Hostname we are connected/connecting to
*/
std::string address;
/**
* Port we are connected/connecting to
*/
std::string port;
bool connected;
bool connecting;
private:
SocketHandler(const SocketHandler&) = delete;