summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2005-01-23 02:14:37 +0000
committerSebastien Helleu <flashcode@flashtux.org>2005-01-23 02:14:37 +0000
commit9d0b6fad72c3381af5397ee3549f9987194892aa (patch)
treecf10b9098baff3beba4bc582944e7d8183efe42d /src
parent63d6ee1007d7038cbd4f86f41909cab67f5d0152 (diff)
downloadweechat-9d0b6fad72c3381af5397ee3549f9987194892aa.zip
Added lag indicator
Diffstat (limited to 'src')
-rw-r--r--src/common/completion.c2
-rw-r--r--src/common/weechat.c19
-rw-r--r--src/common/weechat.h2
-rw-r--r--src/common/weeconfig.c15
-rw-r--r--src/common/weeconfig.h3
-rw-r--r--src/gui/curses/gui-display.c24
-rw-r--r--src/gui/curses/gui-input.c35
-rw-r--r--src/irc/irc-commands.c2
-rw-r--r--src/irc/irc-recv.c31
-rw-r--r--src/irc/irc-server.c12
-rw-r--r--src/irc/irc.h5
11 files changed, 141 insertions, 9 deletions
diff --git a/src/common/completion.c b/src/common/completion.c
index e065b12fe..e28c4286f 100644
--- a/src/common/completion.c
+++ b/src/common/completion.c
@@ -261,8 +261,6 @@ completion_build_list (t_completion *completion, void *channel)
|| (strcasecmp (completion->base_command, "lusers") == 0)
|| (strcasecmp (completion->base_command, "motd") == 0)
|| (strcasecmp (completion->base_command, "oper") == 0)
- || (strcasecmp (completion->base_command, "ping") == 0)
- || (strcasecmp (completion->base_command, "pong") == 0)
|| (strcasecmp (completion->base_command, "rehash") == 0)
|| (strcasecmp (completion->base_command, "restart") == 0)
|| (strcasecmp (completion->base_command, "service") == 0)
diff --git a/src/common/weechat.c b/src/common/weechat.c
index 95a468bfa..b5629268a 100644
--- a/src/common/weechat.c
+++ b/src/common/weechat.c
@@ -124,6 +124,25 @@ weechat_convert_encoding (char *from_code, char *to_code, char *string)
}
/*
+ * get_timeval_diff: calculates difference between two times (return in milliseconds)
+ */
+
+long get_timeval_diff(struct timeval *tv1, struct timeval *tv2)
+{
+ long diff_sec, diff_usec;
+
+ diff_sec = tv2->tv_sec - tv1->tv_sec;
+ diff_usec = tv2->tv_usec - tv1->tv_usec;
+
+ if (diff_usec < 0)
+ {
+ diff_usec += 1000000;
+ diff_sec--;
+ }
+ return ((diff_usec / 1000) + (diff_sec * 1000));
+}
+
+/*
* wee_log_printf: displays a message in WeeChat log (~/.weechat/weechat.log)
*/
diff --git a/src/common/weechat.h b/src/common/weechat.h
index acc416ea5..95e5a1fad 100644
--- a/src/common/weechat.h
+++ b/src/common/weechat.h
@@ -26,6 +26,7 @@
#endif
#include <stdio.h>
+#include <sys/time.h>
#if defined(ENABLE_NLS) && !defined(_)
#include <locale.h>
@@ -102,6 +103,7 @@ extern char *weechat_home;
extern char *local_charset;
extern char *weechat_convert_encoding (char *, char *, char *);
+extern long get_timeval_diff (struct timeval *, struct timeval *);
extern void wee_log_printf (char *, ...);
extern void wee_shutdown ();
diff --git a/src/common/weeconfig.c b/src/common/weeconfig.c
index 6875e8df9..df1aa67e6 100644
--- a/src/common/weeconfig.c
+++ b/src/common/weeconfig.c
@@ -460,6 +460,9 @@ int cfg_irc_display_away;
char *cfg_irc_default_msg_away;
char *cfg_irc_default_msg_part;
char *cfg_irc_default_msg_quit;
+int cfg_irc_lag_check;
+int cfg_irc_lag_min_show;
+int cfg_irc_lag_disconnect;
t_config_option weechat_options_irc[] =
{ { "irc_display_away", N_("display message to all channels when away"),
@@ -478,6 +481,18 @@ t_config_option weechat_options_irc[] =
N_("default quit message ('%v' will be replaced by WeeChat version in string)"),
OPTION_TYPE_STRING, 0, 0, 0,
"WeeChat %v", NULL, NULL, &cfg_irc_default_msg_quit, config_change_noop },
+ { "irc_lag_check", N_("interval between two checks for lag"),
+ N_("interval between two checks for lag (in seconds)"),
+ OPTION_TYPE_INT, 30, INT_MAX, 60,
+ NULL, NULL, &cfg_irc_lag_check, NULL, config_change_noop },
+ { "irc_lag_min_show", N_("minimum lag to show"),
+ N_("minimum lag to show (in seconds)"),
+ OPTION_TYPE_INT, 1, INT_MAX, 1,
+ NULL, NULL, &cfg_irc_lag_min_show, NULL, config_change_noop },
+ { "irc_lag_disconnect", N_("disconnect after important lag"),
+ N_("disconnect after important lag (in minutes, 0 = never disconnect)"),
+ OPTION_TYPE_INT, 0, INT_MAX, 5,
+ NULL, NULL, &cfg_irc_lag_disconnect, NULL, config_change_noop },
{ NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL }
};
diff --git a/src/common/weeconfig.h b/src/common/weeconfig.h
index 7e10c4255..85681dafe 100644
--- a/src/common/weeconfig.h
+++ b/src/common/weeconfig.h
@@ -154,6 +154,9 @@ extern int cfg_irc_display_away;
extern char *cfg_irc_default_msg_away;
extern char *cfg_irc_default_msg_part;
extern char *cfg_irc_default_msg_quit;
+extern int cfg_irc_lag_check;
+extern int cfg_irc_lag_min_show;
+extern int cfg_irc_lag_disconnect;
extern int cfg_dcc_auto_accept_files;
extern int cfg_dcc_auto_accept_chats;
diff --git a/src/gui/curses/gui-display.c b/src/gui/curses/gui-display.c
index 3c89eeeea..2da714033 100644
--- a/src/gui/curses/gui-display.c
+++ b/src/gui/curses/gui-display.c
@@ -1013,8 +1013,11 @@ gui_draw_buffer_status (t_gui_buffer *buffer, int erase)
/* display list of other active windows (if any) with numbers */
if (hotlist)
{
+ gui_window_set_color (ptr_win->win_status,
+ COLOR_WIN_STATUS_DELIMITERS);
+ wprintw (ptr_win->win_status, "[");
gui_window_set_color (ptr_win->win_status, COLOR_WIN_STATUS);
- wprintw (ptr_win->win_status, _("[Act: "));
+ wprintw (ptr_win->win_status, _("Act: "));
for (ptr_hotlist = hotlist; ptr_hotlist;
ptr_hotlist = ptr_hotlist->next_hotlist)
{
@@ -1045,10 +1048,27 @@ gui_draw_buffer_status (t_gui_buffer *buffer, int erase)
wprintw (ptr_win->win_status, ",");
}
gui_window_set_color (ptr_win->win_status,
- COLOR_WIN_STATUS);
+ COLOR_WIN_STATUS_DELIMITERS);
wprintw (ptr_win->win_status, "]");
}
+ /* display lag */
+ if (SERVER(ptr_win->buffer))
+ {
+ if (SERVER(ptr_win->buffer)->lag / 1000 >= cfg_irc_lag_min_show)
+ {
+ gui_window_set_color (ptr_win->win_status,
+ COLOR_WIN_STATUS_DELIMITERS);
+ wprintw (ptr_win->win_status, "[");
+ gui_window_set_color (ptr_win->win_status, COLOR_WIN_STATUS);
+ wprintw (ptr_win->win_status, _("Lag: %.1f"),
+ ((float)(SERVER(ptr_win->buffer)->lag)) / 1000);
+ gui_window_set_color (ptr_win->win_status,
+ COLOR_WIN_STATUS_DELIMITERS);
+ wprintw (ptr_win->win_status, "]");
+ }
+ }
+
/* display "-MORE-" if last line is not displayed */
gui_window_set_color (ptr_win->win_status, COLOR_WIN_STATUS_MORE);
if (ptr_win->sub_lines > 0)
diff --git a/src/gui/curses/gui-input.c b/src/gui/curses/gui-input.c
index eec1532ff..9001587b6 100644
--- a/src/gui/curses/gui-input.c
+++ b/src/gui/curses/gui-input.c
@@ -634,9 +634,10 @@ void
gui_main_loop ()
{
fd_set read_fd;
- static struct timeval timeout;
+ static struct timeval timeout, tv;
+ static struct timezone tz;
t_irc_server *ptr_server;
- int old_min, old_sec;
+ int old_min, old_sec, diff;
time_t new_time;
struct tm *local_time;
@@ -680,8 +681,38 @@ gui_main_loop ()
&& (new_time >= (ptr_server->reconnect_start + ptr_server->autoreconnect_delay)))
server_reconnect (ptr_server);
else
+ {
+ if (ptr_server->is_connected)
+ {
+ /* check for lag */
+ if ((ptr_server->lag_check_time.tv_sec == 0)
+ && (new_time >= ptr_server->lag_next_check))
+ {
+ server_sendf (ptr_server, "PING %s\r\n", ptr_server->address);
+ gettimeofday (&(ptr_server->lag_check_time), &tz);
+ }
+
+ /* lag timeout => disconnect */
+ if ((ptr_server->lag_check_time.tv_sec != 0)
+ && (cfg_irc_lag_disconnect > 0))
+ {
+ gettimeofday (&tv, &tz);
+ diff = (int) get_timeval_diff (&(ptr_server->lag_check_time), &tv);
+ if (diff / 1000 > cfg_irc_lag_disconnect * 60)
+ {
+ irc_display_prefix (ptr_server->buffer, PREFIX_ERROR);
+ gui_printf (ptr_server->buffer,
+ _("%s lag is high, disconnecting from server...\n"),
+ WEECHAT_WARNING);
+ server_disconnect (ptr_server, 1);
+ continue;
+ }
+ }
+ }
+
if (ptr_server->sock4 >= 0)
FD_SET (ptr_server->sock4, &read_fd);
+ }
}
if (select (FD_SETSIZE, &read_fd, NULL, NULL, &timeout))
{
diff --git a/src/irc/irc-commands.c b/src/irc/irc-commands.c
index 5b2a2d6c1..c2cdda618 100644
--- a/src/irc/irc-commands.c
+++ b/src/irc/irc-commands.c
@@ -161,7 +161,7 @@ t_irc_command irc_commands[] =
{ "pong", N_("answer to a ping message"),
N_("daemon [daemon2]"), N_("daemon: daemon who has responded to Ping message\n"
"daemon2: forward message to this daemon"),
- 1, 2, 1, NULL, irc_cmd_send_pong, NULL },
+ 1, 2, 1, NULL, irc_cmd_send_pong, irc_cmd_recv_pong },
{ "privmsg", N_("message received"),
"", "",
0, 0, 1, NULL, NULL, irc_cmd_recv_privmsg },
diff --git a/src/irc/irc-recv.c b/src/irc/irc-recv.c
index 8b193ca99..dbd7bda7b 100644
--- a/src/irc/irc-recv.c
+++ b/src/irc/irc-recv.c
@@ -938,6 +938,37 @@ irc_cmd_recv_ping (t_irc_server *server, char *host, char *arguments)
}
/*
+ * irc_cmd_recv_pong: 'pong' command received
+ */
+
+int
+irc_cmd_recv_pong (t_irc_server *server, char *host, char *arguments)
+{
+ struct timeval tv;
+ struct timezone tz;
+ int old_lag;
+
+ (void)host;
+ (void)arguments;
+
+ if (server->lag_check_time.tv_sec != 0)
+ {
+ /* calculate lag (time diff with lag check) */
+ old_lag = server->lag;
+ gettimeofday (&tv, &tz);
+ server->lag = (int) get_timeval_diff (&(server->lag_check_time), &tv);
+ if (old_lag != server->lag)
+ gui_draw_buffer_status (gui_current_window->buffer, 1);
+
+ /* schedule next lag check */
+ server->lag_check_time.tv_sec = 0;
+ server->lag_check_time.tv_usec = 0;
+ server->lag_next_check = time (NULL) + cfg_irc_lag_check;
+ }
+ return 0;
+}
+
+/*
* irc_cmd_recv_privmsg: 'privmsg' command received
*/
diff --git a/src/irc/irc-server.c b/src/irc/irc-server.c
index b3afa302f..680ebc98e 100644
--- a/src/irc/irc-server.c
+++ b/src/irc/irc-server.c
@@ -84,6 +84,10 @@ server_init (t_irc_server *server)
server->away_time = 0;
server->server_read = -1;
server->server_write = -1;
+ server->lag = 0;
+ server->lag_check_time.tv_sec = 0;
+ server->lag_check_time.tv_usec = 0;
+ server->lag_next_check = 0;
server->buffer = NULL;
server->channels = NULL;
server->last_channel = NULL;
@@ -818,8 +822,6 @@ server_disconnect (t_irc_server *server, int reconnect)
irc_display_prefix (ptr_channel->buffer, PREFIX_INFO);
gui_printf (ptr_channel->buffer, _("Disconnected from server!\n"));
}
- gui_draw_buffer_nick (gui_current_window->buffer, 1);
- gui_draw_buffer_status (gui_current_window->buffer, 1);
}
/* close communication with server */
@@ -839,6 +841,10 @@ server_disconnect (t_irc_server *server, int reconnect)
server->is_connected = 0;
server->is_away = 0;
server->away_time = 0;
+ server->lag = 0;
+ server->lag_check_time.tv_sec = 0;
+ server->lag_check_time.tv_usec = 0;
+ server->lag_next_check = 0;
if ((reconnect) && (server->autoreconnect))
{
@@ -849,6 +855,8 @@ server_disconnect (t_irc_server *server, int reconnect)
}
else
server->reconnect_start = 0;
+
+ gui_redraw_buffer (gui_current_window->buffer);
}
/*
diff --git a/src/irc/irc.h b/src/irc/irc.h
index dce8ae936..df8bf9f39 100644
--- a/src/irc/irc.h
+++ b/src/irc/irc.h
@@ -22,6 +22,7 @@
#define __WEECHAT_IRC_H 1
#include <time.h>
+#include <sys/time.h>
#include "../gui/gui.h"
/* prefixes for chat window */
@@ -142,6 +143,9 @@ struct t_irc_server
time_t away_time; /* time() when user marking as away */
int server_read; /* pipe for reading server data */
int server_write; /* pipe for sending data to server */
+ int lag; /* lag (in milliseconds) */
+ struct timeval lag_check_time; /* last time lag was checked (ping sent)*/
+ time_t lag_next_check; /* time for next check */
t_gui_buffer *buffer; /* GUI buffer allocated for server */
t_irc_channel *channels; /* opened channels on server */
t_irc_channel *last_channel; /* last opened channal on server */
@@ -337,6 +341,7 @@ extern int irc_cmd_recv_nick (t_irc_server *, char *, char *);
extern int irc_cmd_recv_notice (t_irc_server *, char *, char *);
extern int irc_cmd_recv_part (t_irc_server *, char *, char *);
extern int irc_cmd_recv_ping (t_irc_server *, char *, char *);
+extern int irc_cmd_recv_pong (t_irc_server *, char *, char *);
extern int irc_cmd_recv_privmsg (t_irc_server *, char *, char *);
extern int irc_cmd_recv_quit (t_irc_server *, char *, char *);
extern int irc_cmd_recv_server_msg (t_irc_server *, char *, char *);