From 99aba5667d0d7ba6657f9c175a9342126bc4b0f2 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Sat, 22 Feb 2014 21:42:24 +0100 Subject: Connection to servers does not block the process anymore --- src/network/socket_handler.hpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/network/socket_handler.hpp') diff --git a/src/network/socket_handler.hpp b/src/network/socket_handler.hpp index c27d44c..cb09e4e 100644 --- a/src/network/socket_handler.hpp +++ b/src/network/socket_handler.hpp @@ -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 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; -- cgit v1.2.3