commit cfcd4f66c467e39955829d43fcc5dd849895f9d8
parent aee018de4a1323337107b270ec150f07ea5f9f80
Author: Andrew Kloet <andrew@kloet.net>
Date: Tue, 21 Apr 2026 13:39:48 -0400
add reconnect patch
Diffstat:
1 file changed, 79 insertions(+), 0 deletions(-)
diff --git a/patches/reconnect.diff b/patches/reconnect.diff
@@ -0,0 +1,79 @@
+ cio.c | 32 +++++++++++++++++++++++++-------
+ 1 file changed, 25 insertions(+), 7 deletions(-)
+
+diff --git a/cio.c b/cio.c
+index fe90dc3..f7d3bdc 100644
+--- a/cio.c
++++ b/cio.c
+@@ -942,7 +942,7 @@ main(int argc, char *argv[])
+ const char *server = SRV;
+ const char *port = PORT;
+ const char *err;
+- int o, ping;
++ int o, ping, reconn;
+
+ signal(SIGPIPE, SIG_IGN);
+ while ((o = getopt(argc, argv, "hvTVn:c:u:s:p:l:")) >= 0)
+@@ -995,13 +995,14 @@ main(int argc, char *argv[])
+ tinit();
+ err = dial(server, port);
+ #ifdef __OpenBSD__
+- if (pledge("stdio tty", NULL) == -1)
++ if (pledge("stdio tty rpath inet dns", NULL) == -1)
+ die("pledge");
+ #endif /* __OpenBSD__ */
+ if (err) die("cio: %s", err);
+ chadd(server, 0);
+ sinit(nick, user);
+ ping = 0;
++ reconn = 0;
+ while (!quit) {
+ struct timeval t = {.tv_sec = 5};
+ fd_set rfs, wfs;
+@@ -1010,24 +1011,41 @@ main(int argc, char *argv[])
+ FD_ZERO(&wfs);
+ FD_ZERO(&rfs);
+ FD_SET(0, &rfs);
+- FD_SET(srv.fd, &rfs);
+- if (outp != outb)
+- FD_SET(srv.fd, &wfs);
++ if (!reconn) {
++ FD_SET(srv.fd, &rfs);
++ if (outp != outb)
++ FD_SET(srv.fd, &wfs);
++ }
+ if (select(srv.fd + 1, &rfs, &wfs, 0, &t) < 0) {
+ if (errno == EINTR)
+ continue;
+ die("cio: select failed:");
+ }
++ if (reconn) {
++ hangup();
++ if (reconn > MaxRecons)
++ die("cio: link lost");
++ pushf(0, "-!- Link lost, attempt %d/%d...", reconn++, MaxRecons);
++ if (dial(server, port) != 0)
++ continue;
++ sinit(nick, user);
++ for (struct Chan *c = chl; c < &chl[nch]; ++c)
++ if (c->join)
++ sndf("JOIN %s", c->name);
++ reconn = 0;
++ }
+ if (FD_ISSET(srv.fd, &rfs)) {
+ if (!srd()) {
+- die("cio: read error:");
++ reconn = 1;
++ continue;
+ }
+ }
+ if (FD_ISSET(srv.fd, &wfs)) {
+ size_t len = outp - outb;
+ int wr = ssl ? SSL_write(srv.ssl, outb, len) : write(srv.fd, outb, len);
+ if (wr <= 0) {
+- die("cio: write error:");
++ reconn = 1;
++ continue;
+ }
+ outp -= wr;
+ memmove(outb, outb + wr, outp - outb);