]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Changed the end-of-search criteria for ippfind -T 0 1214/head
authorAlexander Pevzner <pzz@apevzner.com>
Sat, 5 Apr 2025 13:08:35 +0000 (16:08 +0300)
committerAlexander Pevzner <pzz@apevzner.com>
Mon, 7 Apr 2025 14:59:50 +0000 (17:59 +0300)
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.

tools/ippfind.c

index 8963557182b06945e1a8dd3776f57b373c4b1fac..8cdc9deaae2d13cb551ef704f1cd8e358ed345b7 100644 (file)
@@ -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;
   }