From f040b1fe921a666514b59f0374817832e11bca2d Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 29 May 2010 13:56:16 +0100 Subject: [PATCH] Group counters into struct --- cli.c | 10 +++++----- infile.c | 12 ++++++------ innduct.h | 8 ++++++-- recv.c | 4 ++-- statemc.c | 12 +++++------- xmit.c | 6 +++--- 6 files changed, 27 insertions(+), 25 deletions(-) diff --git a/cli.c b/cli.c index b03f370..be9af38 100644 --- a/cli.c +++ b/cli.c @@ -329,17 +329,17 @@ static void dump_input_file(FILE *f, const CliCommand *c, free(dipf); if (ipf) { - DUMPV("%d", ipf->,readcount_ok); - DUMPV("%d", ipf->,readcount_blank); - DUMPV("%d", ipf->,readcount_err); - DUMPV("%d", ipf->,count_nooffer_missing); + DUMPV("%d", ipf->counts.,read_ok); + DUMPV("%d", ipf->counts.,read_blank); + DUMPV("%d", ipf->counts.,read_err); + DUMPV("%d", ipf->counts.,nooffer_missing); } fprintf(f,"\n"); if (ipf) { ArtState state; const char *const *statename; for (state=0, statename=artstate_names; *statename; state++,statename++) { #define RC_DUMP_FMT(x) " " #x "=%d" -#define RC_DUMP_VAL(x) ,ipf->counts[state][RC_##x] +#define RC_DUMP_VAL(x) ,ipf->counts.counts[state][RC_##x] fprintf(f,"input %s counts %-11s" RESULT_COUNTS(RC_DUMP_FMT,RC_DUMP_FMT) "\n", wh, *statename diff --git a/infile.c b/infile.c index 3fc1ff6..7ff6a51 100644 --- a/infile.c +++ b/infile.c @@ -77,11 +77,11 @@ static void *feedfile_got_bad_data(InputFile *ipf, off_t offset, const char *data, const char *how) { warn("corrupted file: %s, offset %lu: %s: in %s", ipf->path, (unsigned long)offset, how, sanitise(data,-1)); - ipf->readcount_err++; - if (ipf->readcount_err > max_bad_data_initial + - (ipf->readcount_ok+ipf->readcount_blank) / max_bad_data_ratio) + ipf->counts.read_err++; + if (ipf->counts.read_err > max_bad_data_initial + + (ipf->counts.read_ok + ipf->counts.read_blank) / max_bad_data_ratio) crash("too much garbage in input file! (%d errs, %d ok, %d blank)", - ipf->readcount_err, ipf->readcount_ok, ipf->readcount_blank); + ipf->counts.read_err, ipf->counts.read_ok, ipf->counts.read_blank); return OOP_CONTINUE; } @@ -129,7 +129,7 @@ static void *feedfile_got_article(oop_source *lp, oop_read *rd, if (data[0]==' ') { if (strspn(data," ") != recsz) X_BAD_DATA("line partially blanked"); - ipf->readcount_blank++; + ipf->counts.read_blank++; return OOP_CONTINUE; } @@ -144,7 +144,7 @@ static void *feedfile_got_article(oop_source *lp, oop_read *rd, tokentextbuf[tokenlen]= 0; if (!IsToken(tokentextbuf)) X_BAD_DATA("token wrong syntax"); - ipf->readcount_ok++; + ipf->counts.read_ok++; art= xmalloc(sizeof(*art) - 1 + midlen + 1); memset(art,0,sizeof(*art)); diff --git a/innduct.h b/innduct.h index 65077d6..919b734 100644 --- a/innduct.h +++ b/innduct.h @@ -237,6 +237,11 @@ struct XmitDetails { /*----- core operational data structure types -----*/ +typedef struct { + int counts[art_MaxState][RCI_max]; + int read_ok, read_blank, read_err, nooffer_missing; +} Counts; + struct InputFile { /* This is also an instance of struct oop_readable */ struct oop_readable readable; /* first */ @@ -254,8 +259,7 @@ struct InputFile { long inprogress; /* includes queue.count and also articles in conns */ long autodefer; /* -1 means not doing autodefer */ - int counts[art_MaxState][RCI_max]; - int readcount_ok, readcount_blank, readcount_err, count_nooffer_missing; + Counts counts; char path[]; }; diff --git a/recv.c b/recv.c index dbeb4b6..5204dce 100644 --- a/recv.c +++ b/recv.c @@ -117,7 +117,7 @@ static void update_nocheck(int accepted) { void article_done(Article *art, int whichcount) { if (whichcount>=0 && !art->missing) - art->ipf->counts[art->state][whichcount]++; + art->ipf->counts.counts[art->state][whichcount]++; if (whichcount == RC_accepted) update_nocheck(1); else if (whichcount == RC_unwanted) update_nocheck(0); @@ -242,7 +242,7 @@ void *peer_rd_ok(oop_source *lp, oop_read *oread, oop_rd_event ev, case 335: /* IHAVE says send it */ GET_ARTICLE(-1); assert(art->state == art_Unchecked); - art->ipf->counts[art->state][RC_accepted]++; + art->ipf->counts.counts[art->state][RC_accepted]++; art->state= art_Wanted; LIST_ADDTAIL(conn->priority, art); break; diff --git a/statemc.c b/statemc.c index 5adecf9..8b58803 100644 --- a/statemc.c +++ b/statemc.c @@ -222,9 +222,9 @@ static void notice_processed(InputFile *ipf, int completed, #define RCI_NOTHING(x) /* nothing */ #define RCI_TRIPLE_FMT(x) " " #x "=" RCI_TRIPLE_FMT_BASE -#define RCI_TRIPLE_VALS(x) , RCI_TRIPLE_VALS_BASE(ipf->counts, [RC_##x]) +#define RCI_TRIPLE_VALS(x) , RCI_TRIPLE_VALS_BASE(ipf->counts.counts, [RC_##x]) -#define CNT(art,rc) (ipf->counts[art_##art][RC_##rc]) +#define CNT(art,rc) (ipf->counts.counts[art_##art][RC_##rc]) char *inprog= completed ? xasprintf("%s","") /* GCC produces a stupid warning for printf("") ! */ @@ -238,8 +238,8 @@ static void notice_processed(InputFile *ipf, int completed, RESULT_COUNTS(RCI_NOTHING, RCI_TRIPLE_FMT) , completed?"completed":"processed", what, spec, - ipf->readcount_ok, ipf->readcount_blank, ipf->readcount_err, - inprog, autodefer, ipf->count_nooffer_missing, + ipf->counts.read_ok, ipf->counts.read_blank, ipf->counts.read_err, + inprog, autodefer, ipf->counts.nooffer_missing, CNT(Unchecked,sent) + CNT(Unsolicited,sent) , CNT(Unchecked,sent), CNT(Unsolicited,sent), CNT(Wanted,accepted) + CNT(Unsolicited,accepted) @@ -247,9 +247,7 @@ static void notice_processed(InputFile *ipf, int completed, RESULT_COUNTS(RCI_NOTHING, RCI_TRIPLE_VALS) ); - memset(ipf->counts, 0, sizeof(ipf->counts)); - ipf->readcount_ok= ipf->readcount_blank= - ipf->readcount_err= ipf->count_nooffer_missing= 0; + memset(&ipf->counts, 0, sizeof(ipf->counts)); free(inprog); free(autodefer); diff --git a/xmit.c b/xmit.c index 269e823..a438916 100644 --- a/xmit.c +++ b/xmit.c @@ -174,7 +174,7 @@ int article_check_expired(Article *art /* must be queued, not conn */) { LIST_REMOVE(art->ipf->queue, art); art->missing= 1; - art->ipf->count_nooffer_missing++; + art->ipf->counts.nooffer_missing++; article_done(art,-1); return 1; } @@ -329,7 +329,7 @@ void conn_make_some_xmits(Conn *conn) { (abort(),-1); if (!artdata) art->missing= 1; - art->ipf->counts[art->state][ artdata ? RC_sent : RC_missing ]++; + art->ipf->counts.counts[art->state][ artdata ? RC_sent : RC_missing ]++; if (conn->stream) { if (artdata) { @@ -363,7 +363,7 @@ void conn_make_some_xmits(Conn *conn) { XMIT_LITERAL("\r\n"); assert(art->state == art_Unchecked); - art->ipf->counts[art->state][RC_sent]++; + art->ipf->counts.counts[art->state][RC_sent]++; LIST_ADDTAIL(conn->sent, art); } } -- 2.30.2