fix read timeout and handle EINTR for select()