--- sio.c 2002/10/24 07:46:01 1.3
+++ sio.c 2002/11/05 13:23:36 1.4
@@ -58,6 +58,8 @@
NODE(sio_halfduplex_t) hd;
sio_stage_t *stage;
sio_halfduplex_t *cross;
+ const char *tag;
+ sio_rc_t rc_with_data, rc_no_data;
al_t *al;
sio_rc_t (*func)(sio_t *, al_t *, void *);
};
@@ -99,15 +101,28 @@
* call stage and direct data upstream/downstream
* according to response code
*
+ * if stage directs SIO_OK, chose default direction
+ * depending on data in assembly line
+ *
* if we the stage does not return a direction,
* simply end the code
*
* if we drop off the chain, simply result SIO_OK
*
*/
- h = chain;
+ rc = SIO_UPSTREAM;
+ h = chain;
while (h != NULL) {
rc = h->func(sio, h->al, h->stage->userdata);
+
+ /* chose default direction */
+ if (rc == SIO_OK) {
+ if (al_bytes(h->al) > 0)
+ rc = h->rc_with_data;
+ else
+ rc = h->rc_no_data;
+ }
+
if (rc == SIO_UPSTREAM)
h = NEXT(h,hd);
else if (rc == SIO_DOWNSTREAM)
@@ -176,17 +191,28 @@
NODEINIT(&sios->reader,hd);
NODEINIT(&sios->writer,hd);
+
sios->module = siom;
+
sios->userdata = NULL;
sios->rw = SIO_MODE_INVALID;
- sios->reader.func = siom->input;
+ sios->reader.func = sios->module->input;
sios->reader.stage = sios;
- sios->writer.func = siom->output;
+ sios->writer.func = sios->module->output;
sios->writer.stage = sios;
sios->reader.cross = &sios->writer;
sios->writer.cross = &sios->reader;
+ sios->reader.tag = "reader";
+ sios->writer.tag = "writer";
+
+ /* default rules */
+ sios->reader.rc_with_data = SIO_DOWNSTREAM;
+ sios->reader.rc_no_data = SIO_UPSTREAM;
+ sios->writer.rc_with_data = SIO_UPSTREAM;
+ sios->writer.rc_no_data = SIO_DOWNSTREAM;
+
rc = sios->module->init(sio, &sios->userdata);
if (rc != SIO_OK) {
free(sios);
|