diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2010-04-21 23:24:05 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2010-04-21 23:24:05 +0200 |
commit | 87d29b19871ef7b967a1a818eae338ed29faade9 (patch) | |
tree | e09c172f2502145d787adec47451bb5b143c01ef /src/plugins/irc | |
parent | 9cbcc24d4c19c6a37b0f0c7948955ec4f0cd73be (diff) | |
download | weechat-87d29b19871ef7b967a1a818eae338ed29faade9.zip |
Add new options irc.network.autoreconnect_delay_growing and irc.network.autoreconnect_delay_max (task #10338)
Diffstat (limited to 'src/plugins/irc')
-rw-r--r-- | src/plugins/irc/irc-command.c | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-config.c | 17 | ||||
-rw-r--r-- | src/plugins/irc/irc-config.h | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-protocol.c | 1 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.c | 65 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.h | 1 | ||||
-rw-r--r-- | src/plugins/irc/irc-upgrade.c | 1 | ||||
-rw-r--r-- | src/plugins/irc/irc.c | 4 |
8 files changed, 80 insertions, 13 deletions
diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c index f384f0c15..9316029d5 100644 --- a/src/plugins/irc/irc-command.c +++ b/src/plugins/irc/irc-command.c @@ -684,6 +684,7 @@ irc_command_connect_one_server (struct t_irc_server *server, int no_join) server->disable_autojoin = no_join; if (irc_server_connect (server)) { + server->reconnect_delay = 0; server->reconnect_start = 0; server->reconnect_join = (server->channels) ? 1 : 0; } @@ -2960,6 +2961,7 @@ irc_command_reconnect_one_server (struct t_irc_server *server, int no_join) server->disable_autojoin = no_join; if (irc_server_connect (server)) { + server->reconnect_delay = 0; server->reconnect_start = 0; server->reconnect_join = (server->channels) ? 1 : 0; } diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c index b7c1d3d7d..43e6754f5 100644 --- a/src/plugins/irc/irc-config.c +++ b/src/plugins/irc/irc-config.c @@ -91,6 +91,8 @@ struct t_config_option *irc_config_color_item_buffer_name_ssl; /* IRC config, network section */ +struct t_config_option *irc_config_network_autoreconnect_delay_growing; +struct t_config_option *irc_config_network_autoreconnect_delay_max; struct t_config_option *irc_config_network_connection_timeout; struct t_config_option *irc_config_network_default_msg_part; struct t_config_option *irc_config_network_default_msg_quit; @@ -1056,7 +1058,7 @@ irc_config_server_new_option (struct t_config_file *config_file, config_file, section, option_name, "integer", N_("delay (in seconds) before trying again to reconnect to server"), - NULL, 0, 65535, + NULL, 1, 65535, default_value, value, null_value_allowed, NULL, NULL, @@ -1655,6 +1657,19 @@ irc_config_init () return 0; } + irc_config_network_autoreconnect_delay_growing = weechat_config_new_option ( + irc_config_file, ptr_section, + "autoreconnect_delay_growing", "integer", + N_("growing factor for autoreconnect delay to server (1 = always same " + "delay, 2 = delay*2 for each retry, ..)"), + NULL, 1, 100, "2", NULL, 0, NULL, NULL, + NULL, NULL, NULL, NULL); + irc_config_network_autoreconnect_delay_max = weechat_config_new_option ( + irc_config_file, ptr_section, + "autoreconnect_delay_max", "integer", + N_("maximum autoreconnect delay to server (in seconds, 0 = no maximum)"), + NULL, 0, 3600 * 24, "1800", NULL, 0, NULL, NULL, + NULL, NULL, NULL, NULL); irc_config_network_connection_timeout = weechat_config_new_option ( irc_config_file, ptr_section, "connection_timeout", "integer", diff --git a/src/plugins/irc/irc-config.h b/src/plugins/irc/irc-config.h index 02b2ed4b0..f0ef86f7e 100644 --- a/src/plugins/irc/irc-config.h +++ b/src/plugins/irc/irc-config.h @@ -107,6 +107,8 @@ extern struct t_config_option *irc_config_color_item_away; extern struct t_config_option *irc_config_color_item_channel_modes; extern struct t_config_option *irc_config_color_item_buffer_name_ssl; +extern struct t_config_option *irc_config_network_autoreconnect_delay_growing; +extern struct t_config_option *irc_config_network_autoreconnect_delay_max; extern struct t_config_option *irc_config_network_connection_timeout; extern struct t_config_option *irc_config_network_default_msg_part; extern struct t_config_option *irc_config_network_default_msg_quit; diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index d43b059e4..9de40246b 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -1784,6 +1784,7 @@ IRC_PROTOCOL_CALLBACK(001) /* connection to IRC server is ok! */ server->is_connected = 1; + server->reconnect_delay = 0; if (server->hook_timer_connection) { weechat_unhook (server->hook_timer_connection); diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index 8141f1ac1..19649fddc 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -73,7 +73,7 @@ char *irc_server_option_default[IRC_SERVER_NUM_OPTIONS] = { "", "", "off", "off", "", "2048", "on", "", "plain", "", "", "15", - "off", "on", "30", + "off", "on", "10", "", "", "", "", "", "0", "", "off", "30", }; @@ -356,6 +356,7 @@ irc_server_alloc (const char *name) new_server->nick = NULL; new_server->nick_modes = NULL; new_server->prefix = NULL; + new_server->reconnect_delay = 0; new_server->reconnect_start = 0; new_server->command_time = 0; new_server->reconnect_join = 0; @@ -1858,9 +1859,10 @@ irc_server_timer_cb (void *data, int remaining_calls) /* check if reconnection is pending */ if ((!ptr_server->is_connected) && (ptr_server->reconnect_start > 0) - && (new_time >= (ptr_server->reconnect_start + - IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_AUTORECONNECT_DELAY)))) + && (new_time >= (ptr_server->reconnect_start + ptr_server->reconnect_delay))) + { irc_server_reconnect (ptr_server); + } else { if (ptr_server->is_connected) @@ -2010,21 +2012,57 @@ irc_server_close_connection (struct t_irc_server *server) void irc_server_reconnect_schedule (struct t_irc_server *server) { - int delay; + int minutes, seconds; server->index_current_address = 0; + if (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_AUTORECONNECT)) { + /* growing reconnect delay */ + if (server->reconnect_delay == 0) + server->reconnect_delay = IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AUTORECONNECT_DELAY); + else + server->reconnect_delay = server->reconnect_delay * weechat_config_integer (irc_config_network_autoreconnect_delay_growing); + if ((weechat_config_integer (irc_config_network_autoreconnect_delay_max) > 0) + && (server->reconnect_delay > weechat_config_integer (irc_config_network_autoreconnect_delay_max))) + server->reconnect_delay = weechat_config_integer (irc_config_network_autoreconnect_delay_max); + server->reconnect_start = time (NULL); - delay = IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AUTORECONNECT_DELAY); - weechat_printf (server->buffer, - _("%s: reconnecting to server in %d %s"), - IRC_PLUGIN_NAME, - delay, - NG_("second", "seconds", delay)); + + minutes = server->reconnect_delay / 60; + seconds = server->reconnect_delay % 60; + if ((minutes > 0) && (seconds > 0)) + { + weechat_printf (server->buffer, + _("%s: reconnecting to server in %d %s, %d %s"), + IRC_PLUGIN_NAME, + minutes, + NG_("minute", "minutes", minutes), + seconds, + NG_("second", "seconds", seconds)); + } + else if (minutes > 0) + { + weechat_printf (server->buffer, + _("%s: reconnecting to server in %d %s"), + IRC_PLUGIN_NAME, + minutes, + NG_("minute", "minutes", minutes)); + } + else + { + weechat_printf (server->buffer, + _("%s: reconnecting to server in %d %s"), + IRC_PLUGIN_NAME, + seconds, + NG_("second", "seconds", seconds)); + } } else + { + server->reconnect_delay = 0; server->reconnect_start = 0; + } } /* @@ -2855,6 +2893,7 @@ irc_server_reconnect (struct t_irc_server *server) weechat_printf (server->buffer, _("%s: reconnecting to server..."), IRC_PLUGIN_NAME); + server->reconnect_start = 0; server->index_current_address = 0; @@ -2943,7 +2982,10 @@ irc_server_disconnect (struct t_irc_server *server, int reconnect) && IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_AUTORECONNECT)) irc_server_reconnect_schedule (server); else + { + server->reconnect_delay = 0; server->reconnect_start = 0; + } /* discard current nick if no reconnection asked */ if (!reconnect && server->nick) @@ -3513,6 +3555,8 @@ irc_server_add_to_infolist (struct t_infolist *infolist, return 0; if (!weechat_infolist_new_var_string (ptr_item, "prefix", server->prefix)) return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "reconnect_delay", server->reconnect_delay)) + return 0; if (!weechat_infolist_new_var_time (ptr_item, "reconnect_start", server->reconnect_start)) return 0; if (!weechat_infolist_new_var_time (ptr_item, "command_time", server->command_time)) @@ -3748,6 +3792,7 @@ irc_server_print_log () weechat_log_printf (" nick . . . . . . . . : '%s'", ptr_server->nick); weechat_log_printf (" nick_modes . . . . . : '%s'", ptr_server->nick_modes); weechat_log_printf (" prefix . . . . . . . : '%s'", ptr_server->prefix); + weechat_log_printf (" reconnect_delay. . . : %d", ptr_server->reconnect_delay); weechat_log_printf (" reconnect_start. . . : %ld", ptr_server->reconnect_start); weechat_log_printf (" command_time . . . . : %ld", ptr_server->command_time); weechat_log_printf (" reconnect_join . . . : %d", ptr_server->reconnect_join); diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h index c2c34dae1..adf3e4f2f 100644 --- a/src/plugins/irc/irc-server.h +++ b/src/plugins/irc/irc-server.h @@ -138,6 +138,7 @@ struct t_irc_server char *nick; /* current nickname */ char *nick_modes; /* nick modes */ char *prefix; /* nick prefix allowed (from msg 005) */ + int reconnect_delay; /* current reconnect delay (growing) */ time_t reconnect_start; /* this time + delay = reconnect time */ time_t command_time; /* this time + command_delay = time to */ /* autojoin channels */ diff --git a/src/plugins/irc/irc-upgrade.c b/src/plugins/irc/irc-upgrade.c index 845fa2623..e61f7e1ca 100644 --- a/src/plugins/irc/irc-upgrade.c +++ b/src/plugins/irc/irc-upgrade.c @@ -256,6 +256,7 @@ irc_upgrade_read_cb (void *data, str = weechat_infolist_string (infolist, "prefix"); if (str) irc_upgrade_current_server->prefix = strdup (str); + irc_upgrade_current_server->reconnect_delay = weechat_infolist_integer (infolist, "reconnect_delay"); irc_upgrade_current_server->reconnect_start = weechat_infolist_time (infolist, "reconnect_start"); irc_upgrade_current_server->command_time = weechat_infolist_time (infolist, "command_time"); irc_upgrade_current_server->reconnect_join = weechat_infolist_integer (infolist, "reconnect_join"); diff --git a/src/plugins/irc/irc.c b/src/plugins/irc/irc.c index f180f56ed..fb67c222c 100644 --- a/src/plugins/irc/irc.c +++ b/src/plugins/irc/irc.c @@ -125,8 +125,8 @@ irc_signal_upgrade_cb (void *data, const char *signal, const char *type_data, * after restart */ ptr_server->index_current_address = 0; - ptr_server->reconnect_start = time (NULL) - - IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_AUTORECONNECT_DELAY) - 1; + ptr_server->reconnect_delay = IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_AUTORECONNECT_DELAY); + ptr_server->reconnect_start = time (NULL) - ptr_server->reconnect_delay - 1; } } if (disconnected > 0) |