Gracefully close socket.