chiark / gitweb /
wip obc buffering transparency debugging
authorian <ian>
Tue, 15 Jul 2008 22:40:01 +0000 (22:40 +0000)
committerian <ian>
Tue, 15 Jul 2008 22:40:01 +0000 (22:40 +0000)
testing with
-bessar:hostside> ./realtime -v2 shinkansen.speeds.record santafe.speeds.record homes.record

hostside/daemons.h
hostside/obc.c

index ade54c4139e61e810ea646f1bea06d2bca1c079a..1c1fa0f4d526e19c928b1f1a0375843449c67d4a 100644 (file)
@@ -35,7 +35,7 @@ struct OutBufferChain {
   /* 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;
 };
 
index 2a04ce9ce1c6f75ab13ed3878c7f467520457a8a..25f02ad9f015b1a247cf3e7340e6409044996955 100644 (file)
@@ -55,6 +55,7 @@ static void *writeable(oop_source *evts, int fd,
   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;
@@ -63,8 +64,14 @@ static void *writeable(oop_source *evts, int fd,
 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')
@@ -79,7 +86,7 @@ static void addlink(OutBufferChain *ch, OutBuffer *ob,
 }
 
 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);