OSSP CVS Repository

ossp - Difference in ossp-pkg/sio/sio_bio.c versions 1.11 and 1.12
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/sio/sio_bio.c 1.11 -> 1.12

--- sio_bio.c    2003/02/05 16:29:05     1.11
+++ sio_bio.c    2003/02/06 12:45:18     1.12
@@ -231,9 +231,10 @@
         return SIO_ERR_MEM;
 
     my->bio           = NULL;
-    my->nbio          = NULL;
+    my->inputsize     = 512;
     my->issink        = 0;
     my->freebio       = 0;
+    my->nbio          = NULL;
     my->eof           = '\0';
     my->error         = '\0';
 
@@ -420,35 +421,43 @@
 static
 sio_rc_t siobio_input_upper(private_t *my, al_t *al)
 {
+    size_t n;
+    
+    /* copy global al into input buffer */
+    n = al_bytes(al);
+    al_splice(al, 0, n, NULL, my->al_in);
+
     /* flush output */
     if (my->flush_upper)
         return SIO_SCHED_CROSS;
 
-    if (al_bytes(al) <= 0)
+    /* transport data to lower layers */
+    if (al_bytes(my->al_in) <= 0)
         return SIO_SCHED_UP;
 
-    al_splice(al, 0, al_bytes(al), NULL, my->al_in);
-
     if (!my->isoutput) {
         my->state = LOWER;
         return SIO_SCHED_LOOP;
     }
-
     return SIO_SCHED_CROSS;
 }
 
 static
 sio_rc_t siobio_output_upper(private_t *my, al_t *al)
 {
-    /* flush output */
-    if (my->flush_upper) {
-        my->flush_upper = 0;
-        al_splice(al, al_bytes(al), 0, my->al_out, NULL);
+    /* copy output buffer to global al */
+    my->flush_upper = 0;
+    al_splice(al, al_bytes(al), 0, my->al_out, NULL);
+
+    /* transport data to upper layers */
+    if (al_bytes(al) > 0)
         return SIO_SCHED_UP;
-    }
 
+    /* lower layers signalled they need input */
     if (my->needs_input) {
         my->needs_input = 0;
+        /* place input buffer on global al so input routines
+         * can pick it from there again */
         al_splice(al, 0, al_bytes(al), my->al_in, NULL);
         return SIO_SCHED_CROSS;
     }
@@ -457,7 +466,6 @@
         my->state = LOWER;
         return SIO_SCHED_LOOP;
     }
-
     return SIO_SCHED_CROSS;
 }
 
@@ -493,7 +501,7 @@
 void siobio_bio_read(private_t *my)
 {
     char *p;
-    int n;
+    int n, m;
 
     n = BIO_pending(my->bio);
     if (n <= 0 || (size_t)n > my->inputsize)
@@ -503,21 +511,25 @@
 
     if (my->bio) {
         do {
-            n = BIO_read(my->bio, p, n);
-        } while (n <= 0 && BIO_should_retry(my->bio));
+            m = BIO_read(my->bio, p, n);
+        } while (m <= 0 && BIO_should_retry(my->bio));
+        if (m == -1 && !my->eof_reached) {
+            my->flush_upper = 1;
+            m = 0;
+        }
     } else
-        n = -2;
+        m = -2;
 
-    if (n < 0) {
+    if (m < 0) {
         free(p);
-        if (n < -1)
+        if (m < -1)
             al_append_bytes(my->in_buf, &my->error,
                             sizeof(my->error), my->error_label);
         else
             al_append_bytes(my->in_buf, &my->eof,
                             sizeof(my->eof), my->eof_label);
-    } else if (n > 0)
-        al_attach_buffer(my->in_buf, p, n, my->data_label, freebiobuf, NULL);
+    } else if (m > 0)
+        al_attach_buffer(my->in_buf, p, m, my->data_label, freebiobuf, NULL);
 }
 
 static

CVSTrac 2.0.1