summaryrefslogtreecommitdiff
path: root/src/network/socket_handler.hpp
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2014-02-22 21:42:24 +0100
committerFlorent Le Coz <louiz@louiz.org>2014-02-22 21:42:24 +0100
commit99aba5667d0d7ba6657f9c175a9342126bc4b0f2 (patch)
tree2448f73a7e4129f1a8f9f51e230dd00111452a30 /src/network/socket_handler.hpp
parent61ca40fa0e6c819aa72f3f2364667c7b990855d4 (diff)
downloadbiboumi-99aba5667d0d7ba6657f9c175a9342126bc4b0f2.tar.gz
biboumi-99aba5667d0d7ba6657f9c175a9342126bc4b0f2.tar.bz2
biboumi-99aba5667d0d7ba6657f9c175a9342126bc4b0f2.tar.xz
biboumi-99aba5667d0d7ba6657f9c175a9342126bc4b0f2.zip
Connection to servers does not block the process anymore
Diffstat (limited to 'src/network/socket_handler.hpp')
-rw-r--r--src/network/socket_handler.hpp23
1 files changed, 22 insertions, 1 deletions
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
@@ -20,9 +20,14 @@ 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.
*/
@@ -54,6 +59,11 @@ public:
*/
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.
*/
virtual void on_connection_close() = 0;
@@ -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;