diff options
Diffstat (limited to 'src/irc.c')
| -rw-r--r-- | src/irc.c | 51 |
1 files changed, 49 insertions, 2 deletions
@@ -42,6 +42,8 @@ char numbuf[10]; char last_pm_nick[33]; char last_chan[33]; /* without a screen */ +static char ping_sent = 0; + /* static void join_channel(void) { txbuf_set_str2("JOIN ", channel); @@ -134,7 +136,7 @@ static void print_ping_time(char *p) { scr_print_active("*** "); scr_print_active(msg_src); - scr_print_active(" ping time: "); + scr_print_active(" lag: "); itoa(sec, numbuf, 10); scr_print_active(numbuf); scr_print_active("."); @@ -151,9 +153,12 @@ static void print_ping_time(char *p) { } static void do_server_pong(void) { + 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); + scr_eol_active(); + ping_sent = 0; } /* FIXME: this isn't very fast */ @@ -670,9 +675,45 @@ 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"); + 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(); + } + } + return 1; +} + int irc_read(void) { if(!trip) return 1; + reset_watchdog(); /* on any incoming network traffic */ err = nstatus(conf->url); if(err != 1) { @@ -944,6 +985,9 @@ static void start_keystroke(void) { case 'e': toggle_edbox_only(); break; + case 0x04: /* ^D */ + fn_disconnect(); /* testing only! */ + break; case 's': edbox_hide(); /* fall thru */ @@ -976,7 +1020,10 @@ void irc_loop(void) { txbuf_send_str("AWAY :ATRACT mode"); } } - if(!irc_read()) return; + if(!irc_read() || !check_watchdog()) { + regged = 0; + return; + } keystroke(); } } |
