OSSP CVS Repository

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

ossp-pkg/l2/l2_ch_buffer.c 1.16 -> 1.17

--- l2_ch_buffer.c       2001/09/06 14:37:53     1.16
+++ l2_ch_buffer.c       2001/09/06 16:10:05     1.17
@@ -61,34 +61,27 @@
 /* configure channel */
 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 *cfg = (l2_ch_buffer_t *)ctx->vp;
     l2_param_t pa[2];
     l2_result_t rv;
 
-    /* parameter checks */
-    if ((cfg = (l2_ch_buffer_t *)ctx->vp) == NULL)
-        return L2_ERR_ARG;
-
     /* feed and call generic parameter parsing engine */
     L2_PARAM_SET(pa[0], size, INT, &cfg->bufsize);
     L2_PARAM_END(pa[1]);
     rv = l2_util_setparams(pa, fmt, ap);
     if (cfg->bufsize < 0) 
         return L2_ERR_ARG;
+
     return rv;
 }
 
 /* open channel */
 static l2_result_t hook_open(l2_context_t *ctx, l2_channel_t *ch)
 {
-    l2_ch_buffer_t *cfg;
-    l2_channel_t *downstream;
+    l2_ch_buffer_t *cfg = (l2_ch_buffer_t *)ctx->vp;
+    l2_channel_t *downstream = l2_channel_downstream(ch);
     l2_result_t rv;
 
-    /* parameter checks */
-    if ((cfg = (l2_ch_buffer_t *)ctx->vp) == NULL)
-        return L2_ERR_ARG;
-
     /* open channel buffer */
     if (cfg->bufsize > 0) {
         if ((cfg->buf = malloc(cfg->bufsize)) == NULL)
@@ -97,9 +90,8 @@
     }
 
     /* optionally open downstream channel, too */
-    if ((downstream = l2_channel_downstream(ch)) != NULL)
-        if ((rv = l2_channel_open(downstream)) != L2_OK)
-            return rv;
+    if ((rv = l2_channel_open(downstream)) != L2_OK)
+        return rv;
 
     return L2_OK;
 }
@@ -108,14 +100,10 @@
 static l2_result_t hook_write(l2_context_t *ctx, l2_channel_t *ch, 
                       const char *buf, size_t bufsize)
 {
+    l2_ch_buffer_t *cfg = (l2_ch_buffer_t *)ctx->vp;
     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_ERR_ARG;
-
     if (bufsize > (cfg->bufsize - cfg->bufpos)) {
         /* flush buffer if necessary */
         if (cfg->bufpos > 0) {
@@ -138,26 +126,20 @@
 /* flush channel */
 static l2_result_t hook_flush(l2_context_t *ctx, l2_channel_t *ch)
 {
-    l2_ch_buffer_t *cfg;
-    l2_channel_t *downstream;
+    l2_ch_buffer_t *cfg = (l2_ch_buffer_t *)ctx->vp;
+    l2_channel_t *downstream = l2_channel_downstream(ch);
     l2_result_t rv;
 
-    /* parameter checks */
-    if ((cfg = (l2_ch_buffer_t *)ctx->vp) == NULL)
-        return L2_ERR_ARG;
-
     /* write the buffer contents downstream */
     if (cfg->bufpos > 0) {
-        if ((downstream = l2_channel_downstream(ch)) != NULL)
-            if ((rv = l2_channel_write(downstream, cfg->buf, cfg->bufpos)) != L2_OK)
-                return rv;
+        if ((rv = l2_channel_write(downstream, cfg->buf, cfg->bufpos)) != L2_OK)
+            return rv;
         cfg->bufpos = 0;
     }
 
     /* optionally flush downstream channel, too */
-    if ((downstream = l2_channel_downstream(ch)) != NULL)
-        if ((rv = l2_channel_flush(downstream)) != L2_OK)
-            return rv;
+    if ((rv = l2_channel_flush(downstream)) != L2_OK)
+        return rv;
 
     return L2_OK;
 }
@@ -165,26 +147,20 @@
 /* close channel */
 static l2_result_t hook_close(l2_context_t *ctx, l2_channel_t *ch)
 {
-    l2_ch_buffer_t *cfg;
-    l2_channel_t *downstream;
+    l2_ch_buffer_t *cfg = (l2_ch_buffer_t *)ctx->vp;
+    l2_channel_t *downstream = l2_channel_downstream(ch);
     l2_result_t rv;
 
-    /* parameter checks */
-    if ((cfg = (l2_ch_buffer_t *)ctx->vp) == NULL)
-        return L2_ERR_ARG;
-
-    /* write stale data before closing down */
+    /* write pending data before closing down */
     if (cfg->bufpos > 0) {
-        if ((downstream = l2_channel_downstream(ch)) != NULL)
-            if ((rv = l2_channel_write(downstream, cfg->buf, cfg->bufpos)) != L2_OK)
-                return rv;
+        if ((rv = l2_channel_write(downstream, cfg->buf, cfg->bufpos)) != L2_OK)
+            return rv;
         cfg->bufpos = 0;
     }
 
     /* optionally close downstream channel, too */
-    if ((downstream = l2_channel_downstream(ch)) != NULL)
-        if ((rv = l2_channel_close(downstream)) != L2_OK)
-            return rv;
+    if ((rv = l2_channel_close(downstream)) != L2_OK)
+        return rv;
 
     /* close channel buffer */
     if (cfg->buf != NULL) {
@@ -198,11 +174,7 @@
 /* destroy channel */
 static l2_result_t hook_destroy(l2_context_t *ctx, l2_channel_t *ch)
 {
-    l2_ch_buffer_t *cfg;
-
-    /* parameter checks */
-    if ((cfg = (l2_ch_buffer_t *)ctx->vp) == NULL)
-        return L2_ERR_ARG;
+    l2_ch_buffer_t *cfg = (l2_ch_buffer_t *)ctx->vp;
 
     /* if not already closed, close channel buffer now */
     if (cfg->buf != NULL) {

CVSTrac 2.0.1