OSSP CVS Repository

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

Check-in Number: 2939
Date: 2002-Nov-29 16:45:25 (local)
2002-Nov-29 15:45:25 (UTC)
User:mlelstv
Branch:
Comment: split input stream into even/odd lines for two readers

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

Tickets:
Inspections:
Files:
ossp-pkg/sio/Makefile      1.5 -> 1.6     3 inserted, 3 deleted
ossp-pkg/sio/sio_sillymux.c      added-> 1.1
ossp-pkg/sio/sio_test2.c      1.1 -> 1.2     55 inserted, 19 deleted

ossp-pkg/sio/Makefile 1.5 -> 1.6

--- Makefile     2002/11/29 14:28:00     1.5
+++ Makefile     2002/11/29 15:45:25     1.6
@@ -3,7 +3,7 @@
          -Wmissing-prototypes -Wmissing-declarations -Wnested-externs \
                  -Wno-unused-parameter
 
-all: al_test sio_test
+all: al_test sio_test sio_test2
 
 .c.o:
         $(CC) $(CFLAGS) -c $<
@@ -13,8 +13,8 @@
 sio_test: sio_test.o sio_sa.o sio_buffer.o sio_hello.o sio_bio.o sio.o al.o lib_sa/sa.o
         $(CC) $(CFLAGS) -o sio_test sio_test.o sio_sa.o sio_buffer.o sio_hello.o sio_bio.o sio.o al.o lib_sa/sa.o -lssl -lcrypto
 
-sio_test2: sio_test2.o sio_fd.o sio_buffer.o sio_zlib.o sio_sio.o sio.o al.o
-        $(CC) $(CFLAGS) -o sio_test2 sio_test2.o sio_fd.o sio_buffer.o sio_zlib.o sio_sio.o sio.o al.o -lz
+sio_test2: sio_test2.o sio_fd.o sio_buffer.o sio_zlib.o sio_sio.o sio_sillymux.o sio.o al.o
+        $(CC) $(CFLAGS) -o sio_test2 sio_test2.o sio_fd.o sio_buffer.o sio_zlib.o sio_sio.o sio_sillymux.o sio.o al.o -lz
 
 lib_sa/sa.o: lib_sa/sa.c
         $(CC) $(CFLAGS) -c -Ilib_sa -o lib_sa/sa.o lib_sa/sa.c


ossp-pkg/sio/sio_sillymux.c -> 1.1

