summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2001-11-15 13:47:51 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2001-11-15 13:47:51 +0000
commitc6302cd6e72963d755ebf3aae3bda11b066bc21c (patch)
treea4b072c7426fce3c50cfaf6b9bacf750e63a653c /src
parent4d771c54d9e1396792248f611453cbfccfad9570 (diff)
downloadirssi-c6302cd6e72963d755ebf3aae3bda11b066bc21c.zip
Lag checking fixes - should work fine again.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2016 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src')
-rw-r--r--src/core/server-rec.h2
-rw-r--r--src/fe-common/core/fe-server.c3
-rw-r--r--src/fe-text/statusbar-items.c4
-rw-r--r--src/irc/core/lag.c77
4 files changed, 16 insertions, 70 deletions
diff --git a/src/core/server-rec.h b/src/core/server-rec.h
index 185809be..52526fde 100644
--- a/src/core/server-rec.h
+++ b/src/core/server-rec.h
@@ -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 */
diff --git a/src/fe-common/core/fe-server.c b/src/fe-common/core/fe-server.c
index 11fea23b..cd783898 100644
--- a/src/fe-common/core/fe-server.c
+++ b/src/fe-common/core/fe-server.c
@@ -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)
diff --git a/src/fe-text/statusbar-items.c b/src/fe-text/statusbar-items.c
index da485d5b..e6f23797 100644
--- a/src/fe-text/statusbar-items.c
+++ b/src/fe-text/statusbar-items.c
@@ -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) {
diff --git a/src/irc/core/lag.c b/src/irc/core/lag.c
index a7412440..ec3a3f1f 100644
--- a/src/irc/core/lag.c
+++ b/src/irc/core/lag.c
@@ -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)
-{
- GSList *tmp;
-
- 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)
+static void lag_get(IRC_SERVER_REC *server)
{
- IRC_SERVER_REC *server;
+ g_get_current_time(&server->lag_sent);
+ server->lag_last_check = time(NULL);
- 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);
}