Graceful shutdown support

Interval cleanup after socket close.
Merge pull request #6 from avesus/patch-1

Graceful shutdown support