Prevent DNS hanging on startup
somethingwhatever created issue #1966 on 2014-05-12T08:14:46Z:
Written in follow up to the issue raised here: http://forums.xonotic.org/showthread.php?tid=4818
The main problem is that getaddrinfo() does not support any way to set a timeout, and there are few portable async DNS solutions.
This patch introduces a function LHNET_CheckNetwork(). In POSIX, use pthreads to create a separate thread in which getaddrinfo runs (and tries to resolve google.com). If this operation fails after a (short) timeout (3 seconds, adjustable in struct timespec timeout), the thread is terminated and it’s safe to assume the network is down. In Windows, this uses InternetGetConnectedState, which will tell you if Windows thinks there is a working network connection.
In both cases it sets static flags so that we’re not repeating these operations for every DNS lookup that we do; just the first ones that the engine happens to run.
Right now I tested this in Linux and it seems to work without breaking anything. I don’t have a Windows or OS X build environment to test on those platforms.