1
0
mirror of https://github.com/irssi/irssi.git synced 2024-11-03 04:27:19 -05:00

Lag checking fixes - should work fine again.

git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2016 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2001-11-15 13:47:51 +00:00 committed by cras
parent 4d771c54d9
commit c6302cd6e7
4 changed files with 16 additions and 70 deletions

View File

@ -33,7 +33,7 @@ unsigned int usermode_away:1;
unsigned int banned:1; /* not allowed to connect to this server */
unsigned int dns_error:1; /* DNS said the host doesn't exist */
time_t lag_sent; /* 0 or time when last lag query was sent to server */
GTimeVal lag_sent; /* 0 or time when last lag query was sent to server */
time_t lag_last_check; /* last time we checked lag */
int lag; /* server lag in milliseconds */

View File

@ -287,7 +287,8 @@ static void sig_server_lag_disconnected(SERVER_REC *server)
g_return_if_fail(server != NULL);
printformat(server, NULL, MSGLEVEL_CLIENTNOTICE,
TXT_LAG_DISCONNECTED, server->connrec->address, time(NULL)-server->lag_sent);
TXT_LAG_DISCONNECTED, server->connrec->address,
time(NULL)-server->lag_sent.tv_sec);
}
static void sig_server_reconnect_removed(RECONNECT_REC *reconnect)

View File

@ -89,7 +89,7 @@ static void item_lag(SBAR_ITEM_REC *item, int get_size_only)
str = g_string_new(NULL);
/* FIXME: ugly ugly.. */
if (server->lag_sent == 0 || now-server->lag_sent < 5) {
if (server->lag_sent.tv_sec == 0 || now-server->lag_sent.tv_sec < 5) {
lag_unknown = now-server->lag_last_check >
MAX_LAG_UNKNOWN_TIME+settings_get_int("lag_check_time");
lag_min_show = settings_get_int("lag_min_show")*10;
@ -105,7 +105,7 @@ static void item_lag(SBAR_ITEM_REC *item, int get_size_only)
} else {
/* big lag, still waiting .. */
g_string_sprintfa(str, "%ld (?""?)",
(long) (now-server->lag_sent));
(long) (now-server->lag_sent.tv_sec));
}
if (str->len != 0) {

View File

@ -26,94 +26,42 @@
#include "irc-servers.h"
#include "servers-redirect.h"
typedef struct {
IRC_SERVER_REC *server;
GTimeVal time;
} LAG_REC;
static int timeout_tag;
static gint timeout_tag;
static GSList *lags;
static LAG_REC *lag_find(IRC_SERVER_REC *server)
static void lag_get(IRC_SERVER_REC *server)
{
GSList *tmp;
g_get_current_time(&server->lag_sent);
server->lag_last_check = time(NULL);
for (tmp = lags; tmp != NULL; tmp = tmp->next) {
LAG_REC *lag = tmp->data;
if (lag->server == server)
return lag;
}
return NULL;
}
static void lag_free(LAG_REC *rec)
{
lags = g_slist_remove(lags, rec);
g_free(rec);
}
static void lag_send(LAG_REC *lag)
{
IRC_SERVER_REC *server;
g_get_current_time(&lag->time);
server = lag->server;
server->lag_sent = server->lag_last_check = time(NULL);
server_redirect_event(server, "ping", 1, NULL, FALSE,
"lag ping error",
"event pong", "lag pong", NULL);
irc_send_cmdv(server, "PING %s", server->real_address);
}
static void lag_get(IRC_SERVER_REC *server)
{
LAG_REC *lag;
g_return_if_fail(server != NULL);
/* nick changes may fail this check, so we should never do this
while there's nick change request waiting for reply in server.. */
lag = g_new0(LAG_REC, 1);
lags = g_slist_append(lags, lag);
lag->server = server;
lag_send(lag);
}
/* we didn't receive PONG for some reason .. try again */
static void lag_ping_error(IRC_SERVER_REC *server)
{
LAG_REC *lag;
lag = lag_find(server);
if (lag != NULL)
lag_send(lag);
lag_get(server);
}
static void lag_event_pong(IRC_SERVER_REC *server, const char *data,
const char *nick, const char *addr)
{
GTimeVal now;
LAG_REC *lag;
g_return_if_fail(data != NULL);
lag = lag_find(server);
if (lag == NULL) {
if (server->lag_sent.tv_sec == 0) {
/* not expecting lag reply.. */
return;
}
server->lag_sent = 0;
g_get_current_time(&now);
server->lag = (int) get_timeval_diff(&now, &lag->time);
signal_emit("server lag", 1, server);
server->lag = (int) get_timeval_diff(&now, &server->lag_sent);
memset(&server->lag_sent, 0, sizeof(server->lag_sent));
lag_free(lag);
signal_emit("server lag", 1, server);
}
static int sig_check_lag(void)
@ -136,9 +84,9 @@ static int sig_check_lag(void)
if (!IS_IRC_SERVER(rec))
continue;
if (rec->lag_sent != 0) {
if (rec->lag_sent.tv_sec != 0) {
/* waiting for lag reply */
if (max_lag > 1 && now-rec->lag_sent > max_lag) {
if (max_lag > 1 && now-rec->lag_sent.tv_sec > max_lag) {
/* too much lag, disconnect */
signal_emit("server lag disconnect", 1, rec);
rec->connection_lost = TRUE;
@ -159,7 +107,6 @@ void lag_init(void)
settings_add_int("misc", "lag_check_time", 30);
settings_add_int("misc", "lag_max_before_disconnect", 300);
lags = NULL;
timeout_tag = g_timeout_add(1000, (GSourceFunc) sig_check_lag, NULL);
signal_add_first("lag pong", (SIGNAL_FUNC) lag_event_pong);
signal_add("lag ping error", (SIGNAL_FUNC) lag_ping_error);
@ -168,8 +115,6 @@ void lag_init(void)
void lag_deinit(void)
{
g_source_remove(timeout_tag);
while (lags != NULL)
lag_free(lags->data);
signal_remove("lag pong", (SIGNAL_FUNC) lag_event_pong);
signal_remove("lag ping error", (SIGNAL_FUNC) lag_ping_error);
}