*** /dev/null    Sat Apr 27 15:15:30 2024
--- -    Sat Apr 27 15:15:53 2024
***************
*** 0 ****
--- 1,185 ----
+ #include <stddef.h>
+ #include <stdlib.h>
+ #include <string.h>
+ 
+ #include "al.h"
+ #include "sio.h"
+ 
+ typedef struct {
+     al_label_t odd_label;
+     al_label_t even_label;
+     al_label_t data_label;
+     int        odd;
+     size_t     next;
+     int        found;
+ } private_t;
+ 
+ /*
+  * create stage
+  *
+  * allocate private instance data
+  */
+ static
+ sio_rc_t sillymux_init(sio_t *sio, void **up)
+ {
+     private_t *my;
+     
+     my = (private_t *)malloc(sizeof(private_t));
+     if (my == NULL)
+         return SIO_ERR_MEM;
+ 
+     my->odd_label    = NULL;
+     my->even_label   = NULL;
+ 
+     my->found        = 0;
+     my->odd          = 1;
+ 
+     sio_label(sio, SIO_LN_DATA, &my->data_label);
+ 
+     *up = my;
+ 
+     return SIO_OK;
+ }
+ 
+ /*
+  * configure stage
+  *
+  * pass two void pointers
+  */
+ static
+ sio_rc_t sillymux_configure(sio_t *sio, void *u, void *obj, void *val)
+ {
+     private_t *my = (private_t *)u;
+     const char *name = (const char *)obj;
+ 
+     if (!strcmp(name, "evenlabel")) {
+         my->even_label = (al_label_t *)val;
+     } else if (!strcmp(name, "oddlabel")) {
+         my->odd_label = (al_label_t *)val;
+     } else {
+         return SIO_ERR_ARG;
+     }
+ 
+     return SIO_OK;
+ }
+ 
+ /*
+  * destroy stage
+  */
+ static
+ sio_rc_t sillymux_cleanup(sio_t *sio, void *u)
+ {
+     private_t *my = (private_t *)u;
+ 
+     free(my);
+ 
+     return SIO_OK;
+ }
+ 
+ static
+ sio_rc_t sillymux_openr(sio_t *sio, al_t *al, void *u)
+ {
+     return SIO_OK;
+ }
+ 
+ static
+ sio_rc_t sillymux_closer(sio_t *sio, al_t *al, void *u)
+ {
+     return SIO_OK;
+ }
+ 
+ static
+ sio_rc_t sillymux_openw(sio_t *sio, al_t *al, void *u)
+ {
+     return SIO_OK;
+ }
+ 
+ static
+ sio_rc_t sillymux_closew(sio_t *sio, al_t *al, void *u)
+ {
+     return SIO_OK;
+ }
+ 
+ static
+ al_rc_t findlf(al_chunk_t *alc, void *u)
+ {
+     private_t *my = (private_t *)u;
+     const char *p, *lf;
+     size_t n;
+ 
+     n = al_chunk_len(alc);
+ 
+     if (!al_same_label(alc, my->data_label)) {
+         my->next += n;
+         return AL_OK;
+     }
+ 
+     p = al_chunk_ptr(alc,0);
+     lf = memchr(p, '\n', n);
+     if (lf) {
+         my->next += lf - p + 1;
+         my->found = 1;
+         return AL_ERR_EOF;
+     }
+ 
+     my->next += n;
+ 
+     return AL_OK;
+ }
+ 
+ static
+ sio_rc_t sillymux_input(sio_t *sio, al_t *al, void *u, sio_rc_t orc)
+ {
+     private_t *my = (private_t *)u;
+     size_t pos, n;
+ 
+     n = al_bytes(al);
+     if (n == 0)
+         return SIO_SCHED_UP;
+ 
+     for (pos=0; pos<n; pos = my->next) {
+ 
+         my->next = pos;
+         al_traverse_cb(al, pos, n-pos, AL_FORWARD, NULL, findlf, u);
+ 
+         al_setlabel(al, pos, my->next - pos,
+                     my->data_label,
+                     my->odd ? my->odd_label : my->even_label);
+ 
+         if (my->found) {
+             my->found = 0;
+             my->odd = !my->odd;
+         }
+     }
+ 
+     return SIO_SCHED_DOWN;
+ }
+ 
+ static
+ sio_rc_t sillymux_output(sio_t *sio, al_t *al, void *u, sio_rc_t orc)
+ {
+     private_t *my = (private_t *)u;
+ 
+     if (al_bytes(al) == 0)
+         return SIO_SCHED_DOWN;
+ 
+     al_setlabel(al, 0, al_bytes(al), my->odd_label, my->data_label);
+     al_setlabel(al, 0, al_bytes(al), my->even_label, my->data_label);
+ 
+     return SIO_SCHED_UP;
+ }
+ 
+ sio_module_t sio_module_sillymux = {
+     "sillymux",
+     sillymux_init,
+     sillymux_configure,
+     sillymux_cleanup,
+     sillymux_openr,
+     sillymux_closer,
+     sillymux_openw,
+     sillymux_closew,
+     sillymux_input,
+     sillymux_output,
+     NULL
+ };
+ 


ossp-pkg/sio/sio_test2.c 1.1 -> 1.2

--- sio_test2.c  2002/11/29 12:58:59     1.1
+++ sio_test2.c  2002/11/29 15:45:25     1.2
@@ -6,10 +6,15 @@
 #include "al.h"
 #include "sio.h"
 
+static char oddlabel, evenlabel;
+#define ODDLABEL  ((al_label_t)&oddlabel)
+#define EVENLABEL ((al_label_t)&evenlabel)
+
 extern sio_module_t sio_module_fd;
 extern sio_module_t sio_module_zlib;
 extern sio_module_t sio_module_buffer;
 extern sio_module_t sio_module_sio;
+extern sio_module_t sio_module_sillymux;
 
 #define e(f) rc = f; printf("%s = %s\n",#f, sio_error(rc)); fflush(stdout);
 #define s(f) src = f; printf("%s = %s\n",#f, sa_error(src)); fflush(stdout);
@@ -21,10 +26,15 @@
 
     sio_t *sio;
     sio_stage_t *sios_fd, *sios_buffer, *sios_zlib;
+    sio_stage_t *sios_sillymux;
+
+    sio_t *sio2a;
+    sio_stage_t *sios2a_sio;
 
-    sio_t *sio2;
-    sio_stage_t *sios2_sio;
-    al_label_t data_label, error_label, eof_label;
+    sio_t *sio2b;
+    sio_stage_t *sios2b_sio;
+
+    al_label_t label;
 
     char buf[513];
     size_t buflen;
@@ -49,6 +59,7 @@
     e(sio_create_stage(sio, &sio_module_fd, &sios_fd));
     e(sio_create_stage(sio, &sio_module_zlib, &sios_zlib));
     e(sio_create_stage(sio, &sio_module_buffer, &sios_buffer));
