This will make it easier to enable gevent support.
This is inspired by the version from macdiesel and tomstrummer, but their version was heavily linked with XEP-0096 and focused solely on file transfer. This version is a more generic implementation.