X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=x5%2Fkhatus.c;h=2445c1b918298fdfcaf7a76d4d41927c17adfafd;hb=51e63a6f4abb7090146eff8a0294375ec9525205;hp=35509d47763c6db37736036e71d05eb9a4875be5;hpb=4e3d71e8aad165df793a94f58ffa3c969400c736;p=khatus.git diff --git a/x5/khatus.c b/x5/khatus.c index 35509d4..2445c1b 100644 --- a/x5/khatus.c +++ b/x5/khatus.c @@ -143,7 +143,7 @@ slot_set_error(Slot *s, char *buf) } enum read_status -slot_read(Slot *s, struct timespec t, char *buf) +slot_read(Slot *s, char *buf) { char c; /* Character read. */ int r; /* Remaining unused positions in buffer range. */ @@ -174,18 +174,18 @@ slot_read(Slot *s, struct timespec t, char *buf) r = (s->out_pos_hi - s->out_pos_cur) + 1; if (r > 0) memset(buf + s->out_pos_cur, ' ', r); - s->out_pos_cur = s->out_pos_lo; - s->in_last_read = t; return END_OF_MESSAGE; } else { if (s->out_pos_cur <= s->out_pos_hi) buf[s->out_pos_cur++] = c; - /* Drop beyond available range. */ - /* - * TODO Define max after which we stop reading. - * To ensure that a rogue large message - * doesn't trap us here. - */ + else + /* + * Force EOM beyond available range. + * To ensure that a rogue large message + * doesn't trap us here needlessly + * long. + */ + return END_OF_MESSAGE; } break; default: @@ -277,7 +277,7 @@ slots_read(Config *cfg, struct timespec *ti, char *buf) continue; if (FD_ISSET(s->in_fd, &fds)) { khlib_debug("reading: %s\n", s->in_fifo); - switch (slot_read(s, t, buf)) { + switch (slot_read(s, buf)) { /* * ### MESSAGE LOSS ### * is introduced by closing at EOM in addition @@ -291,12 +291,27 @@ slots_read(Config *cfg, struct timespec *ti, char *buf) * This is an acceptable trade-off because we * are a stateless reporter of a _most-recent_ * status, not a stateful accumulator. + * + * ### LOSSLESS ALTERNATIVES ### + * - Read each pipe until EOF before reading + * another. + * PROBLEM: a fast writer can trap us in the + * read loop. + * + * - Read each pipe until EOM, but close only + * at EOF. + * PROBLEM: a fast writer can fill the pipe + * faster than we can read it and we end-up + * displaying stale data. + * */ case END_OF_MESSAGE: case END_OF_FILE: case FAILURE: close(s->in_fd); - s->in_fd = -1; + s->in_fd = -1; + s->in_last_read = t; + s->out_pos_cur = s->out_pos_lo; ready--; break; case RETRY: