diff --git a/ChangeLog.md b/ChangeLog.md index 76c4236d4..1b4bc564b 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -148,6 +148,7 @@ Nazara Engine: - Added math class Angle, capable of handling both degrees and radians angles and converting them to euler angles/quaternions to improve 2D interface. - ⚠️ AbstractSocket::OnStateChange has been replaced by OnStateChanged, which is now called after state has been changed (with oldState and newState as parameters). - ⚠️ TcpClient::WaitForconnected now closes the socket on failure. +- ⚠️ TcpClient::WaitForconnected now returns the new socket state. Nazara Development Kit: - Added ImageWidget (#139) diff --git a/include/Nazara/Network/TcpClient.hpp b/include/Nazara/Network/TcpClient.hpp index 43b299994..7c92e2ce0 100644 --- a/include/Nazara/Network/TcpClient.hpp +++ b/include/Nazara/Network/TcpClient.hpp @@ -54,7 +54,7 @@ namespace Nz bool SetCursorPos(UInt64 offset) override; - bool WaitForConnected(UInt64 msTimeout = 3000); + SocketState WaitForConnected(UInt64 msTimeout = 3000); inline TcpClient& operator=(TcpClient&& tcpClient) = default; diff --git a/src/Nazara/Network/TcpClient.cpp b/src/Nazara/Network/TcpClient.cpp index 41d06348d..441174836 100644 --- a/src/Nazara/Network/TcpClient.cpp +++ b/src/Nazara/Network/TcpClient.cpp @@ -432,24 +432,18 @@ namespace Nz /*! * \brief Waits for being connected before time out - * \return true If connection is successful + * \return The new socket state, either Connected if connection did succeed or NotConnected if an error occurred * - * \param msTimeout Time in milliseconds before time out + * This functions waits for the pending connection to either succeed or fail for a specific duration before failing. * - * \remark Produces a NazaraAssert if socket is invalid + * \param msTimeout Time in milliseconds before time out (0 for system-specific duration, like a blocking connect would) + * + * \remark This function doesn't do anything if the socket is not currently connecting. */ - - bool TcpClient::WaitForConnected(UInt64 msTimeout) + SocketState TcpClient::WaitForConnected(UInt64 msTimeout) { switch (m_state) { - case SocketState_Bound: - case SocketState_Resolving: - break; - - case SocketState_Connected: - return true; - case SocketState_Connecting: { NazaraAssert(m_handle != SocketImpl::InvalidHandle, "Invalid handle"); @@ -472,15 +466,20 @@ namespace Nz Close(); UpdateState(newState); - return newState == SocketState_Connected; + return newState; } + case SocketState_Connected: case SocketState_NotConnected: - return false; + return m_state; + + case SocketState_Bound: + case SocketState_Resolving: + break; } NazaraInternalError("Unhandled socket state (0x" + String::Number(m_state, 16) + ')'); - return false; + return m_state; } /*!