From: Markus Armbruster Date: Wed, 23 Nov 2011 18:56:24 +0000 (+0100) Subject: Clean up how read deals with new telegram arrivals X-Git-Tag: v4.3.29~8 X-Git-Url: http://git.pond.sub.org/?p=empserver;a=commitdiff_plain;h=b6f666cff95509391b86dc12b3cd5c003a76ba2b Clean up how read deals with new telegram arrivals Fooling around with the file size is silly. It works only because read has flag C_MOD set, so they can only arrive while we're sitting at the delete confirmation prompt, not during reading. Simply try to read more telegrams instead. --- diff --git a/src/lib/commands/rea.c b/src/lib/commands/rea.c index 28f787274..94ba14d42 100644 --- a/src/lib/commands/rea.c +++ b/src/lib/commands/rea.c @@ -60,9 +60,7 @@ rea(void) struct telstr tgm; FILE *telfp; int teles; - int size; char buf[1024]; - int filelen; char *kind; int n, res; int num = player->cnum; @@ -101,9 +99,11 @@ rea(void) return RET_FAIL; } teles = 0; - size = fsize(fileno(telfp)); - more: - while ((res = tel_read_header(telfp, mbox, &tgm)) > 0) { + for (;;) { + res = tel_read_header(telfp, mbox, &tgm); + more: + if (res <= 0) + break; if (*kind == 'a') { if ((!player->god && (getrejects(tgm.tel_from, np) & REJ_ANNO)) || tgm.tel_date < then) { @@ -161,13 +161,12 @@ rea(void) np->nat_annotim = now; putnat(np); } else { - if ((filelen = fsize(fileno(telfp))) > size) { + /* force stdio to re-read tel file */ + fflush(telfp); + fseek(telfp, 0, SEEK_CUR); + res = tel_read_header(telfp, mbox, &tgm); + if (res != 0) { pr("Wait a sec! A new %s has arrived...\n", kind); - /* force stdio to re-read tel file */ - (void)fflush(telfp); - (void)fseek(telfp, (long)size, SEEK_SET); - size = filelen; - now = time(NULL); goto more; } /* Here, we just re-open the file for "w" only,