Index: ossp-pkg/sio/Makefile RCS File: /v/ossp/cvs/ossp-pkg/sio/Attic/Makefile,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/sio/Attic/Makefile,v' 2>/dev/null --- Makefile 2002/11/14 09:24:54 1.1 +++ Makefile 2002/11/19 15:54:51 1.2 @@ -10,7 +10,8 @@ al_test: al_test.o al.o -sio_test: sio_test.o sio_buffer.o sio_hello.o sio_fd.o sio_sa.o sio.o al.o lib_sa/sa.o +sio_test: sio_test.o sio_buffer.o sio_hello.o sio_bio.o sio.o al.o lib_sa/sa.o + $(CC) $(CFLAGS) -o sio_test sio_test.o sio_buffer.o sio_hello.o sio_bio.o sio.o al.o lib_sa/sa.o -lcrypto lib_sa/sa.o: lib_sa/sa.c $(CC) $(CFLAGS) -c -Ilib_sa -o lib_sa/sa.o lib_sa/sa.c @@ -22,5 +23,5 @@ $(CC) $(CFLAGS) -c -Ilib_sa sio_test.c clean: - rm -f sio_test sio_test.o sio_buffer.o sio_hello.o sio_fd.o sio_sa.o sio.o al.o lib_sa/sa.o + rm -f *.o lib_sa/sa.o Index: ossp-pkg/sio/sio_bio.c RCS File: /v/ossp/cvs/ossp-pkg/sio/sio_bio.c,v co -q -kk -p'1.1' '/v/ossp/cvs/ossp-pkg/sio/sio_bio.c,v' | diff -u /dev/null - -L'ossp-pkg/sio/sio_bio.c' 2>/dev/null --- ossp-pkg/sio/sio_bio.c +++ - 2024-05-16 01:46:46.386067071 +0200 @@ -0,0 +1,163 @@ +#include +#include +#include + +#include "al.h" +#include "sio.h" + +#include + +typedef struct { + BIO *bio; + size_t inputsize; + al_label_t data_label; + al_label_t eof_label; + char eof; +} private_t; + +/* + * create stage + * + * allocate private instance data + */ +static +sio_rc_t siobio_init(sio_t *sio, void **u) +{ + private_t *my; + + my = (private_t *)malloc(sizeof(private_t)); + if (my == NULL) + return SIO_ERR_MEM; + + my->bio = NULL; + my->eof = '\0'; + + sio_label(sio, SIO_LN_DATA, &my->data_label); + sio_label(sio, SIO_LN_EOF, &my->eof_label); + + *u = my; + + return SIO_OK; +} + +/* + * configure stage + * + * pass two void pointers + */ +static +sio_rc_t siobio_configure(sio_t *sio, void *u, void *obj, void *val) +{ + private_t *my = (private_t *)u; + const char *name = (const char *)obj; + + if (!strcmp(name, "bio")) { + my->bio = (BIO *)val; + } else if (!strcmp(name, "inputsize")) { + my->inputsize = *(int *)val; + } else { + return SIO_ERR_ARG; + } + + return SIO_OK; +} + +/* + * destroy stage + */ +static +sio_rc_t siobio_cleanup(sio_t *sio, void *u) +{ + private_t *my = (private_t *)u; + + free(my); + + return SIO_OK; +} + +static +sio_rc_t siobio_openr(sio_t *sio, al_t *al, void *u) +{ + return SIO_OK; +} + +static +sio_rc_t siobio_closer(sio_t *sio, al_t *al, void *u) +{ + return SIO_OK; +} + +static +sio_rc_t siobio_openw(sio_t *sio, al_t *al, void *u) +{ + return SIO_OK; +} + +static +sio_rc_t siobio_closew(sio_t *sio, al_t *al, void *u) +{ + return SIO_OK; +} + +static +void freebiobuf(char *p, size_t n, void *u) +{ + free(p); +} +static +sio_rc_t siobio_input(sio_t *sio, al_t *al, void *u) +{ + private_t *my = (private_t *)u; + char *p; + int n; + + n = BIO_pending(my->bio); + if (n == 0 || n > my->inputsize) + n = my->inputsize; + p = malloc(n); + n = BIO_read(my->bio, p, n); + + if (n == 0 && !BIO_should_read(my->bio)) + al_append_bytes(al, &my->eof, sizeof(my->eof), my->eof_label); + else + al_attach_buffer(al, p, n, my->data_label, freebiobuf, NULL); + + return SIO_SCHED_DOWN; +} + +static +al_rc_t siobio_write_chunk(al_chunk_t *alc, void *u) +{ + private_t *my = (private_t *)u; + + if (al_same_label(alc, my->data_label)) + BIO_write(my->bio, al_chunk_ptr(alc, 0), al_chunk_len(alc)); + + return AL_OK; +} +static +sio_rc_t siobio_output(sio_t *sio, al_t *al, void *u) +{ + private_t *my = (private_t *)u; + + al_traverse_cb(al, 0, al_bytes(al), AL_FORWARD, my->data_label, + siobio_write_chunk, (void *)my); + + al_splice(al, 0, al_bytes(al), NULL, NULL); + + return SIO_SCHED_DOWN; +} + +sio_module_t sio_module_bio = { + "bio", + siobio_init, + siobio_configure, + siobio_cleanup, + siobio_openr, + siobio_closer, + siobio_openw, + siobio_closew, + siobio_input, + siobio_output +}; + Index: ossp-pkg/sio/sio_test.c RCS File: /v/ossp/cvs/ossp-pkg/sio/sio_test.c,v rcsdiff -q -kk '-r1.2' '-r1.3' -u '/v/ossp/cvs/ossp-pkg/sio/sio_test.c,v' 2>/dev/null --- sio_test.c 2002/11/05 13:23:36 1.2 +++ sio_test.c 2002/11/19 15:54:51 1.3 @@ -4,8 +4,11 @@ #include "sio.h" #include "sa.h" +#include +#include +extern BIO_METHOD *BIO_s_socket(); -extern sio_module_t sio_module_sa; +extern sio_module_t sio_module_bio; extern sio_module_t sio_module_hello; extern sio_module_t sio_module_buffer; @@ -16,13 +19,16 @@ { sio_rc_t rc; sio_t *sio; - sio_stage_t *sios_sa, *sios_hello, *sios_buffer; + sio_stage_t *sios_bio, *sios_hello, *sios_buffer; sa_rc_t src; sa_addr_t *saa; sa_t *msa, *sa; char *uri; + int fd; + BIO *bio; + char buf[] = "Hello world\n"; size_t actual; @@ -39,12 +45,12 @@ uri = NULL; e(sio_create(&sio)); - e(sio_create_stage(sio, &sio_module_sa, &sios_sa)); + e(sio_create_stage(sio, &sio_module_bio, &sios_bio)); e(sio_create_stage(sio, &sio_module_hello, &sios_hello)); e(sio_create_stage(sio, &sio_module_buffer, &sios_buffer)); buflen = 256; - e(sio_configure_stage(sio, sios_sa, "buflen", &buflen)); + e(sio_configure_stage(sio, sios_bio, "inputsize", &buflen)); buflen = 1000; e(sio_configure_stage(sio, sios_buffer, "outputsize", &buflen)); @@ -58,16 +64,21 @@ printf("Connection from %s\n",uri); s(sa_addr_destroy(saa)); - e(sio_configure_stage(sio, sios_sa, "sa", sa)); + + bio = BIO_new(BIO_s_socket()); + sa_getfd(sa, &fd); + BIO_set_fd(bio, fd, 0); + + e(sio_configure_stage(sio, sios_bio, "bio", bio)); e(sio_attach(sio, sios_buffer, SIO_MODE_WRITE)); e(sio_attach(sio, sios_hello, SIO_MODE_READWRITE)); - e(sio_attach(sio, sios_sa, SIO_MODE_READWRITE)); + e(sio_attach(sio, sios_bio, SIO_MODE_READWRITE)); e(sio_write(sio, buf, sizeof(buf)-1, &actual)); e(sio_push(sio)); - e(sio_detach(sio, sios_sa)); + e(sio_detach(sio, sios_bio)); e(sio_detach(sio, sios_hello)); e(sio_detach(sio, sios_buffer)); @@ -77,7 +88,7 @@ e(sio_destroy_stage(sio, sios_buffer)); e(sio_destroy_stage(sio, sios_hello)); - e(sio_destroy_stage(sio, sios_sa)); + e(sio_destroy_stage(sio, sios_bio)); e(sio_destroy(sio));