OSSP CVS Repository

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

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

--- l2_ch_buffer.c       2001/09/12 16:07:23     1.20
+++ l2_ch_buffer.c       2001/09/14 07:41:49     1.21
@@ -33,9 +33,10 @@
 
 /* declare private channel configuration */
 typedef struct {
-    char        *buf;
+    char       *buf;
     int         bufpos;
     int         bufsize;
+    int         levelflush;
     l2_level_t  level;
 } l2_ch_buffer_t;
 
@@ -49,10 +50,11 @@
         return L2_ERR_MEM;
 
     /* initialize configuration with reasonable defaults */
-    cfg->buf     = NULL;
-    cfg->bufpos  = 0;
-    cfg->bufsize = 4096;
-    cfg->level   = L2_LEVEL_NONE;
+    cfg->buf        = NULL;
+    cfg->bufpos     = 0;
+    cfg->bufsize    = 4096;
+    cfg->levelflush = 0;
+    cfg->level      = L2_LEVEL_NONE;
 
     /* link private channel configuration into channel context */
     ctx->vp = cfg;
@@ -64,12 +66,13 @@
 static l2_result_t hook_configure(l2_context_t *ctx, l2_channel_t *ch, const char *fmt, va_list ap)
 {
     l2_ch_buffer_t *cfg = (l2_ch_buffer_t *)ctx->vp;
-    l2_param_t pa[2];
+    l2_param_t pa[3];
     l2_result_t rv;
 
     /* feed and call generic parameter parsing engine */
-    L2_PARAM_SET(pa[0], size, INT, &cfg->bufsize);
-    L2_PARAM_END(pa[1]);
+    L2_PARAM_SET(pa[0], size,       INT, &cfg->bufsize);
+    L2_PARAM_SET(pa[1], levelflush, INT, &cfg->levelflush);
+    L2_PARAM_END(pa[2]);
     rv = l2_util_setparams(pa, fmt, ap);
     if (cfg->bufsize < 0) 
         return L2_ERR_ARG;
@@ -112,25 +115,28 @@
             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 */
+            cfg->level  = L2_LEVEL_NONE;
         }
         /* pass through immediately to downstream if still too large */
         if (buf_size > cfg->bufsize)
             return l2_channel_write(downstream, level, buf, buf_size);
     }
 
-    /* flush if incoming message level differs from those already in buffer */
-    if ((level != cfg->level) && (cfg->level == L2_LEVEL_NONE))
-    {
+    /* flush if level of incoming message differs from those already in buffer */
+    if (   (cfg->levelflush)             /* if different levels force a flush    */
+        && (cfg->bufpos > 0)             /* and there is something in the buffer */
+        && (cfg->level != L2_LEVEL_NONE) /* and a remembered level is known      */
+        && (level != cfg->level)         /* and the levels really differ         */) {
         if ((rv = l2_channel_write(downstream, cfg->level, cfg->buf, cfg->bufpos)) != L2_OK)
             return rv;
         cfg->bufpos = 0;
-        cfg->level  = level;
+        cfg->level  = L2_LEVEL_NONE;
     }
 
     /* finally write incoming message to channel buffer */
     memcpy(cfg->buf+cfg->bufpos, buf, buf_size);
     cfg->bufpos += buf_size;
+    cfg->level = level;
 
     return L2_OK;
 }

CVSTrac 2.0.1