Close idle tcp drains

There are a few things I'd like to add before merging this (moving the `state` record into its own `.hrl` file and adding automated tests) but I feel like the meat of the implementation is ready for review.