+    e(sio_create_stage(sio, &sio_module_sillymux, &sios_sillymux));
 
     e(sio_configure_stage(sio, sios_fd, "fd", &fd));
     buflen = 512;
@@ -66,46 +77,71 @@
     level = -1;
     e(sio_configure_stage(sio, sios_zlib, "inputlevel", &level));
 
-    e(sio_create(&sio2));
-    e(sio_create_stage(sio2, &sio_module_sio, &sios2_sio));
+    e(sio_configure_stage(sio, sios_sillymux, "oddlabel", ODDLABEL));
+    e(sio_configure_stage(sio, sios_sillymux, "evenlabel", EVENLABEL));
 
-    e(sio_label(sio, SIO_LN_DATA, &data_label));
-    e(sio_label(sio, SIO_LN_ERROR, &error_label));
-    e(sio_label(sio, SIO_LN_EOF, &eof_label));
-    e(sio_configure_stage(sio2, sios2_sio, "upstream", sio));
-    e(sio_configure_stage(sio2, sios2_sio, "mydatalabel", data_label));
-    e(sio_configure_stage(sio2, sios2_sio, "myerrorlabel", error_label));
-    e(sio_configure_stage(sio2, sios2_sio, "myeoflabel", eof_label));
+    e(sio_create(&sio2a));
+    e(sio_create_stage(sio2a, &sio_module_sio, &sios2a_sio));
+    e(sio_configure_stage(sio2a, sios2a_sio, "upstream", sio));
+    e(sio_configure_stage(sio2a, sios2a_sio, "mydatalabel", ODDLABEL));
+    e(sio_attach(sio2a, sios2a_sio, SIO_MODE_READWRITE));
+
+    e(sio_create(&sio2b));
+    e(sio_create_stage(sio2b, &sio_module_sio, &sios2b_sio));
+    e(sio_configure_stage(sio2b, sios2b_sio, "upstream", sio));
+    e(sio_configure_stage(sio2b, sios2b_sio, "mydatalabel", EVENLABEL));
+    e(sio_attach(sio2b, sios2b_sio, SIO_MODE_READWRITE));
 
-    e(sio_attach(sio2, sios2_sio, SIO_MODE_READWRITE));
 
     {
         e(sio_attach(sio, sios_fd, SIO_MODE_READWRITE));
         e(sio_attach(sio, sios_zlib, SIO_MODE_READWRITE));
         e(sio_attach(sio, sios_buffer, SIO_MODE_READWRITE));
+        e(sio_attach(sio, sios_sillymux, SIO_MODE_READWRITE));
 
 #ifdef WRITE
         e(sio_write(sio2, buf, strlen(buf), &actual));
         e(sio_push(sio2));
 #else
         do {
+
+            printf("READ A\n");
+            actual = 0;
+            e(sio_read(sio2a, buf, sizeof(buf), &actual));
+            printf("actual_a = %d\n",actual);
+            fwrite(buf, actual, 1, stdout);
+            printf("\n");
+
+            printf("READ B\n");
             actual = 0;
-            e(sio_read(sio2, buf, sizeof(buf), &actual));
+            e(sio_read(sio2b, buf, sizeof(buf), &actual));
+            printf("actual_b = %d\n",actual);
+            fwrite(buf, actual, 1, stdout);
+            printf("\n");
+
+            printf("READ MUX\n");
+            actual = 0;
+            e(sio_read(sio, buf, sizeof(buf), &actual));
             printf("actual = %d\n",actual);
             fwrite(buf, actual, 1, stdout);
             printf("\n");
-        } while (sio_flag(sio2, SIO_FLAG_EOF) == SIO_FALSE);
+
+        } while (sio_flag(sio, SIO_FLAG_EOF) == SIO_FALSE);
 #endif
 
+        e(sio_detach(sio, sios_sillymux));
         e(sio_detach(sio, sios_buffer));
         e(sio_detach(sio, sios_zlib));
         e(sio_detach(sio, sios_fd));
     }
 
-    e(sio_detach(sio2, sios2_sio));
-
-    e(sio_destroy_stage(sio2, sios2_sio));
-    e(sio_destroy(sio2));
+    e(sio_detach(sio2b, sios2b_sio));
+    e(sio_destroy_stage(sio2b, sios2b_sio));
+    e(sio_destroy(sio2b));
+
+    e(sio_detach(sio2a, sios2a_sio));
+    e(sio_destroy_stage(sio2a, sios2a_sio));
+    e(sio_destroy(sio2a));
 
     e(sio_destroy_stage(sio, sios_buffer));
     e(sio_destroy_stage(sio, sios_zlib));

CVSTrac 2.0.1