High-level implementation of session with events.

Fixed several problems with potential segfaults in resolver code.
Fixed more problems with uv_resolver.