The nasty code with static variable in retry_send() which avoids looping forever needs to be called on success of the syscall, to reset the static variable.