Set cancellation points in keepalive_thread() and client_thread() and