irctk

libircclient binding for scripts
git clone https://a3nm.net/git/irctk/
Log | Files | Refs | README

commit 2f941d3658d6afb14c5a0c77f867a8f53db1639d
parent 02a02ebca3b3dcf83d379816eca54003873dc2d3
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Sat, 16 Jun 2012 17:04:53 +0200

retry_after, retry_factor

Diffstat:
irctk.c | 28+++++++++++++++++++++-------
1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/irctk.c b/irctk.c @@ -24,10 +24,6 @@ #define thread_id_t pthread_t #define _GNU_SOURCE -// TODO cli options for that -#define INITIAL_RETRY 5 -#define FACTOR_RETRY 2 - #define E_SESSION 1 #define E_CONNECT 2 #define E_THREAD 3 @@ -79,6 +75,12 @@ static struct argp_option options[] = { MISC}, /*{"no-auto-join", 0, 0, 0, "Refuse to send any message to channels not specified on the command line (default is to join as needed)", MISC }, // TODO*/ + {"retry-after", 'y', "secs", 0, + "Wait delay before trying to reconnect (default: 5)", + MISC}, + {"retry-factor", 'Y', "secs", 0, + "Retry delay multiplication factor after each failed attempt (default: 2)", + MISC}, /*{"synchronous", 's', 0, 0, "Will wait for a multiline, blankline-terminated answer on stdin to all lines passed on stdout, and will bufferize activity before that", COM_MODE }, // TODO*/ @@ -164,6 +166,8 @@ struct arguments int verbosity; int interval; + int retry_after; + int retry_factor; enum default_destinations default_destination; int show_inferred; @@ -209,6 +213,8 @@ void initialize_args() args.verbosity = 0; args.interval = isatty(fileno(stdin))?0:1000000; + args.retry_after = 5; + args.retry_factor = 2; args.default_destination = DEFAULT_LAST_IN; args.show_inferred = 0; @@ -272,6 +278,12 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) case 'i': arguments->interval = (int) (atof(arg) * 1000000.); break; + case 'y': + arguments->retry_after = (int) (atof(arg)); + break; + case 'Y': + arguments->retry_factor = (int) (atof(arg)); + break; case 'U': arguments->username_set = 1; arguments->username = arg; @@ -1020,11 +1032,13 @@ int start (int max_wait) } if (!args.ready) { debug("nick is %s\n", args.nick); - info("Connection timed out after %d seconds, retrying...", max_wait); + int new_max_wait = max_wait * args.retry_factor; + info("Connection timed out after %d seconds, retrying for %d seconds...", + max_wait, new_max_wait); irc_disconnect(s); args.ready = 0; sleep(1); - return start(max_wait * FACTOR_RETRY); + return start(new_max_wait); } } @@ -1101,7 +1115,7 @@ int main (int argc, char **argv) //debug_args(); - return start(INITIAL_RETRY); + return start(args.retry_after); }