OSSP CVS Repository

ossp - Check-in [2738]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 2738
Date: 2002-Nov-05 17:53:55 (local)
2002-Nov-05 16:53:55 (UTC)
User:mlelstv
Branch:
Comment: add special state flags (error, eof) sio_read now parses assembly line for data and signalling chunks and sets flags accordingly.

PR: Submitted by: Reviewed by: Approved by: Obtained from:

Tickets:
Inspections:
Files:
ossp-pkg/sio/sio.c      1.7 -> 1.8     70 inserted, 6 deleted

ossp-pkg/sio/sio.c 1.7 -> 1.8

--- sio.c        2002/11/05 16:12:39     1.7
+++ sio.c        2002/11/05 16:53:55     1.8
@@ -30,6 +30,7 @@
 
 #include <stddef.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "al.h"
 #include "sio.h"
@@ -73,9 +74,12 @@
         LIST(sio_halfduplex_t)  hd;
         al_t                   *al;
     } writers;
-    sio_labelnum_t             label_data;
-    sio_labelnum_t             label_error;
-    sio_labelnum_t             label_eof;
+    sio_labelnum_t              label_data;
+    sio_labelnum_t              label_error;
+    sio_labelnum_t              label_eof;
+    int                         eof_flag;
+    int                         error_flag;
+    char                       *dst;
 };
 #define SIO_LABEL_DATA(sio)  ((al_label_t)&(sio)->label_data)
 #define SIO_LABEL_ERROR(sio) ((al_label_t)&(sio)->label_error)
@@ -484,6 +488,24 @@
     return SIO_RC(rc);
 }
 
+al_rc_t sio_readchunk(al_chunk_t *alc, void *u)
+{
+    sio_t *sio = (sio_t *)u;
+    size_t len;
+
+    if (al_same_label(alc, SIO_LABEL_DATA(sio))) {
+        len = al_chunk_len(alc);
+        memcpy(sio->dst, al_chunk_ptr(alc,0), len);
+        sio->dst += len;
+    } else if (al_same_label(alc, SIO_LABEL_ERROR(sio))) {
+        sio->error_flag = 1;
+    } else if (al_same_label(alc, SIO_LABEL_EOF(sio))) {
+        sio->eof_flag = 1;
+    }
+
+    return AL_OK;
+}
+
 sio_rc_t sio_read(sio_t *sio, char *dst, size_t n, size_t *actualp)
 {
     al_rc_t arc;
@@ -497,9 +519,11 @@
     if (arc != AL_OK) return SIO_RC(SIO_ERR_INT);
 
     rc = sio_input(sio, al, n);
-    if (rc == SIO_OK)
-        arc = al_flatten(al, 0, n, AL_FORWARD_SPAN, SIO_LABEL_DATA(sio),
-                         dst, actualp);
+    if (rc == SIO_OK) {
+        sio->dst = dst;
+        al_traverse_cb(al, 0, n, AL_FORWARD, NULL, sio_readchunk, (void*)sio);
+        *actualp = sio->dst - dst;
+    }
 
     arc = al_destroy(al);
     if (arc != AL_OK) return SIO_RC(SIO_ERR_INT);
@@ -531,6 +555,46 @@
     return SIO_RC(rc);
 }
 
+int sio_flag(sio_t *sio, sio_flag_t fl)
+{
+    int rc;
+
+    switch (fl) {
+    case SIO_FLAG_ERROR:
+        rc = sio->error_flag;
+        break;
+    case SIO_FLAG_EOF:
+        rc = sio->eof_flag;
+        break;
+    default:
+        rc = 0;
+        break;
+    }
+
+    return rc;
+}
+
+int sio_clearflag(sio_t *sio, sio_flag_t fl)
+{
+    int rc;
+
+    switch (fl) {
+    case SIO_FLAG_ERROR:
+        rc = sio->error_flag;
+        sio->error_flag = 0;
+        break;
+    case SIO_FLAG_EOF:
+        rc = sio->eof_flag;
+        sio->eof_flag = 0;
+        break;
+    default:
+        rc = 0;
+        break;
+    }
+
+    return rc;
+}
+
 const char *sio_error(sio_rc_t rc)
 {
     const char *mess;

CVSTrac 2.0.1