Make the socket error rescueing more cross platform