--- 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;
|