diff --git a/async-sockets/include/basesocket.hpp b/async-sockets/include/basesocket.hpp index 144dcbf..6f3df85 100644 --- a/async-sockets/include/basesocket.hpp +++ b/async-sockets/include/basesocket.hpp @@ -29,6 +29,7 @@ class BaseSocket const uint16_t BUFFER_SIZE = 0xFFFF; sockaddr_in address; bool isClosed = false; + bool isConnecting = false; protected: int sock = 0; diff --git a/async-sockets/include/tcpsocket.hpp b/async-sockets/include/tcpsocket.hpp index 586fc00..cecc9ef 100644 --- a/async-sockets/include/tcpsocket.hpp +++ b/async-sockets/include/tcpsocket.hpp @@ -62,6 +62,7 @@ class TCPSocket : public BaseSocket this->address.sin_family = AF_INET; this->address.sin_port = htons(port); this->address.sin_addr.s_addr = ipv4; + this->isConnecting = true; this->setTimeout(5); @@ -69,6 +70,8 @@ class TCPSocket : public BaseSocket if (connect(this->sock, (const sockaddr *)&this->address, sizeof(sockaddr_in)) < 0) { onError(errno, "Connection failed to the host."); + this->isConnecting = false; + this->isClosed = true; this->setTimeout(0); return; } @@ -80,6 +83,8 @@ class TCPSocket : public BaseSocket // Start listening from server: this->Listen(); + this->isConnecting = false; + this->isClosed = false; } void Listen()