summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Carbonneaux2022-05-10 21:17:19 +0200
committerQuentin Carbonneaux2024-04-12 19:53:35 +0000
commit17fc6b5c307623fb94a2b5179e5732119a08704f (patch)
treef55a01dd3da58e16410c35a011ea28e35e1c2b76
parente8fdea1df28fd08f4a8d150ddf99f1eb530f0e0f (diff)
ping the server regularly
-rw-r--r--irc.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/irc.c b/irc.c
index 4255bda..a455991 100644
--- a/irc.c
+++ b/irc.c
@@ -40,6 +40,7 @@ enum {
BufSz = 2048,
LogSz = 4096,
MaxRecons = 10, /* -1 for infinitely many */
+ PingDelay = 6,
UtfSz = 4,
RuneInvalid = 0xFFFD,
};
@@ -462,6 +463,8 @@ scmd(char *usr, char *cmd, char *par, char *data)
}
} else if (!strcmp(cmd, "PING")) {
sndf("PONG :%s", data ? data : "(null)");
+ } else if (!strcmp(cmd, "PONG")) {
+ /* nothing */
} else if (!strcmp(cmd, "PART")) {
if (!pm)
return;
@@ -812,7 +815,7 @@ main(int argc, char *argv[])
const char *server = SRV;
const char *port = PORT;
char *err;
- int o, reconn;
+ int o, reconn, ping;
signal(SIGPIPE, SIG_IGN);
while ((o = getopt(argc, argv, "thk:n:u:s:p:l:")) >= 0)
@@ -859,6 +862,7 @@ main(int argc, char *argv[])
chadd(server, 0);
sinit(key, nick, user);
reconn = 0;
+ ping = 0;
while (!quit) {
struct timeval t = {.tv_sec = 5};
struct Chan *c;
@@ -918,6 +922,13 @@ main(int argc, char *argv[])
tgetch();
wrefresh(scr.iw);
}
+ if (!FD_ISSET(srv.fd, &wfs))
+ if (!FD_ISSET(srv.fd, &rfs))
+ if (outp == outb)
+ if (++ping == PingDelay) {
+ sndf("PING %s", server);
+ ping = 0;
+ }
}
hangup();
while (nch--)