From cefc5884b8706fcb49dfeed5329ed6e89e36036b Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Mon, 8 May 2000 12:00:06 +0000 Subject: Implement exponential backoff for finding servers. --- zhm/zhm.h | 1 - zhm/zhm_server.c | 17 ++++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'zhm') diff --git a/zhm/zhm.h b/zhm/zhm.h index 733d9cc..3d6f153 100644 --- a/zhm/zhm.h +++ b/zhm/zhm.h @@ -44,7 +44,6 @@ #define ever (;;) -#define SERV_TIMEOUT 5 #define BOOTING 1 #define NOTICES 2 diff --git a/zhm/zhm_server.c b/zhm/zhm_server.c index 4630955..50fa04f 100644 --- a/zhm/zhm_server.c +++ b/zhm/zhm_server.c @@ -19,8 +19,11 @@ static char rcsid_hm_server_c[] = "$Id$"; #endif /* lint */ static void boot_timeout __P((void *)); +static int get_serv_timeout __P((void)); static Timer *boot_timer = NULL; +static int serv_rexmit_times[] = { 5, 10, 20, 40 }; +static int serv_timeouts = 0; int serv_loop = 0; extern u_short cli_port; @@ -64,7 +67,7 @@ char *op; Zperr(ret); com_err("hm", ret, "sending startup notice"); } - boot_timer = timer_set_rel(SERV_TIMEOUT, boot_timeout, NULL); + boot_timer = timer_set_rel(get_serv_timeout(), boot_timeout, NULL); } /* Argument is whether we are detaching or really going down */ @@ -182,6 +185,7 @@ ZNotice_t *notice; } else { /* This is our server, handle the notice */ booting = 0; + serv_timeouts = 0; if (boot_timer) { timer_reset(boot_timer); boot_timer = NULL; @@ -305,6 +309,17 @@ char *sugg_serv; static void boot_timeout(arg) void *arg; { + serv_timeouts++; new_server(NULL); } +static int get_serv_timeout(void) +{ + int ind, ntimeouts; + + ind = (numserv == 0) ? serv_timeouts : serv_timeouts / numserv; + ntimeouts = sizeof(serv_rexmit_times) / sizeof(*serv_rexmit_times); + if (ind >= ntimeouts) + ind = ntimeouts - 1; + return serv_rexmit_times[ind]; +} -- cgit v1.2.3