From: Alexander Pevzner Date: Sat, 5 Apr 2025 13:08:35 +0000 (+0300) Subject: Changed the end-of-search criteria for ippfind -T 0 X-Git-Tag: v2.4.12~2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1214%2Fhead;p=thirdparty%2Fcups.git Changed the end-of-search criteria for ippfind -T 0 Previously, with the -T 0 option ("search quickly with automatic timeout"), ippfind used the following criteria to determine when the search was complete: 1. At least one service was discovered, and 2. Either all discovered services were resolved or 2.5 seconds had passed since the last update. However, this algorithm caused unreliable behavior when a mix of devices was present—some that could be discovered quickly (such as cached or locally published devices via ipp-usb) and others that required more time (such as network devices). As a result, ippfind often terminated prematurely, missing network devices in its output. The updated end-of-search criteria are as follows: 1. All discovered services must be either resolved or have at least 1.0 second since their last update, and 2. The total discovery time of at least 2.5 seconds has passed. This updated algorithm significantly improves discovery reliability. --- diff --git a/tools/ippfind.c b/tools/ippfind.c index 8963557182..8cdc9deaae 100644 --- a/tools/ippfind.c +++ b/tools/ippfind.c @@ -1295,12 +1295,15 @@ main(int argc, /* I - Number of command-line args */ /* * Process browse/resolve requests... + * + * Note, _cupsGetClock() is 0-based, so there is no need to snapshot the start + * time here. */ if (bonjour_timeout > 1.0) - endtime = _cupsGetClock() + bonjour_timeout; + endtime = bonjour_timeout; else - endtime = _cupsGetClock() + 300.0; + endtime = 300.0; while (_cupsGetClock() < endtime) { @@ -1423,10 +1426,14 @@ main(int argc, /* I - Number of command-line args */ } /* - * If we have processed all services we have discovered, then we are done. + * If we are running with the minimal timeout (-T 0) and have processed all + * services we have discovered, then we are done. + * + * The minimal discovery time is enforced to be at least 2.5 seconds. Otherwise, + * with the cold Avahi cache discovery of the network devices is not stable. */ - if (processed > 0 && (processed == cupsArrayCount(services) || (_cupsGetClock() - last_update) >= 2.5) && bonjour_timeout <= 1.0) + if (bonjour_timeout <= 1.0 && _cupsGetClock() >= 2.5 && (processed == cupsArrayCount(services) || (_cupsGetClock() - last_update) >= 1.0)) break; }