/* set/used by obc_... but may be read by user */
int total; /* amount buffered */
/* set/used by obc_..., oprintf, etc., only */
- int done_of_head;
+ int done_of_head; /* -1 = empty and fileevent not registered with liboop */
struct { OutBuffer *head, *tail; } obs;
};
obc_tryflush(ch);
if (evts && !ch->obs.head) {
events->cancel_fd(events, ch->fd, OOP_WRITE);
+ ch->done_of_head= -1;
if (ch->empty) ch->empty(ch);
}
return OOP_CONTINUE;
static void addlink(OutBufferChain *ch, OutBuffer *ob,
CopyCallBack *ccb, void *ccbu) {
if (ccb) ccb(ob->m,ob->l,ccbu);
- if (!ch->obs.head && events) /* in simulation, events==0 */
- events->on_fd(events, ch->fd, OOP_WRITE, writeable, ch);
+
+ if (ch->done_of_head < 0) {
+ assert(!ch->obs.head);
+ if (events) /* in simulation, events==0 */
+ events->on_fd(events, ch->fd, OOP_WRITE, writeable, ch);
+ ch->done_of_head= 0;
+ }
+
LIST_LINK_TAIL(ch->obs, ob);
ch->total += ob->l;
if (ob->l>0 && ob->m[ob->l-1]=='\n')
}
void obc_init_core(OutBufferChain *ch) {
- ch->done_of_head= 0;
+ ch->done_of_head= -1;
ch->total= 0;
if (!ch->limit) ch->limit= 128*1024;
LIST_INIT(ch->obs);