OSSP CVS Repository

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

ossp-pkg/l2/l2_ch_buffer.c 1.14 -> 1.15

--- l2_ch_buffer.c       2001/09/05 07:47:12     1.14
+++ l2_ch_buffer.c       2001/09/06 11:47:51     1.15
@@ -107,13 +107,25 @@
 static l2_result_t hook_write(l2_context_t *ctx, l2_channel_t *ch, 
                       const char *buf, size_t bufsize)
 {
+    l2_channel_t *downstream = l2_channel_downstream(ch);
     l2_ch_buffer_t *cfg;
+    l2_result_t rv;
 
     /* parameter checks */
     if ((cfg = (l2_ch_buffer_t *)ctx->vp) == NULL)
         return L2_ERROR;
-    if (bufsize > (cfg->bufsize - cfg->bufpos))
-        return L2_ERROR; /* The buffer is too small */
+
+    if (bufsize > (cfg->bufsize - cfg->bufpos)) {
+        /* flush buffer if necessary */
+        if (cfg->bufpos > 0) {
+            if ((rv = l2_channel_write(downstream, cfg->buf, cfg->bufpos)) != L2_OK)
+                return rv;
+            cfg->bufpos = 0;
+        }
+        /* pass through immediately to downstream if still too large */
+        if (bufsize > cfg->bufsize)
+            return l2_channel_write(downstream, buf, bufsize);
+    }
 
     /* write message to channel buffer */
     memcpy(cfg->buf+cfg->bufpos, buf, bufsize);

CVSTrac 2.0.1