Add support for connection pooling

This pull requests adds support for connection pooling.
Code is thread safe and should work also on Linux.