@@ -91,6 +91,17 @@ s_string_compare (void *item1, void *item2)
9191 return strcmp (str1 , str2 );
9292}
9393
94+ static int64_t
95+ s_reap_interval (zyre_node_t * self )
96+ {
97+ uint64_t interval = self -> evasive_timeout ;
98+ if (self -> expired_timeout < interval )
99+ interval = self -> expired_timeout ;
100+ if (interval > REAP_INTERVAL )
101+ interval = REAP_INTERVAL ;
102+ return interval ;
103+ }
104+
94105// --------------------------------------------------------------------------
95106// Constructor
96107
@@ -1547,15 +1558,15 @@ zyre_node_ping_peer (const char *key, void *item, void *argument)
15471558 zstr_sendm (self -> outbox , "EVASIVE" );
15481559 zstr_sendm (self -> outbox , zyre_peer_identity (peer ));
15491560 zstr_send (self -> outbox , zyre_peer_name (peer ));
1550- if (zclock_mono () >= zyre_peer_evasive_at (peer ) + REAP_INTERVAL ) {
1561+ if (zclock_mono () >= zyre_peer_evasive_at (peer ) + s_reap_interval ( self ) ) {
15511562 // Inform the calling application this peer is being silent
15521563 // despite having tried to ping it. Something is wrong with
15531564 // the connection to this peer (or with the network).
15541565 // NB: this is an improvement of the EVASIVE event which triggers
15551566 // before getting ping result and thus has poor meaning.
15561567 if (self -> verbose )
15571568 zsys_info ("(%s) peer '%s' has not answered ping after %d milliseconds (silent)" ,
1558- self -> name , zyre_peer_name (peer ), REAP_INTERVAL );
1569+ self -> name , zyre_peer_name (peer ), s_reap_interval ( self ) );
15591570 zstr_sendm (self -> outbox , "SILENT" );
15601571 zstr_sendm (self -> outbox , zyre_peer_identity (peer ));
15611572 zstr_send (self -> outbox , zyre_peer_name (peer ));
@@ -1581,7 +1592,7 @@ zyre_node_actor (zsock_t *pipe, void *args)
15811592 zsock_signal (self -> pipe , 0 );
15821593
15831594 // Loop until the agent is terminated one way or another
1584- int64_t reap_at = zclock_mono () + REAP_INTERVAL ;
1595+ int64_t last_reaped_at = zclock_mono ();
15851596 while (!self -> terminated ) {
15861597
15871598 // Start beacon as soon as we can
@@ -1635,10 +1646,8 @@ zyre_node_actor (zsock_t *pipe, void *args)
16351646 zstr_free (& hostname );
16361647 }
16371648
1638- int timeout = (int ) (reap_at - zclock_mono ());
1639- if (timeout > REAP_INTERVAL )
1640- timeout = REAP_INTERVAL ;
1641- else
1649+ // If nothing else happens, wait until the next reap
1650+ int timeout = (int ) ((last_reaped_at + s_reap_interval (self )) - zclock_mono ());
16421651 if (timeout < 0 )
16431652 timeout = 0 ;
16441653
@@ -1661,9 +1670,9 @@ zyre_node_actor (zsock_t *pipe, void *args)
16611670 break ; // Interrupted, check before expired
16621671 else
16631672 if (zpoller_expired (self -> poller )) {
1664- if (zclock_mono () >= reap_at ) {
1673+ if (zclock_mono () >= ( last_reaped_at + s_reap_interval ( self )) ) {
16651674 void * item ;
1666- reap_at = zclock_mono () + REAP_INTERVAL ;
1675+ last_reaped_at = zclock_mono ();
16671676 // Ping all peers and reap any expired ones
16681677 for (item = zhash_first (self -> peers ); item != NULL ;
16691678 item = zhash_next (self -> peers ))
0 commit comments