More robust socket status check