Add signal handling

Close connection on termination and report statistics on HUP.