Fully implement the close method.

Add in another structure to handle keeping tract of the
which resources need to be released when a blocking close
is called.