33// commands such as IPP and Bonjour conformance tests. This tool is
44// inspired by the UNIX "find" command, thus its name.
55//
6- // Copyright © 2021-2023 by OpenPrinting.
6+ // Copyright © 2021-2025 by OpenPrinting.
77// Copyright © 2020 by the IEEE-ISTO Printer Working Group
88// Copyright © 2008-2018 by Apple Inc.
99//
@@ -118,6 +118,7 @@ static int address_family = AF_UNSPEC;
118118static bool bonjour_error = false; // Error browsing/resolving?
119119static double bonjour_timeout = 1.0 ; // Timeout in seconds
120120static int ipp_version = 20 ; // IPP version for LIST
121+ static double last_update = 0.0 ; // Last update time
121122
122123
123124//
@@ -129,7 +130,6 @@ static int compare_services(ippfind_srv_t *a, ippfind_srv_t *b);
129130static int eval_expr (ippfind_srv_t * service , ippfind_expr_t * expressions );
130131static int exec_program (ippfind_srv_t * service , size_t num_args , char * * args );
131132static ippfind_srv_t * get_service (ippfind_srvs_t * services , const char * serviceName , const char * regtype , const char * replyDomain ) _CUPS_NONNULL (1 ,2 ,3 ,4 );
132- static double get_time (void );
133133static int list_service (ippfind_srv_t * service );
134134static ippfind_expr_t * new_expr (ippfind_op_t op , bool invert , const char * value , const char * regex , char * * args );
135135static void resolve_callback (cups_dnssd_resolve_t * resolve , void * context , cups_dnssd_flags_t flags , uint32_t if_index , const char * fullName , const char * hostTarget , uint16_t port , size_t num_txt , cups_option_t * txt );
@@ -962,11 +962,11 @@ main(int argc, // I - Number of command-line args
962962
963963 // Process browse/resolve requests...
964964 if (bonjour_timeout > 1.0 )
965- endtime = get_time () + bonjour_timeout ;
965+ endtime = cupsGetClock () + bonjour_timeout ;
966966 else
967- endtime = get_time () + 300.0 ;
967+ endtime = cupsGetClock () + 300.0 ;
968968
969- while (get_time () < endtime )
969+ while (cupsGetClock () < endtime )
970970 {
971971 // Process any services that we have found...
972972 size_t j , // Looping var
@@ -1022,7 +1022,7 @@ main(int argc, // I - Number of command-line args
10221022 if (getenv ("IPPFIND_DEBUG" ))
10231023 fprintf (stderr , "STATUS processed=%u, resolved=%u, count=%u\n" , (unsigned )processed , (unsigned )resolved , (unsigned )count );
10241024
1025- if (processed > 0 && processed == cupsArrayGetCount (services .services ) && bonjour_timeout <= 1.0 )
1025+ if (processed > 0 && ( processed == cupsArrayGetCount (services .services ) || ( cupsGetClock () - last_update ) >= 2.5 ) && bonjour_timeout <= 1.0 )
10261026 break ;
10271027
10281028 // Give the browsers/resolvers some time...
@@ -1053,6 +1053,8 @@ browse_callback(
10531053 ippfind_srv_t * service ; // Service
10541054
10551055
1056+ last_update = cupsGetClock ();
1057+
10561058 if (getenv ("IPPFIND_DEBUG" ))
10571059 fprintf (stderr , "B flags=0x%04X, if_index=%u, serviceName=\"%s\", regtype=\"%s\", replyDomain=\"%s\"\n" , flags , if_index , serviceName , regtype , replyDomain );
10581060
@@ -1505,31 +1507,6 @@ get_service(ippfind_srvs_t *services, // I - Service array
15051507}
15061508
15071509
1508- //
1509- // 'get_time()' - Get the current time-of-day in seconds.
1510- //
1511-
1512- static double
1513- get_time (void )
1514- {
1515- #ifdef _WIN32
1516- struct _timeb curtime ; // Current Windows time
1517-
1518- _ftime (& curtime );
1519-
1520- return (curtime .time + 0.001 * curtime .millitm );
1521-
1522- #else
1523- struct timeval curtime ; // Current UNIX time
1524-
1525- if (gettimeofday (& curtime , NULL ))
1526- return (0.0 );
1527- else
1528- return (curtime .tv_sec + 0.000001 * curtime .tv_usec );
1529- #endif // _WIN32
1530- }
1531-
1532-
15331510//
15341511// 'list_service()' - List the contents of a service.
15351512//
@@ -1809,6 +1786,8 @@ resolve_callback(
18091786 char * value ; // Pointer into value
18101787
18111788
1789+ last_update = cupsGetClock ();
1790+
18121791 if (getenv ("IPPFIND_DEBUG" ))
18131792 fprintf (stderr , "R flags=0x%04X, if_index=%u, fullName=\"%s\", hostTarget=\"%s\", port=%u, num_txt=%u, txt=%p\n" , flags , if_index , fullName , hostTarget , port , (unsigned )num_txt , txt );
18141793
0 commit comments