Extract resource management in TimedStack

This makes TimedStack extendable for use by multiple connections.  For
multiple connections the resource managed is the number of file
descriptors used instead of the number of connections to a particular
service.

A subclass can use thread local variables to pass extra arguments down
without altering the calls which, while clumsy, is functional.