@@ -116,9 +116,10 @@ typedef struct ippfind_srv_s // Service information
116116static cups_dnssd_t * dnssd ; // DNS-SD context
117117static int address_family = AF_UNSPEC ;
118118 // Address family for LIST
119- static int bonjour_error = 0 ; // Error browsing/resolving?
119+ static bool bonjour_error = false ; // Error browsing/resolving?
120120static double bonjour_timeout = 1.0 ; // Timeout in seconds
121121static int ipp_version = 20 ; // IPP version for LIST
122+ static double last_update = 0.0 ; // Last update time
122123
123124
124125//
@@ -130,7 +131,6 @@ static int compare_services(ippfind_srv_t *a, ippfind_srv_t *b, void *data);
130131static int eval_expr (ippfind_srv_t * service , ippfind_expr_t * expressions );
131132static int exec_program (ippfind_srv_t * service , int num_args , char * * args );
132133static ippfind_srv_t * get_service (ippfind_srvs_t * services , const char * serviceName , const char * regtype , const char * replyDomain ) _CUPS_NONNULL (1 ,2 ,3 ,4 );
133- static double get_time (void );
134134static int list_service (ippfind_srv_t * service );
135135static ippfind_expr_t * new_expr (ippfind_op_t op , bool invert , const char * value , const char * regex , char * * args );
136136static 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 , int num_txt , cups_option_t * txt );
@@ -1064,11 +1064,11 @@ main(int argc, // I - Number of command-line args
10641064
10651065 // Process browse/resolve requests...
10661066 if (bonjour_timeout > 1.0 )
1067- endtime = get_time () + bonjour_timeout ;
1067+ endtime = cupsGetClock () + bonjour_timeout ;
10681068 else
1069- endtime = get_time () + 300.0 ;
1069+ endtime = cupsGetClock () + 300.0 ;
10701070
1071- while (get_time () < endtime )
1071+ while (cupsGetClock () < endtime )
10721072 {
10731073 // Process any services that we have found...
10741074 int j , // Looping var
@@ -1122,7 +1122,7 @@ main(int argc, // I - Number of command-line args
11221122 if (getenv ("IPPFIND_DEBUG" ))
11231123 fprintf (stderr , "STATUS processed=%u, resolved=%u, count=%u\n" , (unsigned )processed , (unsigned )resolved , (unsigned )count );
11241124
1125- if (processed > 0 && processed == cupsArrayGetCount (services .services ) && bonjour_timeout <= 1.0 )
1125+ if (processed > 0 && ( processed == cupsArrayGetCount (services .services ) || ( cupsGetClock () - last_update ) >= 2.5 ) && bonjour_timeout <= 1.0 )
11261126 break ;
11271127
11281128 // Give the browsers/resolvers some time...
@@ -1152,6 +1152,9 @@ browse_callback(
11521152{
11531153 ippfind_srv_t * service ; // Service
11541154
1155+
1156+ last_update = cupsGetClock ();
1157+
11551158 if (getenv ("IPPFIND_DEBUG" ))
11561159 fprintf (stderr , "B flags=0x%04X, if_index=%u, serviceName=\"%s\", regtype=\"%s\", replyDomain=\"%s\"\n" , flags , if_index , serviceName , regtype , replyDomain );
11571160
@@ -1592,31 +1595,6 @@ get_service(ippfind_srvs_t *services, // I - Service array
15921595}
15931596
15941597
1595- //
1596- // 'get_time()' - Get the current time-of-day in seconds.
1597- //
1598-
1599- static double
1600- get_time (void )
1601- {
1602- #ifdef _WIN32
1603- struct _timeb curtime ; // Current Windows time
1604-
1605- _ftime (& curtime );
1606-
1607- return (curtime .time + 0.001 * curtime .millitm );
1608-
1609- #else
1610- struct timeval curtime ; // Current UNIX time
1611-
1612- if (gettimeofday (& curtime , NULL ))
1613- return (0.0 );
1614- else
1615- return (curtime .tv_sec + 0.000001 * curtime .tv_usec );
1616- #endif // _WIN32
1617- }
1618-
1619-
16201598//
16211599// 'list_service()' - List the contents of a service.
16221600//
@@ -1897,6 +1875,8 @@ resolve_callback(
18971875 char * value ; // Pointer into value
18981876
18991877
1878+ last_update = cupsGetClock ();
1879+
19001880 if (getenv ("IPPFIND_DEBUG" ))
19011881 fprintf (stderr , "R flags=0x%04X, if_index=%u, fullName=\"%s\", hostTarget=\"%s\", port=%u, num_txt=%d, txt=%p\n" , flags , if_index , fullName , hostTarget , port , num_txt , (void * )txt );
19021882
@@ -1907,7 +1887,7 @@ resolve_callback(
19071887 // Only process "add" data...
19081888 if (flags & CUPS_DNSSD_FLAGS_ERROR )
19091889 {
1910- bonjour_error = 1 ;
1890+ bonjour_error = true ;
19111891 return ;
19121892 }
19131893
0 commit comments