OSSP CVS Repository

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

Check-in Number: 2877
Date: 2002-Nov-24 20:36:48 (local)
2002-Nov-24 19:36:48 (UTC)
User:mlelstv
Branch:
Comment: add optional shutdown function to modules. On detach, it is called and if returning SIO_OK another round through output and input is done. modules are now pushed at pipe head instead of appended so that a module can do upstream I/O while being wound up.

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

Tickets:
Inspections:
Files:
ossp-pkg/sio/sio.c      1.12 -> 1.13     30 inserted, 9 deleted
ossp-pkg/sio/sio.h      1.6 -> 1.7     1 inserted, 0 deleted
ossp-pkg/sio/sio_buffer.c      1.4 -> 1.5     2 inserted, 1 deleted
ossp-pkg/sio/sio_fd.c      1.8 -> 1.9     2 inserted, 1 deleted
ossp-pkg/sio/sio_hello.c      1.8 -> 1.9     2 inserted, 1 deleted
ossp-pkg/sio/sio_hole.c      1.4 -> 1.5     2 inserted, 1 deleted
ossp-pkg/sio/sio_null.c      1.5 -> 1.6     8 inserted, 1 deleted
ossp-pkg/sio/sio_sa.c      1.3 -> 1.4     2 inserted, 1 deleted
ossp-pkg/sio/sio_test.c      1.4 -> 1.5     51 inserted, 13 deleted

ossp-pkg/sio/sio.c 1.12 -> 1.13

--- sio.c        2002/11/14 15:56:10     1.12
+++ sio.c        2002/11/24 19:36:48     1.13
@@ -381,6 +381,9 @@
 /*
  * attach a stage to the read and/or write side of the pipe
  *
+ * the stage is attached to the head of the pipe, you
+ * have to create your pipes "backwards".
+ *
  * prepare assembly lines
  *
  * stages that are reader and writer get a pointer to the
@@ -423,7 +426,7 @@
             sio_destroy_al(sio, rw);
             return SIO_RC(rc);
         }
-        ADDTAIL(&sio->readers,hd,&sios->reader);
+        ADDHEAD(&sio->readers,hd,&sios->reader);
         freereader = 1;
     }
     if (rw == SIO_MODE_WRITE || rw == SIO_MODE_READWRITE) {
@@ -436,7 +439,7 @@
             sio_destroy_al(sio, rw);
             return SIO_RC(rc);
         }
-        ADDTAIL(&sio->writers,hd,&sios->writer);
+        ADDHEAD(&sio->writers,hd,&sios->writer);
     }
 
     if (rw == SIO_MODE_READWRITE) {
@@ -462,7 +465,7 @@
  */
 sio_rc_t sio_detach(sio_t *sio, sio_stage_t *sios)
 {
-    sio_rc_t rc;
+    sio_rc_t rc, rc2;
 
     /* argument sanity check(s) */
     if (sio == NULL || sios == NULL)
@@ -477,20 +480,38 @@
         return SIO_RC(SIO_ERR_ARG);
     }
 
-    rc = SIO_OK;
+    rc  = SIO_OK;
+    rc2 = SIO_OK;
+
+    if (sios->module->shutdown != NULL &&
+        sios->module->shutdown(sio, sios->userdata) == SIO_OK) {
+
+        if (sios->rw == SIO_MODE_WRITE || sios->rw == SIO_MODE_READWRITE) {
+printf("final output\n");
+            rc = sio_strategy(sio, HEAD(&sio->writers,hd));
+            if (rc != SIO_OK) return SIO_RC(rc);
+        }
+        if (sios->rw == SIO_MODE_READ || sios->rw == SIO_MODE_READWRITE) {
+printf("final input\n");
+            sio_strategy(sio, HEAD(&sio->readers,hd));
+            if (rc != SIO_OK) return SIO_RC(rc);
+        }
+
+    }
+
     if (sios->rw == SIO_MODE_WRITE || sios->rw == SIO_MODE_READWRITE) {
         REMOVE(&sio->writers,hd,&sios->writer);
         rc = sios->module->closew(sio, sio->writers.al, sios->userdata);
     }
     if (sios->rw == SIO_MODE_READ || sios->rw == SIO_MODE_READWRITE) {
         REMOVE(&sio->readers,hd,&sios->reader);
-        if (rc == SIO_OK)
-            rc = sios->module->closer(sio, sio->readers.al, sios->userdata);
-        else
-            /* XXX - double error handling ? */
-            sios->module->closer(sio, sio->readers.al, sios->userdata);
+        rc2 = sios->module->closer(sio, sio->readers.al, sios->userdata);
     }
 
