--- l2_ch_buffer.c 2001/10/31 16:47:05 1.30
+++ l2_ch_buffer.c 2001/11/03 22:51:36 1.31
@@ -180,9 +180,7 @@
static l2_result_t hook_open(l2_context_t *ctx, l2_channel_t *ch)
{
l2_ch_buffer_t *cfg = (l2_ch_buffer_t *)ctx->vp;
- l2_channel_t *downstream = l2_channel_downstream(ch);
struct sigaction locact;
- l2_result_t rv;
if ((cfg->bufinterval != 0) && (cfg->bufinterval != -1L)) {
/* initialize auto vars before using them */
@@ -208,11 +206,7 @@
cfg->bufpos = 0;
}
- /* optionally open downstream channel, too */
- if ((rv = l2_channel_open(downstream)) != L2_OK)
- return rv;
-
- return L2_OK;
+ return L2_OK_PASS;
}
/* write to channel */
@@ -220,20 +214,27 @@
l2_level_t level, const char *buf, size_t buf_size)
{
l2_ch_buffer_t *cfg = (l2_ch_buffer_t *)ctx->vp;
- l2_channel_t *downstream = l2_channel_downstream(ch);
+ l2_channel_t *downstream;
l2_result_t rv;
if (buf_size > (cfg->bufsize - cfg->bufpos)) {
/* flush buffer if necessary */
if (cfg->bufpos > 0) {
- if ((rv = l2_channel_write(downstream, cfg->level, cfg->buf, cfg->bufpos)) != L2_OK)
- return rv;
+ downstream = NULL;
+ while ((rv = l2_channel_downstream(ch, &downstream)) == 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;
}
/* pass through immediately to downstream if still too large */
- if (buf_size > cfg->bufsize)
- return l2_channel_write(downstream, level, buf, buf_size);
+ if (buf_size > cfg->bufsize) {
+ downstream = NULL;
+ while ((rv = l2_channel_downstream(ch, &downstream)) == L2_OK)
+ if ((rv = l2_channel_write(downstream, level, buf, buf_size)) != L2_OK)
+ return rv;
+ return L2_OK;
+ }
}
/* flush if level of incoming message differs from those already in buffer */
@@ -241,8 +242,10 @@
&& (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;
+ downstream = NULL;
+ while (l2_channel_downstream(ch, &downstream) == 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;
}
@@ -259,14 +262,16 @@
static l2_result_t hook_flush(l2_context_t *ctx, l2_channel_t *ch)
{
l2_ch_buffer_t *cfg = (l2_ch_buffer_t *)ctx->vp;
- l2_channel_t *downstream = l2_channel_downstream(ch);
+ l2_channel_t *downstream;
l2_result_t rv;
/* write the buffer contents downstream */
TRACE("l2_ch_buffer hook_flush called\n");
if (cfg->bufpos > 0) {
- if ((rv = l2_channel_write(downstream, cfg->level, cfg->buf, cfg->bufpos)) != L2_OK)
- return rv;
+ downstream = NULL;
+ while (l2_channel_downstream(ch, &downstream) == 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 */
}
@@ -276,18 +281,14 @@
if (reset_alarm(cfg))
return L2_ERR_SYS;
- /* optionally flush downstream channel, too */
- if ((rv = l2_channel_flush(downstream)) != L2_OK)
- return rv;
-
- return L2_OK;
+ return L2_OK_PASS;
}
/* close channel */
static l2_result_t hook_close(l2_context_t *ctx, l2_channel_t *ch)
{
l2_ch_buffer_t *cfg = (l2_ch_buffer_t *)ctx->vp;
- l2_channel_t *downstream = l2_channel_downstream(ch);
+ l2_channel_t *downstream;
l2_result_t rv;
if ((cfg->bufinterval != 0) && (cfg->bufinterval != -1L)) {
@@ -305,46 +306,34 @@
/* write pending data before closing down */
if (cfg->bufpos > 0) {
- if ((rv = l2_channel_write(downstream, cfg->level, cfg->buf, cfg->bufpos)) != L2_OK)
- return rv;
+ downstream = NULL;
+ while (l2_channel_downstream(ch, &downstream) == 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 */
}
- /* optionally close downstream channel, too */
- if ((rv = l2_channel_close(downstream)) != L2_OK)
- return rv;
-
/* close channel buffer */
if (cfg->buf != NULL) {
free(cfg->buf);
cfg->buf = NULL;
}
- return L2_OK;
+ return L2_OK_PASS;
}
/* destroy channel */
static l2_result_t hook_destroy(l2_context_t *ctx, l2_channel_t *ch)
{
l2_ch_buffer_t *cfg = (l2_ch_buffer_t *)ctx->vp;
- l2_channel_t *downstream = l2_channel_downstream(ch);
- l2_result_t rv;
-
- /* if not already closed, close channel buffer now */
- if (cfg->buf != NULL) {
- free(cfg->buf);
- cfg->buf = NULL;
- }
/* destroy channel configuration */
+ if (cfg->buf != NULL)
+ free(cfg->buf);
free(cfg);
- /* optionally destroy downstream channel, too */
- if ((rv = l2_channel_destroy(downstream)) != L2_OK)
- return rv;
-
- return L2_OK;
+ return L2_OK_PASS;
}
/* exported channel handler structure */
|