OSSP CVS Repository

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

ossp-pkg/sio/sio_fd.c 1.2 -> 1.3

--- sio_fd.c     2002/10/23 17:05:10     1.2
+++ sio_fd.c     2002/11/05 15:52:21     1.3
@@ -18,9 +18,10 @@
     int fd;
     buffer_t input;
     size_t written;
-    void *label_data;
-    void *label_error;
-    void *label_eof;
+    al_label_t data_label;
+    al_label_t error_label;
+    al_label_t eof_label;
+    char eof, error;
 } private_t;
 
 /*
@@ -31,22 +32,25 @@
 static
 sio_rc_t fd_init(sio_t *sio, void **u)
 {
-    private_t *mydata;
+    private_t *my;
     
-    mydata = (private_t *)malloc(sizeof(private_t));
-    if (mydata == NULL)
+    my = (private_t *)malloc(sizeof(private_t));
+    if (my == NULL)
         return SIO_ERR_MEM;
 
-    mydata->fd           = -1;
+    my->fd           = -1;
 
-    mydata->input.mem    = NULL;
-    mydata->input.size   = 0;
+    my->input.mem    = NULL;
+    my->input.size   = 0;
 
-    sio_label(sio, SIO_LN_DATA,  &mydata->label_data);
-    sio_label(sio, SIO_LN_ERROR, &mydata->label_error);
-    sio_label(sio, SIO_LN_EOF,   &mydata->label_eof);
+    sio_label(sio, SIO_LN_DATA,  &my->data_label);
+    sio_label(sio, SIO_LN_ERROR, &my->error_label);
+    sio_label(sio, SIO_LN_EOF,   &my->eof_label);
 
-    *u = mydata;
+    my->eof          = '\0';
+    my->error        = '\0';
+
+    *u = my;
 
     return SIO_OK;
 }
@@ -58,13 +62,13 @@
 static
 sio_rc_t fd_configure(sio_t *sio, void *u, void *obj, void *val)
 {
-    private_t *mydata = (private_t *)u;
+    private_t *my = (private_t *)u;
     const char *name = (const char *)obj;
 
     if (!strcmp(name, "fd")) {
-        mydata->fd = *(int *)val;
+        my->fd = *(int *)val;
     } else if (!strcmp(name, "buflen")) {
-        mydata->input.size = *(size_t *)val;
+        my->input.size = *(size_t *)val;
     } else {
         return SIO_ERR_ARG;
     }
@@ -84,8 +88,8 @@
 static
 sio_rc_t fd_openr(sio_t *sio, al_t *al, void *u)
 {
-    private_t *mydata = (private_t *)u;
-    buffer_t *buf = &mydata->input;
+    private_t *my = (private_t *)u;
+    buffer_t *buf = &my->input;
     char *p;
     size_t n;
 
@@ -103,8 +107,8 @@
 static
 sio_rc_t fd_closer(sio_t *sio, al_t *al, void *u)
 {
-    private_t *mydata = (private_t *)u;
-    buffer_t *buf = &mydata->input;
+    private_t *my = (private_t *)u;
+    buffer_t *buf = &my->input;
 
     if (buf->mem != NULL) {
         free(buf->mem);
@@ -129,20 +133,20 @@
 static
 sio_rc_t fd_input(sio_t *sio, al_t *al, void *u)
 {
-    private_t *mydata = (private_t *)u;
-    buffer_t *buf = &mydata->input;
+    private_t *my = (private_t *)u;
+    buffer_t *buf = &my->input;
     size_t actual;
 
-    actual = read(mydata->fd, buf->mem, buf->size);
+    actual = read(my->fd, buf->mem, buf->size);
     if (actual < 0) {
-        al_append_bytes(al, NULL, 0, mydata->label_error);
-        return SIO_OK;
+        al_appendbytes(al, &my->eof, sizeof(my->eof), my->error_label);
+        return SIO_DOWNSTREAM;
     } else if (actual == 0) {
-        al_append_bytes(al, NULL, 0, mydata->label_eof);
-        return SIO_OK;
+        al_appendbytes(al, &my->error, sizeof(my->error), my->eof_label);
+        return SIO_DOWNSTREAM;
     }
 
-    al_append_bytes(al, buf->mem, actual, mydata->label_data);
+    al_append_bytes(al, buf->mem, actual, my->data_label);
 
     return SIO_DOWNSTREAM;
 }
@@ -150,18 +154,18 @@
 static
 al_rc_t fd_output_chunk(al_chunk_t *alc, void *u)
 {
-    private_t *mydata = (private_t *)u;
+    private_t *my = (private_t *)u;
     char   *p;
     size_t n, actual;
 
     p = al_chunk_ptr(alc, 0);
     n = al_chunk_len(alc);
 
-    actual = write(mydata->fd, p, n);
+    actual = write(my->fd, p, n);
     if (actual < 0)
         return AL_ERR_EOF;
 
-    mydata->written += actual;
+    my->written += actual;
 
     return AL_OK;
 }
@@ -169,18 +173,20 @@
 static
 sio_rc_t fd_output(sio_t *sio, al_t *al, void *u)
 {
-    private_t *mydata = (private_t *)u;
+    private_t *my = (private_t *)u;
     al_rc_t arc;
     size_t n = al_bytes(al);
 
-    mydata->written = 0;
+    my->written = 0;
 
-    arc = al_traverse_cb(al, 0, n, AL_FORWARD, mydata->label_data,
+    arc = al_traverse_cb(al, 0, n, AL_FORWARD, my->data_label,
                          fd_output_chunk, u);
-    if (arc != AL_OK) return SIO_ERR_INT;
+    if (arc != AL_OK)
+        return SIO_ERR_DOWNSTREAM;
 
-    arc = al_splice(al, 0, mydata->written, NULL, NULL);
-    if (arc != AL_OK) return SIO_ERR_INT;
+    arc = al_splice(al, 0, my->written, NULL, NULL);
+    if (arc != AL_OK)
+        return SIO_ERR_DOWNSTREAM;
 
     return SIO_DOWNSTREAM;
 }

CVSTrac 2.0.1