Check-in Number:
|
870 | |
Date: |
2001-Sep-06 13:47:51 (local)
2001-Sep-06 11:47:51 (UTC) |
User: | rse |
Branch: | |
Comment: |
Fix buffer channel: in case the buffer is full, the "write" operation
has to flush it instead of complaining, of course. |
Tickets: |
|
Inspections: |
|
Files: |
|
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);
|
|