In my opinion you shouldn't try any tricks to determine whether you have an internet connection: if you're not testing the exact thing you need, there will be situations in which your test provides the wrong result. Also you'd be making your code and its behavior more complex.
That's in fact okay, if I encapsulate it well.
I think there are two components to a proper solution:
- OpenDingux should fail fast if there is no chance at all of a successful DNS lookup
- Hase should deal with DNS lookups that don't fail fast
About point 1: When I try command line stuff (nslookup, ssh) when the Zero is networked via USB, name resolution fails immediately. So I cannot reproduce the problem you're describing. Could you make a minimal test case that demonstrates the problem? What kind of networking is active on the Zero? Is there anything in "/etc/resolv.conf"?
I have no idea. What I do is:
Getting the IP via DNS lookup via SDL_net.
If this IP is invalid, I know, the connection is missing. On the Pandora this is quite fast. Also on the PC. But somebody mentioned, that this may take a while on the GCW. This problem also exists for me C4A implementation afaik. I could make a simple shell program, which tries to lookup a DNS with the same method and return whether this connection is availbale or not. Does this help?
About point 2: If you know you have a responsive server, you can reduce the timeout. Also you can contact the server asynchronously such that the user interface doesn't block while Hase is waiting for the server's reply.
Yes I could make a thread for this. I will think about this sollution as it seems to be the best. However it is harder so synchronize and more special cases pop up like creating a game if an update is running right now. Do I wait for the update state? Do I use the old state? Do I assume being offline as long as the check runs?
Furthermore using a timeout means killing the SDL_Net function for DNS lookup. I don't know, whether this is a good idea...