OSSP CVS Repository

ossp - Difference in ossp-pkg/l2/l2_ch_buffer.c versions 1.19 and 1.20
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/l2/l2_ch_buffer.c 1.19 -> 1.20

--- l2_ch_buffer.c       2001/09/12 09:39:16     1.19
+++ l2_ch_buffer.c       2001/09/12 16:07:23     1.20
@@ -33,9 +33,10 @@
 
 /* declare private channel configuration */
 typedef struct {
-    char  *buf;
-    int    bufpos;
-    int    bufsize;
+    char        *buf;
+    int         bufpos;
+    int         bufsize;
+    l2_level_t  level;
 } l2_ch_buffer_t;
 
 /* create channel */
@@ -51,6 +52,7 @@
     cfg->buf     = NULL;
     cfg->bufpos  = 0;
     cfg->bufsize = 4096;
+    cfg->level   = L2_LEVEL_NONE;
 
     /* link private channel configuration into channel context */
     ctx->vp = cfg;
@@ -107,16 +109,26 @@
     if (buf_size > (cfg->bufsize - cfg->bufpos)) {
         /* flush buffer if necessary */
         if (cfg->bufpos > 0) {
-            if ((rv = l2_channel_write(downstream, level, cfg->buf, cfg->bufpos)) != L2_OK)
+            if ((rv = l2_channel_write(downstream, cfg->level, cfg->buf, cfg->bufpos)) != L2_OK)
                 return rv;
             cfg->bufpos = 0;
+            cfg->level  = L2_LEVEL_NONE; /* reset this->context->level */
         }
         /* pass through immediately to downstream if still too large */
         if (buf_size > cfg->bufsize)
             return l2_channel_write(downstream, level, buf, buf_size);
     }
 
-    /* write message to channel buffer */
+    /* flush if incoming message level differs from those already in buffer */
+    if ((level != cfg->level) && (cfg->level == L2_LEVEL_NONE))
+    {
+        if ((rv = l2_channel_write(downstream, cfg->level, cfg->buf, cfg->bufpos)) != L2_OK)
+            return rv;
+        cfg->bufpos = 0;
+        cfg->level  = level;
+    }
+
+    /* finally write incoming message to channel buffer */
     memcpy(cfg->buf+cfg->bufpos, buf, buf_size);
     cfg->bufpos += buf_size;
 
@@ -131,10 +143,11 @@
     l2_result_t rv;
 
     /* write the buffer contents downstream */
-    if (cfg->bufpos > 0) {                    /* !---------! */
-        if ((rv = l2_channel_write(downstream, L2_LEVEL_PANIC, cfg->buf, cfg->bufpos)) != L2_OK)
-            return rv;                        /* !! FIXME !! */
-        cfg->bufpos = 0;                      /* !---------! */
+    if (cfg->bufpos > 0) {
+        if ((rv = l2_channel_write(downstream, cfg->level, cfg->buf, cfg->bufpos)) != L2_OK)
+            return rv;
+        cfg->bufpos = 0;
+        cfg->level  = L2_LEVEL_NONE; /* reset this->context->level */
     }
 
     /* optionally flush downstream channel, too */
@@ -152,10 +165,11 @@
     l2_result_t rv;
 
     /* write pending data before closing down */
-    if (cfg->bufpos > 0) {                    /* !---------! */
-        if ((rv = l2_channel_write(downstream, L2_LEVEL_PANIC, cfg->buf, cfg->bufpos)) != L2_OK)
-            return rv;                        /* !! FIXME !! */
-        cfg->bufpos = 0;                      /* !---------! */
+    if (cfg->bufpos > 0) {
+        if ((rv = l2_channel_write(downstream, cfg->level, cfg->buf, cfg->bufpos)) != L2_OK)
+            return rv;
+        cfg->bufpos = 0;
+        cfg->level  = L2_LEVEL_NONE; /* reset this->context->level */
     }
 
     /* optionally close downstream channel, too */

CVSTrac 2.0.1