libsdl-org / SDL_net

A simple, cross-platform wrapper over TCP/IP sockets.
zlib License
202 stars 49 forks source link

SDLNet_WaitUntilResolved is broken when using timeouts #96

Closed JoelLinn closed 2 weeks ago

JoelLinn commented 5 months ago

SDL_net 78dc78694f17317b08ec788d4812e74850b4acff SDL d95f5bad2459608816cbf24f14dcab618a4a9ab7 prerelease-3.1.2

Hi,

when setting a timeout, SDLNet_WaitUntilResolved has broken behaviour. This can be reproduced using one of the examples:

diff --git a/examples/resolve-hostnames.c b/examples/resolve-hostnames.c
index ac28e7b..0efae0d 100644
--- a/examples/resolve-hostnames.c
+++ b/examples/resolve-hostnames.c
@@ -25,7 +25,7 @@ int main(int argc, char **argv)
     }

     for (int i = 1; i < argc; i++) {
-        SDLNet_WaitUntilResolved(addrs[i], -1);
+        SDLNet_WaitUntilResolved(addrs[i], 1000);

         if (SDLNet_GetAddressStatus(addrs[i]) == -1) {
             SDL_Log("%s: [FAILED TO RESOLVE: %s]", argv[i], SDL_GetError());
> ./resolve-hostnames 8.8.8.8

Issues:

TheGauntt commented 2 weeks ago

Happening for me as well - happy to add more info if that helps. Works with workarounds listed above

icculus commented 2 weeks ago

Okay, the hang is fixed.

Note that examples/resolve-hostnames.c's logic for checking the address status is incorrect without an infinite timeout, which is why it reported NULL address strings before this bug was fixed with the above patch; it shouldn't get a status of zero with an infinite wait.

TheGauntt commented 2 weeks ago

Thanks for fixing! Also, much appreciation for the level of documentation throughout the project