+    /* XXX double error handling ? */
+    if (rc == SIO_OK)
+        rc = rc2;
+
     if (sios->rw == SIO_MODE_READWRITE) {
         sios->reader.cross = NULL;
         sios->writer.cross = NULL;


ossp-pkg/sio/sio.h 1.6 -> 1.7

--- sio.h        2002/11/14 15:56:10     1.6
+++ sio.h        2002/11/24 19:36:48     1.7
@@ -106,6 +106,7 @@
     sio_rc_t (*closew)    (sio_t *, al_t *, void *);
     sio_rc_t (*input)     (sio_t *, al_t *, void *);
     sio_rc_t (*output)    (sio_t *, al_t *, void *);
+    sio_rc_t (*shutdown)  (sio_t *, void *);
 };
 
 typedef enum {


ossp-pkg/sio/sio_buffer.c 1.4 -> 1.5

--- sio_buffer.c 2002/11/14 15:56:10     1.4
+++ sio_buffer.c 2002/11/24 19:36:48     1.5
@@ -206,6 +206,7 @@
     buffer_openw,
     buffer_closew,
     buffer_input,
-    buffer_output
+    buffer_output,
+    NULL
 };
 


ossp-pkg/sio/sio_fd.c 1.8 -> 1.9

--- sio_fd.c     2002/11/19 15:30:51     1.8
+++ sio_fd.c     2002/11/24 19:36:48     1.9
@@ -204,7 +204,8 @@
     fd_openw,
     fd_closew,
     fd_input,
-    fd_output
+    fd_output,
+    NULL
 };
 
 


ossp-pkg/sio/sio_hello.c 1.8 -> 1.9

--- sio_hello.c  2002/11/19 22:20:52     1.8
+++ sio_hello.c  2002/11/24 19:36:48     1.9
@@ -412,6 +412,7 @@
     hello_openw,
     hello_closew,
     hello_input,
-    hello_output
+    hello_output,
+    NULL
 };
 


ossp-pkg/sio/sio_hole.c 1.4 -> 1.5

--- sio_hole.c   2002/11/14 15:56:10     1.4
+++ sio_hole.c   2002/11/24 19:36:48     1.5
@@ -103,6 +103,7 @@
     hole_openw,
     hole_closew,
     hole_input,
-    hole_output
+    hole_output,
+    NULL
 };
 


ossp-pkg/sio/sio_null.c 1.5 -> 1.6

--- sio_null.c   2002/11/14 15:56:10     1.5
+++ sio_null.c   2002/11/24 19:36:48     1.6
@@ -97,6 +97,12 @@
     return SIO_OK;
 }
 
+static
+sio_rc_t null_shutdown(sio_t *sio, al_t *al, void *u)
+{
+    return SIO_OK;
+}
+
 sio_module_t sio_module_null = {
     "null",
     null_init,
@@ -107,6 +113,7 @@
     null_openw,
     null_closew,
     null_input,
-    null_output
+    null_output,
+    null_shutdown
 };
 


ossp-pkg/sio/sio_sa.c 1.3 -> 1.4

--- sio_sa.c     2002/11/14 15:56:10     1.3
+++ sio_sa.c     2002/11/24 19:36:48     1.4
@@ -217,7 +217,8 @@
     saw_openw,
     saw_closew,
     saw_input,
-    saw_output
+    saw_output,
+    NULL
 };
 
 


ossp-pkg/sio/sio_test.c 1.4 -> 1.5

--- sio_test.c   2002/11/19 22:30:07     1.4
+++ sio_test.c   2002/11/24 19:36:48     1.5
@@ -11,6 +11,9 @@
 extern sio_module_t sio_module_bio;
 extern sio_module_t sio_module_hello;
 extern sio_module_t sio_module_buffer;
+#ifndef SINK
+extern sio_module_t sio_module_sa;
+#endif
 
 #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);
@@ -23,6 +26,9 @@
     void *rp;
     sio_rc_t rc;
     sio_t *sio;
+#ifndef SINK
+    sio_stage_t *sios_sa;
+#endif
     sio_stage_t *sios_bio, *sios_hello, *sios_buffer;
 
     sa_rc_t src;
@@ -32,12 +38,17 @@
 
     int fd;
     SSL_CTX *ctx;
