summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/irc/irc-protocol.c12
-rw-r--r--src/plugins/irc/irc-server.c38
-rw-r--r--src/plugins/irc/irc-server.h1
3 files changed, 43 insertions, 8 deletions
diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c
index 55a3b35a5..67b0109cd 100644
--- a/src/plugins/irc/irc-protocol.c
+++ b/src/plugins/irc/irc-protocol.c
@@ -1838,17 +1838,19 @@ IRC_PROTOCOL_CALLBACK(pong)
gettimeofday (&tv, NULL);
server->lag = (int)(weechat_util_timeval_diff (&(server->lag_check_time),
&tv) / 1000);
- if (server->lag != server->lag_displayed)
- {
- server->lag_displayed = server->lag;
- weechat_bar_item_update ("lag");
- }
/* schedule next lag check */
server->lag_check_time.tv_sec = 0;
server->lag_check_time.tv_usec = 0;
server->lag_next_check = time (NULL) +
weechat_config_integer (irc_config_network_lag_check);
+
+ /* refresh lag bar item if needed */
+ if (server->lag != server->lag_displayed)
+ {
+ server->lag_displayed = server->lag;
+ irc_server_set_lag (server);
+ }
}
else
{
diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c
index 2645c6c52..2d6f7eaaf 100644
--- a/src/plugins/irc/irc-server.c
+++ b/src/plugins/irc/irc-server.c
@@ -786,6 +786,34 @@ irc_server_set_prefix_modes_chars (struct t_irc_server *server,
}
/*
+ * Sets lag in server buffer (local variable), update bar item "lag"
+ * and send signal "irc_server_lag_changed" for the server.
+ */
+
+void
+irc_server_set_lag (struct t_irc_server *server)
+{
+ char str_lag[32];
+
+ if (server->lag >= weechat_config_integer (irc_config_network_lag_min_show))
+ {
+ snprintf (str_lag, sizeof (str_lag),
+ ((server->lag_check_time.tv_sec == 0) || (server->lag < 1000)) ?
+ "%.3f" : "%.0f",
+ ((float)(server->lag)) / 1000);
+ weechat_buffer_set (server->buffer, "localvar_set_lag", str_lag);
+ }
+ else
+ {
+ weechat_buffer_set (server->buffer, "localvar_del_lag", "");
+ }
+ weechat_hook_signal_send ("irc_server_lag_changed",
+ WEECHAT_HOOK_SIGNAL_STRING,
+ server->name);
+ weechat_bar_item_update ("lag");
+}
+
+/*
* Gets prefix_modes for server (for example: "ohv").
*
* Returns default modes if prefix_modes is not set in server.
@@ -3105,7 +3133,7 @@ irc_server_timer_cb (const void *pointer, void *data, int remaining_calls)
struct t_irc_redirect *ptr_redirect, *ptr_next_redirect;
time_t current_time;
static struct timeval tv;
- int away_check;
+ int away_check, refresh_lag;
/* make C compiler happy */
(void) pointer;
@@ -3179,6 +3207,7 @@ irc_server_timer_cb (const void *pointer, void *data, int remaining_calls)
/* compute lag */
if (ptr_server->lag_check_time.tv_sec != 0)
{
+ refresh_lag = 0;
gettimeofday (&tv, NULL);
ptr_server->lag = (int)(weechat_util_timeval_diff (&(ptr_server->lag_check_time),
&tv) / 1000);
@@ -3191,7 +3220,7 @@ irc_server_timer_cb (const void *pointer, void *data, int remaining_calls)
if (ptr_server->lag != ptr_server->lag_displayed)
{
ptr_server->lag_displayed = ptr_server->lag;
- weechat_bar_item_update ("lag");
+ refresh_lag = 1;
}
}
/* lag timeout? => disconnect */
@@ -3219,7 +3248,7 @@ irc_server_timer_cb (const void *pointer, void *data, int remaining_calls)
if (ptr_server->lag != ptr_server->lag_displayed)
{
ptr_server->lag_displayed = ptr_server->lag;
- weechat_bar_item_update ("lag");
+ refresh_lag = 1;
}
/* schedule next lag check in 5 seconds */
@@ -3229,6 +3258,8 @@ irc_server_timer_cb (const void *pointer, void *data, int remaining_calls)
weechat_config_integer (irc_config_network_lag_check);
}
}
+ if (refresh_lag)
+ irc_server_set_lag (ptr_server);
}
/* remove redirects if timeout occurs */
@@ -4831,6 +4862,7 @@ irc_server_disconnect (struct t_irc_server *server, int switch_address,
server->lag_next_check = time (NULL) +
weechat_config_integer (irc_config_network_lag_check);
server->lag_last_refresh = 0;
+ irc_server_set_lag (server);
server->monitor = 0;
server->monitor_time = 0;
diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h
index 359c32356..fc7d63e95 100644
--- a/src/plugins/irc/irc-server.h
+++ b/src/plugins/irc/irc-server.h
@@ -289,6 +289,7 @@ extern const char *irc_server_get_isupport_value (struct t_irc_server *server,
const char *feature);
extern void irc_server_set_prefix_modes_chars (struct t_irc_server *server,
const char *prefix);
+extern void irc_server_set_lag (struct t_irc_server *server);
extern const char *irc_server_get_prefix_modes (struct t_irc_server *server);
extern const char *irc_server_get_prefix_chars (struct t_irc_server *server);
extern int irc_server_get_prefix_mode_index (struct t_irc_server *server,