X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=innduct.git;a=blobdiff_plain;f=infile.c;h=b8e01bcfc6f6ad200a19741f70bcfa14a2f7dd1a;hp=3c93d1f2d1c796b171f61d8382e19e2ade19c70d;hb=a34c62479ae1f91aac7b30d3d5f1a5106a6635f5;hpb=ff034fbd099c2ad74cba31e5beb9f1f54a80fc29 diff --git a/infile.c b/infile.c index 3c93d1f..b8e01bc 100644 --- a/infile.c +++ b/infile.c @@ -59,6 +59,8 @@ InputFile *open_input_file(const char *path) { LIST_INIT(ipf->queue); strcpy(ipf->path, path); + dbg("started input file %p %s", ipf, path); + return ipf; } @@ -178,48 +180,57 @@ static void *feedfile_got_article(oop_source *lp, oop_read *rd, /*========== tailing input file ==========*/ +static void tailing_rable_on_time(InputFile *ipf); + static void *tailing_rable_call_time(oop_source *lp, struct timeval tv, void *user) { /* lifetime of ipf here is OK because destruction will cause * on_cancel which will cancel this callback */ InputFile *ipf= user; - dbg("**TRACT** ipf=%p called",ipf); + //dbg("**TRACT** ipf=%p called",ipf); if (!ipf->fake_readable) return OOP_CONTINUE; /* we just keep calling readable until our caller (oop_rd) * has called try_read, and try_read has found EOF so given EAGAIN */ - dbg("**TRACT** ipf=%p reschedule",ipf); - loop->on_time(loop, OOP_TIME_NOW, tailing_rable_call_time, ipf); + //dbg("**TRACT** ipf=%p reschedule",ipf); + tailing_rable_on_time(ipf); - assert(ipf->readable_callback): + assert(ipf->readable_callback); return ipf->readable_callback(loop, &ipf->readable, ipf->readable_callback_user); } +static void tailing_rable_on_time(InputFile *ipf) { + loop->cancel_time(loop, OOP_TIME_NOW, tailing_rable_call_time, ipf); + loop->on_time(loop, OOP_TIME_NOW, tailing_rable_call_time, ipf); + /* on_time is not idempotent - it counts. So we need this to make + * sure we only have one outstanding, as otherwise our cancel doesn't work */ +} + static void tailing_on_cancel(struct oop_readable *rable) { InputFile *ipf= (void*)rable; - dbg("**TOR** ipf=%p on_cancel",ipf); + //dbg("**TOR** ipf=%p on_cancel",ipf); if (ipf->filemon) filemon_stop(ipf); - dbg("**TRACT** ipf=%p cancel",ipf); + //dbg("**TRACT** ipf=%p cancel",ipf); loop->cancel_time(loop, OOP_TIME_NOW, tailing_rable_call_time, ipf); ipf->readable_callback= 0; } void tailing_make_readable(InputFile *ipf) { - dbg("**TRACT** ipf=%p makereadable rcb=%p",ipf, - (void*)ipf?ipf->readable_callback:0); + //dbg("**TRACT** ipf=%p makereadable rcb=%p",ipf, + // (void*)ipf?ipf->readable_callback:0); if (!ipf || !ipf->readable_callback) /* so callers can be naive */ return; ipf->fake_readable= 1; - loop->on_time(loop, OOP_TIME_NOW, tailing_rable_call_time, ipf); + tailing_rable_on_time(ipf); } static int tailing_on_readable(struct oop_readable *rable, oop_readable_call *cb, void *user) { InputFile *ipf= (void*)rable; - dbg("**TOR** ipf=%p on_readable",ipf); + //dbg("**TOR** ipf=%p on_readable",ipf); tailing_on_cancel(rable); ipf->readable_callback= cb; @@ -253,7 +264,7 @@ static ssize_t tailing_try_read(struct oop_readable *rable, void *buffer, abort(); } } - dbg("**TOR** ipf=%p try_read r=%d",ipf,r); + //dbg("**TOR** ipf=%p try_read r=%d",ipf,r); return r; } } @@ -316,12 +327,12 @@ void filepoll(void) { } char *dbg_report_ipf(InputFile *ipf) { - if (!ipf) return xasprintf("none"); + if (!ipf) return masprintf("none"); const char *slash= strrchr(ipf->path,'/'); const char *path= slash ? slash+1 : ipf->path; - return xasprintf("%p/%s:queue=%d,ip=%ld,autodef=%ld,off=%ld,fd=%d%s%s%s", + return masprintf("%p/%s:queue=%d,ip=%ld,autodef=%ld,off=%ld,fd=%d%s%s%s", ipf, path, ipf->queue.count, ipf->inprogress, ipf->autodefer, (long)ipf->offset, ipf->fd,