circo

claudio's IRC oasis
git clone git://git.bitsmanent.org/circo
Log | Files | Refs | README | LICENSE

commit b2d965211a4ce6ef20ac6349c1322ded534b6ae3
parent 68d45b297520cb9596befa948b864b43e6542efd
Author: Claudio Alessi <smoppy@gmail.com>
Date:   Wed, 18 Apr 2018 20:00:17 +0200

Use globals to store I/O buffers.

Lost connections are now handled in main(). This makes sense because the
parsesrv() function should be called only if there is data available from the
server, else we should just disconnects. Which is how it works now.

When a connection goes down, the message "Remote host closed connection" is
sent to all buffers.

Diffstat:
Mcirco.c | 28+++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/circo.c b/circo.c @@ -157,6 +157,8 @@ void usrin(void); /* variables */ FILE *srv, *logp; Buffer *buffers, *status, *sel; +char bufin[4096]; +char bufout[4096]; struct termios origti; int running = 1; int rows, cols; @@ -758,15 +760,8 @@ parsecmd(void) { void parsesrv(void) { char *cmd, *usr, *par, *txt; - char buf[BUFSZ]; - if(fgets(buf, sizeof buf, srv) == NULL) { - srv = NULL; - bprintf(sel, "! Remote host closed connection.\n"); - return; - } - - cmd = buf; + cmd = bufin; usr = host; if(!cmd || !*cmd) return; @@ -995,12 +990,11 @@ skip(char *s, char c) { void sout(char *fmt, ...) { va_list ap; - char buf[BUFSZ]; va_start(ap, fmt); - vsnprintf(buf, sizeof buf, fmt, ap); + vsnprintf(bufout, sizeof bufout, fmt, ap); va_end(ap); - fprintf(srv, "%s\r\n", buf); + fprintf(srv, "%s\r\n", bufout); } void @@ -1133,8 +1127,16 @@ main(int argc, char *argv[]) { sout("PING %s", host); continue; } - if(srv && FD_ISSET(fileno(srv), &rd)) - parsesrv(); + if(srv && FD_ISSET(fileno(srv), &rd)) { + if(fgets(bufin, sizeof bufin, srv) == NULL) { + srv = NULL; + bprintf(sel, "Remote host closed connection.\n"); + for(Buffer *b = buffers; b; b = b->next) + bprintf(b, "Remote host closed connection.\n"); + } + else + parsesrv(); + } if(FD_ISSET(0, &rd)) usrin(); if(sel->need_redraw) {