Asynchronous address resolution

* Use getaddrinfo_a to asynchronously resolve hostnames.
* Add a timeout when connecting to a server.
* Unify global variables in the event context.