Bidirectional close propagation

Added a unit test for bidirectional close propagation.
This requires some ugly hacks to allow sockets to close.