source/Sources/AirPlayReceiverServer.c
static void	_UpdateBonjour( AirPlayReceiverServerRef inServer )
{
	OSStatus				err, firstErr = kNoErr;
	dispatch_source_t		timer;
	Boolean					activated = true;
	uint64_t				ms;
	
	if( !inServer->serversStarted || !activated )
	{
		_StopBonjour( inServer, "disable" );
		return;
	}
	if( inServer->bonjourStartTicks == 0 ) inServer->bonjourStartTicks = UpTicks();
	
	err = _UpdateBonjourAirPlay( inServer, NULL );
	if( !firstErr ) firstErr = err;
	
	if( !firstErr )
	{
		dispatch_source_forget( &inServer->bonjourRetryTimer );
	}
	else if( !inServer->bonjourRetryTimer )
	{
		ms = UpTicksToMilliseconds( UpTicks() - inServer->bonjourStartTicks );
		ms = ( ms < 11113 ) ? ( 11113 - ms ) : 1; // Use 11113 to avoid being syntonic with 10 second re-launching.
		aprs_ulog( kLogLevelNotice, "### Bonjour failed, retrying in %llu ms: %#m\n", ms, firstErr );
		
		inServer->bonjourRetryTimer = timer = dispatch_source_create( DISPATCH_SOURCE_TYPE_TIMER, 0, 0, inServer->queue );
		check( timer );
		if( timer )
		{
			dispatch_set_context( timer, inServer );
			dispatch_source_set_event_handler_f( timer, _RetryBonjour );
			dispatch_source_set_timer( timer, dispatch_time_milliseconds( ms ), INT64_MAX, kNanosecondsPerSecond );
			dispatch_resume( timer );
		}
	}
}
//===========================================================================================================================
//	_UpdateBonjour
//
//	Update all Bonjour services.
//===========================================================================================================================
_UpdateBonjour
Update all Bonjour services.
_UpdateBonjour Update all Bonjour services .
static void	_UpdateBonjour( AirPlayReceiverServerRef inServer )
{
	OSStatus				err, firstErr = kNoErr;
	dispatch_source_t		timer;
	Boolean					activated = true;
	uint64_t				ms;
	if( !inServer->serversStarted || !activated )
	{
		_StopBonjour( inServer, "disable" );
		return;
	}
	if( inServer->bonjourStartTicks == 0 ) inServer->bonjourStartTicks = UpTicks();
	err = _UpdateBonjourAirPlay( inServer, NULL );
	if( !firstErr ) firstErr = err;
	if( !firstErr )
	{
		dispatch_source_forget( &inServer->bonjourRetryTimer );
	}
	else if( !inServer->bonjourRetryTimer )
	{
		ms = UpTicksToMilliseconds( UpTicks() - inServer->bonjourStartTicks );
		ms = ( ms < 11113 ) ? ( 11113 - ms ) : 1; 
		aprs_ulog( kLogLevelNotice, "### Bonjour failed, retrying in %llu ms: %#m\n", ms, firstErr );
		inServer->bonjourRetryTimer = timer = dispatch_source_create( DISPATCH_SOURCE_TYPE_TIMER, 0, 0, inServer->queue );
		check( timer );
		if( timer )
		{
			dispatch_set_context( timer, inServer );
			dispatch_source_set_event_handler_f( timer, _RetryBonjour );
			dispatch_source_set_timer( timer, dispatch_time_milliseconds( ms ), INT64_MAX, kNanosecondsPerSecond );
			dispatch_resume( timer );
		}
	}
}
static void _UpdateBonjour ( AirPlayReceiverServerRef inServer ) { OSStatus err , firstErr = kNoErr ; dispatch_source_t timer ; Boolean activated = true ; uint64_t ms ; if ( ! inServer -> serversStarted || ! activated ) { _StopBonjour ( inServer , " " ) ; return ; } if ( inServer -> bonjourStartTicks == 0 ) inServer -> bonjourStartTicks = UpTicks ( ) ; err = _UpdateBonjourAirPlay ( inServer , NULL ) ; if ( ! firstErr ) firstErr = err ; if ( ! firstErr ) { dispatch_source_forget ( & inServer -> bonjourRetryTimer ) ; } else if ( ! inServer -> bonjourRetryTimer ) { ms = UpTicksToMilliseconds ( UpTicks ( ) - inServer -> bonjourStartTicks ) ; ms = ( ms < 11113 ) ? ( 11113 - ms ) : 1 ; aprs_ulog ( kLogLevelNotice , " \n " , ms , firstErr ) ; inServer -> bonjourRetryTimer = timer = dispatch_source_create ( DISPATCH_SOURCE_TYPE_TIMER , 0 , 0 , inServer -> queue ) ; check ( timer ) ; if ( timer ) { dispatch_set_context ( timer , inServer ) ; dispatch_source_set_event_handler_f ( timer , _RetryBonjour ) ; dispatch_source_set_timer ( timer , dispatch_time_milliseconds ( ms ) , INT64_MAX , kNanosecondsPerSecond ) ; dispatch_resume ( timer ) ; } } }
_UpdateBonjour
Update all Bonjour services.
_UpdateBonjour Update all Bonjour services .
// Use 11113 to avoid being syntonic with 10 second re-launching.