From what I can tell, I'm not sure even using
select will help you in all cases. For starters, the
connect() call is not asynchronous. Additionally, the call to
gethostbyname() can block, and this is probably what is happening when your VPN goes down.
One possibility is to use a local proxy - then your process should never hang while establishing the HTTP connection.