diff --git a/src/SFML/Network/SocketTCP.cpp b/src/SFML/Network/SocketTCP.cpp index 03d96d3b..6de4b081 100644 --- a/src/SFML/Network/SocketTCP.cpp +++ b/src/SFML/Network/SocketTCP.cpp @@ -131,11 +131,22 @@ Socket::Status SocketTCP::Connect(unsigned short Port, const IPAddress& HostAddr Time.tv_sec = static_cast(Timeout); Time.tv_usec = (static_cast(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(mySocket + 1), NULL, &Selector, NULL, &Time) > 0) - { - // Connection succeeded - Status = Socket::Done; + { + // 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), &Size) != -1) + { + // Connection accepted + Status = Socket::Done; + } + else + { + // Connection failed + Status = SocketHelper::GetErrorStatus(); + } } else {