Network/TcpClient: WaitForConnected now returns new socket state

This commit is contained in:
Lynix 2018-10-01 22:38:20 +02:00
parent 13a515c1b5
commit dad2dbae1c
3 changed files with 16 additions and 16 deletions

View File

@ -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. - 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). - ⚠️ 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 closes the socket on failure.
- ⚠️ TcpClient::WaitForconnected now returns the new socket state.
Nazara Development Kit: Nazara Development Kit:
- Added ImageWidget (#139) - Added ImageWidget (#139)

View File

@ -54,7 +54,7 @@ namespace Nz
bool SetCursorPos(UInt64 offset) override; bool SetCursorPos(UInt64 offset) override;
bool WaitForConnected(UInt64 msTimeout = 3000); SocketState WaitForConnected(UInt64 msTimeout = 3000);
inline TcpClient& operator=(TcpClient&& tcpClient) = default; inline TcpClient& operator=(TcpClient&& tcpClient) = default;

View File

@ -432,24 +432,18 @@ namespace Nz
/*! /*!
* \brief Waits for being connected before time out * \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.
*/ */
SocketState TcpClient::WaitForConnected(UInt64 msTimeout)
bool TcpClient::WaitForConnected(UInt64 msTimeout)
{ {
switch (m_state) switch (m_state)
{ {
case SocketState_Bound:
case SocketState_Resolving:
break;
case SocketState_Connected:
return true;
case SocketState_Connecting: case SocketState_Connecting:
{ {
NazaraAssert(m_handle != SocketImpl::InvalidHandle, "Invalid handle"); NazaraAssert(m_handle != SocketImpl::InvalidHandle, "Invalid handle");
@ -472,15 +466,20 @@ namespace Nz
Close(); Close();
UpdateState(newState); UpdateState(newState);
return newState == SocketState_Connected; return newState;
} }
case SocketState_Connected:
case SocketState_NotConnected: 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) + ')'); NazaraInternalError("Unhandled socket state (0x" + String::Number(m_state, 16) + ')');
return false; return m_state;
} }
/*! /*!