-    BIO *bio, *sbio;
+#ifdef SINK
+    BIO *bio;
+#endif
+    BIO *sbio;
 
     char buf[] = "Hello world\n";
 
     size_t actual;
     size_t buflen;
+    int no  = 0;
+    int yes = 1;
 
     s(sa_create(&msa));
     s(sa_option(msa, SA_OPTION_REUSEADDR, 1));
@@ -49,16 +60,22 @@
     s(sa_addr_destroy(saa));
     uri = NULL;
 
+    ERR_load_BIO_strings();
     OpenSSL_add_ssl_algorithms();
     ctx = SSL_CTX_new(SSLv23_server_method());
 
-    SSL_CTX_use_certificate_file(ctx, "/u/mlelstv/ssl/server.crt", SSL_FILETYPE_PEM);
-    SSL_CTX_use_PrivateKey_file(ctx, "/u/mlelstv/ssl/server.key", SSL_FILETYPE_PEM);
+    if (!SSL_CTX_use_certificate_file(ctx, "/u/mlelstv/ssl/server.crt", SSL_FILETYPE_PEM))
+        exit(98);
+    if (!SSL_CTX_use_PrivateKey_file(ctx, "/u/mlelstv/ssl/server.key", SSL_FILETYPE_PEM))
+        exit(99);
 
     e(sio_create(&sio));
-    e(sio_create_stage(sio, &sio_module_bio, &sios_bio));
-    e(sio_create_stage(sio, &sio_module_hello, &sios_hello));
+    e(sio_create_stage(sio, &sio_module_bio,    &sios_bio));
+    e(sio_create_stage(sio, &sio_module_hello,  &sios_hello));
     e(sio_create_stage(sio, &sio_module_buffer, &sios_buffer));
+#ifndef SINK
+    e(sio_create_stage(sio, &sio_module_sa,     &sios_sa));
+#endif
 
     buflen = 256;
     e(sio_configure_stage(sio, sios_bio, "inputsize", &buflen));
@@ -75,33 +92,54 @@
         printf("Connection from %s\n",uri);
         s(sa_addr_destroy(saa));
 
+        p(sbio = BIO_new_ssl(ctx,0));
+        e(sio_configure_stage(sio, sios_bio, "bio", sbio));
+
+#ifdef SINK
         s(sa_getfd(sa, &fd));
         p(bio = BIO_new_socket(fd, 0));
-
-        p(sbio = BIO_new_ssl(ctx,0));
         p(BIO_push(sbio,bio));
+#else
+        e(sio_configure_stage(sio, sios_sa, "sa", sa));
+        buflen = 256;
+        e(sio_configure_stage(sio, sios_sa, "buflen", &buflen));
+        e(sio_configure_stage(sio, sios_bio, "issink", &no));
+#endif
+        e(sio_configure_stage(sio, sios_bio, "freebio", &yes));
 
-        e(sio_configure_stage(sio, sios_bio, "bio", sbio));
 
-        e(sio_attach(sio, sios_buffer, SIO_MODE_WRITE));
-        e(sio_attach(sio, sios_hello, SIO_MODE_READWRITE));
+#ifndef SINK
+        e(sio_attach(sio, sios_sa, SIO_MODE_READWRITE));
+#endif
         e(sio_attach(sio, sios_bio, SIO_MODE_READWRITE));
+        e(sio_attach(sio, sios_hello, SIO_MODE_READWRITE));
+        e(sio_attach(sio, sios_buffer, SIO_MODE_WRITE));
 
         e(sio_write(sio, buf, sizeof(buf)-1, &actual));
         e(sio_push(sio));
 
-        e(sio_detach(sio, sios_bio));
-        e(sio_detach(sio, sios_hello));
         e(sio_detach(sio, sios_buffer));
+        e(sio_detach(sio, sios_hello));
+        e(sio_detach(sio, sios_bio));
+#ifndef SINK
+        e(sio_detach(sio, sios_sa));
+#endif
 
+#ifdef SINK
         BIO_pop(bio);
-        BIO_free(sbio);
+#endif
+        /* BIO_free(sbio); */
+#ifdef SINK
         BIO_free(bio);
+#endif
 
         sa_destroy(sa);
     }
 
 
+#ifndef SINK
+    e(sio_destroy_stage(sio, sios_sa));
+#endif
     e(sio_destroy_stage(sio, sios_buffer));
     e(sio_destroy_stage(sio, sios_hello));
     e(sio_destroy_stage(sio, sios_bio));

CVSTrac 2.0.1