Skip to content

Commit

Permalink
use adaptive reconnect_interval
Browse files Browse the repository at this point in the history
Start reconnect attempts in 10s interval and enlarge
the interval by 10s each time until it reaches 100s.

This makes reasonable retry density for both small/large reconnect timeouts.

Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
Wu, Fengguang authored and David Woodhouse committed Dec 12, 2008
1 parent 0c1364b commit 13aad61
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
19 changes: 14 additions & 5 deletions cstp.c
Expand Up @@ -324,15 +324,24 @@ int make_cstp_connection(struct openconnect_info *vpninfo)

static int cstp_reconnect(struct openconnect_info *vpninfo)
{
int retries, nr_retries, ret;
int ret;
int timeout;
int interval;

nr_retries = vpninfo->reconnect_timeout / vpninfo->reconnect_interval;
timeout = vpninfo->reconnect_timeout;
interval = vpninfo->reconnect_interval;

while ((ret = make_cstp_connection(vpninfo))) {
retries++;
if (retries >= nr_retries)
if (timeout <= 0)
return ret;
sleep(vpninfo->reconnect_interval);
vpninfo->progress(vpninfo, PRG_INFO,
"sleep %ds, remain timeout %ds\n",
interval, timeout);
sleep(interval);
timeout -= interval;
interval += vpninfo->reconnect_interval;
if (interval > RECONNECT_INTERVAL_MAX)
interval = RECONNECT_INTERVAL_MAX;
}
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion main.c
Expand Up @@ -157,7 +157,7 @@ int main(int argc, char **argv)
vpninfo->deflate = 1;
vpninfo->dtls_attempt_period = 60;
vpninfo->max_qlen = 10;
vpninfo->reconnect_interval = 20;
vpninfo->reconnect_interval = RECONNECT_INTERVAL_MIN;
vpninfo->reconnect_timeout = 300;

if (RAND_bytes(vpninfo->dtls_secret, sizeof(vpninfo->dtls_secret)) != 1) {
Expand Down
3 changes: 3 additions & 0 deletions openconnect.h
Expand Up @@ -69,6 +69,9 @@ struct split_include {
struct split_include *next;
};

#define RECONNECT_INTERVAL_MIN 10
#define RECONNECT_INTERVAL_MAX 100

struct openconnect_info {
char *redirect_url;

Expand Down

0 comments on commit 13aad61

Please sign in to comment.