Network/TcpClient: Fix QueryState() when connection failed
Former-commit-id: 15824535922186c0601ade8bfbbe76866b7cd5ff
This commit is contained in:
parent
5325513bd8
commit
a324f44901
|
|
@ -94,50 +94,56 @@ namespace Nz
|
|||
|
||||
SocketState TcpClient::QueryState()
|
||||
{
|
||||
// Check our state depending on our last state
|
||||
switch (m_state)
|
||||
// Only check state if we have a valid handle, else we're not connected.
|
||||
if (m_handle != SocketImpl::InvalidHandle)
|
||||
{
|
||||
case SocketState_Connecting:
|
||||
// Check our state depending on our last state
|
||||
switch (m_state)
|
||||
{
|
||||
// If we were connecting, check how it's going
|
||||
SocketError getError;
|
||||
SocketError error = SocketImpl::GetLastError(m_handle, &getError);
|
||||
|
||||
if (getError != SocketError_NoError)
|
||||
break; //< Do not update state if we cannot get socket state
|
||||
|
||||
if (error == SocketError_NoError)
|
||||
case SocketState_Connecting:
|
||||
{
|
||||
// No error yet, we're still connecting or connected, check that by calling Connect again
|
||||
return Connect(m_peerAddress);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Our connection attempt failed
|
||||
m_lastError = error;
|
||||
UpdateState(SocketState_NotConnected);
|
||||
}
|
||||
// If we were connecting, check how it's going
|
||||
SocketError getError;
|
||||
SocketError error = SocketImpl::GetLastError(m_handle, &getError);
|
||||
|
||||
break;
|
||||
}
|
||||
if (getError != SocketError_NoError)
|
||||
break; //< Do not update state if we cannot get socket state
|
||||
|
||||
default:
|
||||
{
|
||||
// Check our peer address, if it works we're connected
|
||||
SocketError error;
|
||||
m_peerAddress = SocketImpl::QueryPeerAddress(m_handle, &error);
|
||||
if (m_peerAddress == IpAddress::Invalid)
|
||||
{
|
||||
// Other errors mean a problem while getting the peer address
|
||||
if (error == SocketError_ConnectionClosed)
|
||||
if (error == SocketError_NoError)
|
||||
{
|
||||
// No error yet, we're still connecting or connected, check that by calling Connect again
|
||||
return Connect(m_peerAddress);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Our connection attempt failed
|
||||
m_lastError = error;
|
||||
UpdateState(SocketState_NotConnected);
|
||||
}
|
||||
else
|
||||
UpdateState(SocketState_Connected); // If we are not connecting and have a peer address, we are connected
|
||||
}
|
||||
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
// Check our peer address, if it works we're connected
|
||||
SocketError error;
|
||||
m_peerAddress = SocketImpl::QueryPeerAddress(m_handle, &error);
|
||||
if (m_peerAddress == IpAddress::Invalid)
|
||||
{
|
||||
// Other errors mean a problem while getting the peer address
|
||||
if (error == SocketError_ConnectionClosed)
|
||||
UpdateState(SocketState_NotConnected);
|
||||
}
|
||||
else
|
||||
UpdateState(SocketState_Connected); // If we are not connecting and have a peer address, we are connected
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
UpdateState(SocketState_NotConnected);
|
||||
|
||||
return m_state;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue