Fixed TCP connect with timeout returning success when the connection failed
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1173 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
5972c22d89
commit
ed0cf87e28
@ -131,13 +131,24 @@ Socket::Status SocketTCP::Connect(unsigned short Port, const IPAddress& HostAddr
|
|||||||
Time.tv_sec = static_cast<long>(Timeout);
|
Time.tv_sec = static_cast<long>(Timeout);
|
||||||
Time.tv_usec = (static_cast<long>(Timeout * 1000) % 1000) * 1000;
|
Time.tv_usec = (static_cast<long>(Timeout * 1000) % 1000) * 1000;
|
||||||
|
|
||||||
// Wait for something to write on our socket (would mean the connection has been accepted)
|
// Wait for something to write on our socket (which means that the connection request has returned)
|
||||||
if (select(static_cast<int>(mySocket + 1), NULL, &Selector, NULL, &Time) > 0)
|
if (select(static_cast<int>(mySocket + 1), NULL, &Selector, NULL, &Time) > 0)
|
||||||
{
|
{
|
||||||
// Connection succeeded
|
// At this point the connection may have been either accepted or refused.
|
||||||
|
// To know whether it's a success or a failure, we try to retrieve the name of the connected peer
|
||||||
|
SocketHelper::LengthType Size = sizeof(SockAddr);
|
||||||
|
if (getpeername(mySocket, reinterpret_cast<sockaddr*>(&SockAddr), &Size) != -1)
|
||||||
|
{
|
||||||
|
// Connection accepted
|
||||||
Status = Socket::Done;
|
Status = Socket::Done;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
// Connection failed
|
||||||
|
Status = SocketHelper::GetErrorStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
// Failed to connect before timeout is over
|
// Failed to connect before timeout is over
|
||||||
Status = SocketHelper::GetErrorStatus();
|
Status = SocketHelper::GetErrorStatus();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user