From: ian Date: Tue, 15 Jul 2008 20:17:07 +0000 (+0000) Subject: new OutBufferChain->empty feature X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=4f814c0402468fecf0792b139c1d0cbdee7eb980;p=trains.git new OutBufferChain->empty feature --- diff --git a/hostside/daemons.h b/hostside/daemons.h index c103cdb..9d1ae87 100644 --- a/hostside/daemons.h +++ b/hostside/daemons.h @@ -21,6 +21,7 @@ typedef struct OutBufferChain OutBufferChain; typedef void OutBufferError(OutBufferChain*, const char *e1, const char *e2 /* on error: both e1 and e2 non-0. say `$e1: $e2' * on eof: both e1 and e2 =0. */); +typedef void OutBufferEmpty(OutBufferChain*); typedef void CopyCallBack(char *m, size_t l, void *u); @@ -30,6 +31,7 @@ struct OutBufferChain { int fd; int limit; /* 0 means obc_init will set a default */ OutBufferError *error; + OutBufferEmpty *empty; /* may be 0 */ /* set/used by obc_..., oprintf, etc., only */ int done_of_head, total; struct { OutBuffer *head, *tail; } obs; diff --git a/hostside/obc.c b/hostside/obc.c index deedb72..2a04ce9 100644 --- a/hostside/obc.c +++ b/hostside/obc.c @@ -24,11 +24,8 @@ int obc_tryflush(OutBufferChain *ch) { for (;;) { ob= ch->obs.head; - if (!ob) { - if (events) - events->cancel_fd(events, ch->fd, OOP_WRITE); + if (!ob) return 0; - } if (ch->done_of_head == ob->l) { LIST_UNLINK(ch->obs, ob); free(ob->m); @@ -56,6 +53,10 @@ static void *writeable(oop_source *evts, int fd, assert(fd == ch->fd); assert(evt == OOP_WRITE); obc_tryflush(ch); + if (evts && !ch->obs.head) { + events->cancel_fd(events, ch->fd, OOP_WRITE); + if (ch->empty) ch->empty(ch); + } return OOP_CONTINUE; }