aboutsummaryrefslogtreecommitdiff
path: root/src/irc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/irc.c')
-rw-r--r--src/irc.c71
1 files changed, 37 insertions, 34 deletions
diff --git a/src/irc.c b/src/irc.c
index 9269206..eee3cab 100644
--- a/src/irc.c
+++ b/src/irc.c
@@ -42,7 +42,7 @@ char numbuf[10];
char last_pm_nick[33];
char last_chan[33]; /* without a screen */
-static char ping_sent = 0;
+static int minutes, last_read_min;
/*
static void join_channel(void) {
@@ -153,8 +153,6 @@ static void print_ping_time(char *p) {
}
static void do_server_pong(void) {
- ping_sent = 0;
- if(*msg_text == 'A') return; /* don't print auto-pings */
msg_src = "Server";
// FIXME: what if the server doesn't :-quote the response?
print_ping_time(msg_text);
@@ -545,7 +543,7 @@ static void dispatch_msg(void) {
} else if(streq_i(msg_cmd, "MODE")) {
do_mode();
} else if(streq_i(msg_cmd, "PONG")) {
- do_server_pong();
+ if(*msg_text != 'A') do_server_pong();
} else if(isdigit(msg_cmd[0])) {
do_numeric();
} else {
@@ -675,45 +673,49 @@ void print_errnum(void) {
scr_print_current(numbuf);
}
-/* gets called on *any* incoming network traffic */
-static void reset_watchdog() {
- // scr_print_current("reset_watchdog()\n");
+static void start_minute_timer() {
+ minutes = 0;
OS.cdtmf4 = 0xff;
OS.cdtmv4 = 60 * hz;
}
-/* after 60 sec of inactivity from the server, send it a ping.
- if it doesn't reply within another 60 seconds, assume it's dead. */
-static char check_watchdog() {
- /*
- scr_print_current("check_watchdog()\nping_sent==");
- if(ping_sent)
- scr_print_current("1\n");
- else
- scr_print_current("0\n");
- */
-
- if(!OS.cdtmf4) { /* timer hath expired */
- if(ping_sent) {
- ping_sent = 0;
- bell(); /* for testing only */
- scr_print_current("Server timed out");
- return 0; /* we pinged and didn't get a pong :( */
- } else {
- ping_sent = 1;
- // bell(); /* for testing only */
- // cmd_server_ping();
- txbuf_send_str("PING A");
- reset_watchdog();
- }
+static char service_minute_timer() {
+ signed int idle;
+
+ if(OS.cdtmf4) return 1; /* timer hath not expired */
+
+ minutes++;
+ start_minute_timer();
+ idle = minutes - last_read_min;
+
+ /* if idle is 1, that doesn't really mean a full minute of
+ idle time: last_read_min might have gotten set just before
+ minutes updated. think of it as rounding up. */
+ if(idle < 0) {
+ /* timer rolled over, reset and ignore */
+ last_read_min = minutes;
+ return 1;
+ } else if(idle < 2) {
+ /* idle between 1 and 60 sec, no problem. */
+ return 1;
+ } else if(idle == 2) {
+ /* we've been idle between 61 and 120 seconds.
+ generate some traffic. */
+ txbuf_send_str("PING A");
+ return 1;
+ } else {
+ /* idle >=121 sec, already sent a ping, got nothing back.
+ we timed out. */
+ bell(); /* for testing only */
+ scr_print_current("Server timed out");
+ return 0;
}
- return 1;
}
int irc_read(void) {
if(!trip) return 1;
- reset_watchdog(); /* on any incoming network traffic */
+ last_read_min = minutes;
err = nstatus(conf->url);
if(err != 1) {
@@ -1012,6 +1014,7 @@ static void keystroke(void) {
/* only exits on error (e.g. connection closed, which might be via /QUIT). */
void irc_loop(void) {
hide_motd = conf->hide_motd;
+ start_minute_timer();
while(1) {
ind_check_timer();
if(conf->atract_away) {
@@ -1020,7 +1023,7 @@ void irc_loop(void) {
txbuf_send_str("AWAY :ATRACT mode");
}
}
- if(!irc_read() || !check_watchdog()) {
+ if(!irc_read() || !service_minute_timer()) {
regged = 0;
return;
}