Index: ossp-pkg/sio/sio.c RCS File: /v/ossp/cvs/ossp-pkg/sio/sio.c,v rcsdiff -q -kk '-r1.5' '-r1.6' -u '/v/ossp/cvs/ossp-pkg/sio/sio.c,v' 2>/dev/null --- sio.c 2002/11/05 15:48:57 1.5 +++ sio.c 2002/11/05 15:52:21 1.6 @@ -77,9 +77,9 @@ sio_labelnum_t label_error; sio_labelnum_t label_eof; }; -#define SIO_LABEL_DATA(sio) ((al_label_t *)&(sio)->label_data) -#define SIO_LABEL_ERROR(sio) ((al_label_t *)&(sio)->label_error) -#define SIO_LABEL_EOF(sio) ((al_label_t *)&(sio)->label_eof) +#define SIO_LABEL_DATA(sio) ((al_label_t)&(sio)->label_data) +#define SIO_LABEL_ERROR(sio) ((al_label_t)&(sio)->label_error) +#define SIO_LABEL_EOF(sio) ((al_label_t)&(sio)->label_eof) struct sio_stage_st { sio_halfduplex_t reader; @@ -551,7 +551,7 @@ return mess; } -sio_rc_t sio_label(sio_t *sio, sio_labelnum_t ln, void **p) +sio_rc_t sio_label(sio_t *sio, sio_labelnum_t ln, al_label_t *p) { void *label; Index: ossp-pkg/sio/sio_buffer.c RCS File: /v/ossp/cvs/ossp-pkg/sio/sio_buffer.c,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/sio/sio_buffer.c,v' 2>/dev/null --- sio_buffer.c 2002/10/23 17:05:10 1.1 +++ sio_buffer.c 2002/11/05 15:52:21 1.2 @@ -11,6 +11,7 @@ al_tx_t *outputtx; size_t inputsize; al_t *input, *output; + al_label_t data_label; } private_t; /* @@ -21,16 +22,18 @@ static sio_rc_t buffer_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->inputsize = 0; - mydata->outputsize = 0; + my->inputsize = 0; + my->outputsize = 0; - *u = mydata; + sio_label(sio, SIO_LN_DATA, &my->data_label); + + *u = my; return SIO_OK; } @@ -43,13 +46,13 @@ static sio_rc_t buffer_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, "inputsize")) { - mydata->inputsize = *(size_t *)val; + my->inputsize = *(size_t *)val; } else if (!strcmp(name, "outputsize")) { - mydata->outputsize = *(size_t *)val; + my->outputsize = *(size_t *)val; } else { return SIO_ERR_ARG; } @@ -63,9 +66,9 @@ static sio_rc_t buffer_cleanup(sio_t *sio, void *u) { - private_t *mydata = (private_t *)u; + private_t *my = (private_t *)u; - free(mydata); + free(my); return SIO_OK; } @@ -73,10 +76,10 @@ static sio_rc_t buffer_openr(sio_t *sio, al_t *al, void *u) { - private_t *mydata = (private_t *)u; + private_t *my = (private_t *)u; al_rc_t arc; - arc = al_create(&mydata->input); + arc = al_create(&my->input); if (arc != AL_OK) return SIO_ERR_INT; @@ -86,10 +89,10 @@ static sio_rc_t buffer_closer(sio_t *sio, al_t *al, void *u) { - private_t *mydata = (private_t *)u; + private_t *my = (private_t *)u; - al_destroy(mydata->input); - mydata->input = NULL; + al_destroy(my->input); + my->input = NULL; return SIO_OK; } @@ -97,16 +100,16 @@ static sio_rc_t buffer_openw(sio_t *sio, al_t *al, void *u) { - private_t *mydata = (private_t *)u; + private_t *my = (private_t *)u; al_rc_t arc; - arc = al_txalloc(al, &mydata->outputtx); + arc = al_txalloc(al, &my->outputtx); if (arc != AL_OK) return SIO_ERR_INT; - arc = al_create(&mydata->output); + arc = al_create(&my->output); if (arc != AL_OK) { - al_txfree(al, mydata->outputtx); + al_txfree(al, my->outputtx); return SIO_ERR_INT; } @@ -116,18 +119,29 @@ static sio_rc_t buffer_closew(sio_t *sio, al_t *al, void *u) { - private_t *mydata = (private_t *)u; + private_t *my = (private_t *)u; - al_destroy(mydata->output); - mydata->output = NULL; - al_txfree(al, mydata->outputtx); - mydata->outputtx = NULL; + al_destroy(my->output); + my->output = NULL; + al_txfree(al, my->outputtx); + my->outputtx = NULL; return SIO_OK; } +/* + * buffer logic + * + * gather data from producer + * if buffer size reached or label changes then push data to consumer + * (read -> downstream, write -> upstream) + * + * buffer size depends on label type + * + */ static -sio_rc_t buffer_inout(sio_t *sio, al_t *al, al_t *buf, size_t size, +sio_rc_t buffer_inout(sio_t *sio, al_t *al, private_t *my, + al_t *buf, size_t size, sio_rc_t up, sio_rc_t down) { size_t avail, data, needed; @@ -148,7 +162,13 @@ al_flatten(buf, 0, avail, AL_FORWARD_SPAN, label, NULL, &data); - needed = size; + /* non-data is not buffered */ + if (label == my->data_label) + needed = size; + else + needed = 1; + + /* flush if there is extra data (that must have a different label) */ if (data < avail) needed = 1; @@ -165,18 +185,20 @@ static sio_rc_t buffer_input(sio_t *sio, al_t *al, void *u) { - private_t *mydata = (private_t *)u; + private_t *my = (private_t *)u; - return buffer_inout(sio, al, mydata->input, mydata->inputsize, + return buffer_inout(sio, al, my, + my->input, my->inputsize, SIO_DOWNSTREAM, SIO_UPSTREAM); } static sio_rc_t buffer_output(sio_t *sio, al_t *al, void *u) { - private_t *mydata = (private_t *)u; + private_t *my = (private_t *)u; - return buffer_inout(sio, al, mydata->output, mydata->outputsize, + return buffer_inout(sio, al, my, + my->output, my->outputsize, SIO_UPSTREAM, SIO_DOWNSTREAM); } Index: ossp-pkg/sio/sio_fd.c RCS File: /v/ossp/cvs/ossp-pkg/sio/sio_fd.c,v rcsdiff -q -kk '-r1.2' '-r1.3' -u '/v/ossp/cvs/ossp-pkg/sio/sio_fd.c,v' 2>/dev/null --- 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; } Index: ossp-pkg/sio/sio_hello.c RCS File: /v/ossp/cvs/ossp-pkg/sio/sio_hello.c,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/sio/sio_hello.c,v' 2>/dev/null --- sio_hello.c 2002/11/05 13:23:36 1.1 +++ sio_hello.c 2002/11/05 15:52:21 1.2 @@ -32,8 +32,8 @@ int npass; /* characters in input buffer */ al_t *pre; /* saved output during protocol */ int isoutput; /* remember originator of protocol */ - void *data_label; /* al labels used by SIO */ - void *eof_label; + al_label_t data_label; /* al labels used by SIO */ + al_label_t eof_label; char eof; /* eof label buffer */ } private_t; Index: ossp-pkg/sio/sio_module.h RCS File: /v/ossp/cvs/ossp-pkg/sio/Attic/sio_module.h,v rcsdiff -q -kk '-r1.2' '-r1.3' -u '/v/ossp/cvs/ossp-pkg/sio/Attic/sio_module.h,v' 2>/dev/null --- sio_module.h 2002/10/23 17:05:10 1.2 +++ sio_module.h 2002/11/05 15:52:21 1.3 @@ -17,4 +17,4 @@ SIO_LN_EOF } sio_labelnum_t; -sio_rc_t sio_label(sio_t *, sio_labelnum_t label, void **labelp); +sio_rc_t sio_label(sio_t *, sio_labelnum_t, al_label_t *); Index: ossp-pkg/sio/sio_sa.c RCS File: /v/ossp/cvs/ossp-pkg/sio/sio_sa.c,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/sio/sio_sa.c,v' 2>/dev/null --- sio_sa.c 2002/11/05 13:23:36 1.1 +++ sio_sa.c 2002/11/05 15:52:21 1.2 @@ -20,9 +20,9 @@ sa_t *sa; 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; char error; } private_t; @@ -33,7 +33,7 @@ * allocate private instance data */ static -sio_rc_t sa_init(sio_t *sio, void **u) +sio_rc_t saw_init(sio_t *sio, void **u) { private_t *my; @@ -46,9 +46,9 @@ my->input.mem = NULL; my->input.size = 0; - sio_label(sio, SIO_LN_DATA, &my->label_data); - sio_label(sio, SIO_LN_ERROR, &my->label_error); - sio_label(sio, SIO_LN_EOF, &my->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); my->eof = '\0'; my->error = '\0'; @@ -63,7 +63,7 @@ * */ static -sio_rc_t sa_configure(sio_t *sio, void *u, void *obj, void *val) +sio_rc_t saw_configure(sio_t *sio, void *u, void *obj, void *val) { private_t *my = (private_t *)u; const char *name = (const char *)obj; @@ -83,13 +83,13 @@ * destroy stage */ static -sio_rc_t sa_cleanup(sio_t *sio, void *u) +sio_rc_t saw_cleanup(sio_t *sio, void *u) { return SIO_OK; } static -sio_rc_t sa_openr(sio_t *sio, al_t *al, void *u) +sio_rc_t saw_openr(sio_t *sio, al_t *al, void *u) { private_t *my = (private_t *)u; buffer_t *buf = &my->input; @@ -108,7 +108,7 @@ } static -sio_rc_t sa_closer(sio_t *sio, al_t *al, void *u) +sio_rc_t saw_closer(sio_t *sio, al_t *al, void *u) { private_t *my = (private_t *)u; buffer_t *buf = &my->input; @@ -122,33 +122,33 @@ } static -sio_rc_t sa_openw(sio_t *sio, al_t *al, void *u) +sio_rc_t saw_openw(sio_t *sio, al_t *al, void *u) { return SIO_OK; } static -sio_rc_t sa_closew(sio_t *sio, al_t *al, void *u) +sio_rc_t saw_closew(sio_t *sio, al_t *al, void *u) { return SIO_OK; } static -void sa_writeeof(al_t *al, private_t *my) +void saw_writeeof(al_t *al, private_t *my) { al_splice(al, 0, al_bytes(al), NULL, NULL); - al_append_bytes(al, &my->eof, sizeof(my->eof), my->label_eof); + al_append_bytes(al, &my->eof, sizeof(my->eof), my->eof_label); } static -void sa_writeerror(al_t *al, private_t *my) +void saw_writeerror(al_t *al, private_t *my) { al_splice(al, 0, al_bytes(al), NULL, NULL); - al_append_bytes(al, &my->error, sizeof(my->error), my->label_error); + al_append_bytes(al, &my->error, sizeof(my->error), my->error_label); } static -sio_rc_t sa_input(sio_t *sio, al_t *al, void *u) +sio_rc_t saw_input(sio_t *sio, al_t *al, void *u) { private_t *my = (private_t *)u; buffer_t *buf = &my->input; @@ -157,20 +157,20 @@ src = sa_read(my->sa, buf->mem, buf->size, &actual); if (src != SA_OK) { - sa_writeerror(al, my); + saw_writeerror(al, my); return SIO_DOWNSTREAM; } else if (src == SA_ERR_EOF) { - sa_writeeof(al, my); + saw_writeeof(al, my); return SIO_DOWNSTREAM; } - al_append_bytes(al, buf->mem, actual, my->label_data); + al_append_bytes(al, buf->mem, actual, my->data_label); return SIO_DOWNSTREAM; } static -al_rc_t sa_output_chunk(al_chunk_t *alc, void *u) +al_rc_t saw_output_chunk(al_chunk_t *alc, void *u) { private_t *my = (private_t *)u; char *p; @@ -190,7 +190,7 @@ } static -sio_rc_t sa_output(sio_t *sio, al_t *al, void *u) +sio_rc_t saw_output(sio_t *sio, al_t *al, void *u) { private_t *my = (private_t *)u; al_rc_t arc; @@ -198,8 +198,8 @@ my->written = 0; - arc = al_traverse_cb(al, 0, n, AL_FORWARD, my->label_data, - sa_output_chunk, u); + arc = al_traverse_cb(al, 0, n, AL_FORWARD, my->data_label, + saw_output_chunk, u); if (arc != AL_OK) return SIO_ERR_INT; arc = al_splice(al, 0, al_bytes(al), NULL, NULL); @@ -210,15 +210,15 @@ sio_module_t sio_module_sa = { "sa", - sa_init, - sa_configure, - sa_cleanup, - sa_openr, - sa_closer, - sa_openw, - sa_closew, - sa_input, - sa_output + saw_init, + saw_configure, + saw_cleanup, + saw_openr, + saw_closer, + saw_openw, + saw_closew, + saw_input, + saw_output };