head 1.20; access; symbols SIO_0_9_3:1.20 SIO_0_9_2:1.19 SIO_0_9_1:1.18 SIO_0_9_0:1.17; locks; strict; comment @ * @; 1.20 date 2005.10.03.09.06.11; author rse; state Exp; branches; next 1.19; 1.19 date 2003.06.30.10.36.52; author rse; state Exp; branches; next 1.18; 1.18 date 2003.02.11.10.54.07; author mlelstv; state Exp; branches; next 1.17; 1.17 date 2003.02.06.13.51.54; author mlelstv; state Exp; branches; next 1.16; 1.16 date 2003.02.06.12.50.53; author mlelstv; state Exp; branches; next 1.15; 1.15 date 2003.02.06.12.49.16; author mlelstv; state Exp; branches; next 1.14; 1.14 date 2003.02.04.15.07.21; author mlelstv; state Exp; branches; next 1.13; 1.13 date 2003.02.03.17.19.11; author mlelstv; state Exp; branches; next 1.12; 1.12 date 2003.01.30.16.38.32; author mlelstv; state Exp; branches; next 1.11; 1.11 date 2003.01.30.15.06.54; author mlelstv; state Exp; branches; next 1.10; 1.10 date 2003.01.30.15.04.06; author mlelstv; state Exp; branches; next 1.9; 1.9 date 2003.01.30.13.44.20; author mlelstv; state Exp; branches; next 1.8; 1.8 date 2003.01.20.19.13.39; author mlelstv; state Exp; branches; next 1.7; 1.7 date 2003.01.20.15.34.13; author mlelstv; state Exp; branches; next 1.6; 1.6 date 2003.01.06.19.04.56; author rse; state Exp; branches; next 1.5; 1.5 date 2002.11.24.19.36.48; author mlelstv; state Exp; branches; next 1.4; 1.4 date 2002.11.19.22.30.07; author mlelstv; state Exp; branches; next 1.3; 1.3 date 2002.11.19.15.54.51; author mlelstv; state Exp; branches; next 1.2; 1.2 date 2002.11.05.13.23.36; author mlelstv; state Exp; branches; next 1.1; 1.1 date 2002.10.23.17.05.10; author mlelstv; state Exp; branches; next ; desc @@ 1.20 log @adjust copyright messages @ text @/* ** OSSP sio - Stream I/O ** Copyright (c) 2002-2005 Cable & Wireless ** Copyright (c) 2002-2005 The OSSP Project ** Copyright (c) 2002-2005 Ralf S. Engelschall ** ** This file is part of OSSP sio, a layered stream I/O library ** which can be found at http://www.ossp.org/pkg/lib/sio/. ** ** Permission to use, copy, modify, and distribute this software for ** any purpose with or without fee is hereby granted, provided that ** the above copyright notice and this permission notice appear in all ** copies. ** ** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ** SUCH DAMAGE. ** ** sio_test.c: stream I/O library test suite */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include #include #include #include #include #include #include #include #include "ts.h" #include "al.h" #include "sio.h" #if ENABLE_BIO #include #include extern BIO_METHOD *BIO_s_socket(); extern sio_module_t sio_module_bio; #endif #if ENABLE_SA #include "sa.h" extern sio_module_t sio_module_sa; #endif extern sio_module_t sio_module_null; extern sio_module_t sio_module_hole; extern sio_module_t sio_module_buffer; extern sio_module_t sio_module_zlib; extern sio_module_t sio_module_sio; extern sio_module_t sio_module_fd; extern sio_module_t sio_module_hello; extern sio_module_t sio_module_sillymux; #define EVAL(name,rc,rc0,block,errf) \ ts_test_check(TS_CTX, name); \ block \ if (rc != rc0) \ ts_test_fail(TS_CTX, "%s -> %d[%s] (expected %d[%s])\n", \ name, rc, errf(rc), rc0, errf(rc0)) #define EVAL0(X) EVAL(#X,rc,SIO_OK,{ rc = X; },sio_error) #define EVALS(X) EVAL(#X,rc,SA_OK,{ rc = X; },sa_error) static sio_rc_t sreadloop(sio_t *, char *, size_t, size_t *); static int test_sio_pipe_read(ts_test_t *, int, int); static int test_sio_pipe_write(ts_test_t *, int, int); static int test_sio_hello_client(ts_test_t *, int, int); static int test_sio_hello_server(ts_test_t *, int, int); typedef int (*func)(ts_test_t *, int, int); static void session(ts_test_t *, func, func, int); static sio_rc_t sreadloop(sio_t *sio, char *buf, size_t len, size_t *actualp) { sio_rc_t rc = SIO_OK; size_t actual, total = 0; while (len > 0) { rc = sio_read(sio, buf, len, &actual); if (rc != SIO_OK) break; if (actual == 0) break; buf += actual; total += actual; len -= actual; } *actualp = total; return rc; } static void session(ts_test_t *_t, func client, func server, int duplex) { pid_t child; int pd[2]; int wcount = 147; int status; fflush(stdout); fflush(stderr); if (duplex) { if (socketpair(AF_UNIX, SOCK_STREAM, 0, pd) == -1) { ts_test_fail(TS_CTX, "cannot create socketpair (%s)\n", strerror(errno)); } } else { if (pipe(pd) == -1) { ts_test_fail(TS_CTX, "cannot create pipe (%s)\n", strerror(errno)); } } child = fork(); if (child == -1) { ts_test_fail(TS_CTX, "cannot fork (%s)\n", strerror(errno)); return; } if (child == 0) { int result; close(pd[0]); result = (*server)(NULL, pd[1], wcount); close(pd[1]); exit(result ? 1 : 0); } else { close(pd[1]); (*client)(_t, pd[0], wcount); close(pd[0]); waitpid(child, &status, 0); if (WIFEXITED(status) && WEXITSTATUS(status) != 0) { ts_test_fail(TS_CTX, "child terminated through exit with return code %d\n", WEXITSTATUS(status)); } else if (WIFSIGNALED(status)) { ts_test_fail(TS_CTX, "child terminated through signal %d%s\n", WTERMSIG(status), WCOREDUMP(status) ? " (core dump written)" : ""); } else if (WIFSTOPPED(status)) { ts_test_fail(TS_CTX, "child stopped through signal %d%s\n", WSTOPSIG(status)); } } } TS_TEST(test_sio_buffer) { sio_rc_t rc; sio_t *sio; sio_stage_t *sios_buffer, *sios_hole; size_t bufsize = 1000; /* output/input buffer size */ int i,wcount = 100; char S[] = "Hello world\n"; size_t actual, len = strlen(S); EVAL0(sio_create(&sio)); if (rc != SIO_OK) return; EVAL0(sio_create_stage(sio, &sio_module_hole, &sios_hole)); if (rc != SIO_OK) return; EVAL0(sio_create_stage(sio, &sio_module_buffer, &sios_buffer)); if (rc != SIO_OK) return; EVAL0(sio_configure_stage(sio, sios_buffer, "outputsize", &bufsize)); if (rc != SIO_OK) return; EVAL0(sio_attach(sio, sios_hole, SIO_MODE_WRITE)); if (rc != SIO_OK) return; EVAL0(sio_attach(sio, sios_buffer, SIO_MODE_WRITE)); if (rc != SIO_OK) return; for (i=0; i 0) { int n = lenodd - codd; if (n > actual) n = actual; if (memcmp(p, SO + codd, n) != 0) { ts_test_fail(TS_CTX, "data mismatch on odd stream\n"); break; } actual -= n; p += n; codd += n; if (codd >= lenodd) { codd = 0; ++nodd; if (nodd > wcount) ts_test_fail(TS_CTX, "excess data on odd stream\n"); } } if (actual > 0) break; EVAL0( ( (rc = sreadloop(C_sio, buf, sizeof(buf), &actual)), rc == SIO_ERR_EOF ? (--nstreams, SIO_OK) : rc ) ); if (rc != SIO_OK) break; p = buf; while (actual > 0) { int n = leneven - ceven; if (n > actual) n = actual; if (memcmp(p, SE + ceven, n) != 0) { ts_test_fail(TS_CTX, "data mismatch on even stream\n"); break; } actual -= n; p += n; ceven += n; if (ceven >= leneven) { ceven = 0; ++neven; if (neven > wcount) ts_test_fail(TS_CTX, "excess data on even stream\n"); } } if (actual > 0) break; if (nstreams == 0) break; } if (nodd < wcount) ts_test_fail(TS_CTX, "missing data on odd stream %d vs %d\n",nodd,wcount); if (neven < wcount) ts_test_fail(TS_CTX, "missing data on even stream %d vs %d\n",neven,wcount); if (codd != 0) ts_test_fail(TS_CTX, "extra chars on odd stream\n"); if (ceven != 0) ts_test_fail(TS_CTX, "extra chars on even stream\n"); /* * destroy EVEN stream */ EVAL0(sio_detach(C_sio, C_sios_sio)); EVAL0(sio_destroy_stage(C_sio, C_sios_sio)); EVAL0(sio_destroy(C_sio)); /* * destroy ODD stream */ EVAL0(sio_detach(B_sio, B_sios_sio)); EVAL0(sio_destroy_stage(B_sio, B_sios_sio)); EVAL0(sio_destroy(B_sio)); /* * destroy MUX stream */ EVAL0(sio_detach(A_sio, A_sios_sillymux)); EVAL0(sio_detach(A_sio, A_sios_fd)); EVAL0(sio_destroy_stage(A_sio, A_sios_sillymux)); EVAL0(sio_destroy_stage(A_sio, A_sios_fd)); EVAL0(sio_destroy(A_sio)); close_and_cleanup: close(fd); if (unlink(tempfile) < 0) { ts_test_fail(TS_CTX, "cannot unlink temporary file \"%s\" (%s)\n", tempfile, strerror(errno)); } } static int test_sio_hello_client(ts_test_t *_t, int fd, int dummy) { FILE *f; char buf[81]; int c, i; int do_login = 1; char S[] = "Welcome to the real world\r\n"; int result = 0; f = fdopen(fd, "r+"); if (f == NULL) { ts_test_fail(TS_CTX, "cannot make FILE handle\n"); return -1; } i = 0; for (;;) { c = fgetc(f); if (c == EOF) { ts_test_fail(TS_CTX, "EOF from server\n"); result = -1; break; } if (i >= 80) { ts_test_fail(TS_CTX, "input buffer overflow\n"); result = -1; break; } buf[i++] = c; buf[i] = '\0'; if (do_login) { if (i > 7) { ts_test_fail(TS_CTX, "handshake failure\n"); result = -1; break; } if (strcmp(buf, "Login: ") == 0) { fputs("Geheim\r\n", f); fflush(f); i = 0; do_login = 0; } } else if (c == '\n') break; } if (strcmp(buf, S)) { ts_test_fail(TS_CTX, "data mismatch\n"); result = -1; } fclose(f); return result; } static int test_sio_hello_server(ts_test_t *_t, int fd, int dummy) { int error = 0, result = -1; sio_rc_t rc; sio_t *sio; sio_stage_t *sios_hello, *sios_fd; size_t buflen = 47; /* fd input buffer size */ char S[] = "Welcome to the real world\r\n"; size_t actual, len = strlen(S); EVAL0(sio_create(&sio)); if (rc != SIO_OK) return -1; EVAL0(sio_create_stage(sio, &sio_module_fd, &sios_fd)); if (rc != SIO_OK) return -1; EVAL0(sio_create_stage(sio, &sio_module_hello, &sios_hello)); if (rc != SIO_OK) return -1; EVAL0(sio_configure_stage(sio, sios_fd, "buflen", &buflen)); if (rc != SIO_OK) return -1; EVAL0(sio_configure_stage(sio, sios_fd, "fd", &fd)); if (rc != SIO_OK) goto badwrite; EVAL0(sio_attach(sio, sios_fd, SIO_MODE_READWRITE)); if (rc != SIO_OK) goto badwrite; EVAL0(sio_attach(sio, sios_hello, SIO_MODE_READWRITE)); if (rc != SIO_OK) goto badwrite2; EVAL0(sio_write(sio, S, len, &actual)); if (rc != SIO_OK) error = 1; EVAL0(sio_push(sio)); if (rc != SIO_OK) error = 1; EVAL0(sio_detach(sio, sios_hello)); if (rc != SIO_OK) error = 1; result = error; badwrite2: EVAL0(sio_detach(sio, sios_fd)); if (rc != SIO_OK) result = -1; badwrite: /* * common cleanup */ EVAL0(sio_destroy_stage(sio, sios_hello)); if (rc != SIO_OK) result = -1; EVAL0(sio_destroy_stage(sio, sios_fd)); if (rc != SIO_OK) result = -1; EVAL0(sio_destroy(sio)); if (rc != SIO_OK) result = -1; return result; } TS_TEST(test_sio_hello) { session(_t, test_sio_hello_server, test_sio_hello_client, 1); } #if ENABLE_ZLIB TS_TEST(test_sio_zlib) { sio_rc_t rc; sio_t *sio; sio_stage_t *sios_zlib, *sios_fd; size_t bufsize = 1000; /* input/output buffer size */ int zoutlevel = 9; /* compress best on output */ int zinlevel = -1; /* decompress input */ size_t buflen = 81; /* fd input buffer size */ int fd; int i,wcount = 100; char S[] = "Hello world\n"; char buf[sizeof(S)]; size_t actual, len = strlen(S); char tempfile[] = "./sio_test_tmpfile.XXXXXX"; int do_unlink = 0; EVAL0(sio_create(&sio)); if (rc != SIO_OK) return; EVAL0(sio_create_stage(sio, &sio_module_fd, &sios_fd)); if (rc != SIO_OK) return; EVAL0(sio_create_stage(sio, &sio_module_zlib, &sios_zlib)); if (rc != SIO_OK) return; EVAL0(sio_configure_stage(sio, sios_fd, "buflen", &buflen)); if (rc != SIO_OK) return; EVAL0(sio_configure_stage(sio, sios_zlib, "outputsize", &bufsize)); if (rc != SIO_OK) return; EVAL0(sio_configure_stage(sio, sios_zlib, "inputsize", &bufsize)); if (rc != SIO_OK) return; EVAL0(sio_configure_stage(sio, sios_zlib, "outputlevel", &zoutlevel)); if (rc != SIO_OK) return; EVAL0(sio_configure_stage(sio, sios_zlib, "inputlevel", &zinlevel)); if (rc != SIO_OK) return; /* * WRITE phase */ mktemp(tempfile); fd = open(tempfile, O_CREAT|O_EXCL|O_WRONLY, 0600); if (fd < 0) { ts_test_fail(TS_CTX, "cannot create temporary file \"%s\" (%s)\n", tempfile, strerror(errno)); } else { do_unlink = 1; EVAL0(sio_configure_stage(sio, sios_fd, "fd", &fd)); if (rc != SIO_OK) goto badwrite; EVAL0(sio_attach(sio, sios_fd, SIO_MODE_READWRITE)); if (rc != SIO_OK) goto badwrite; EVAL0(sio_attach(sio, sios_zlib, SIO_MODE_READWRITE)); if (rc != SIO_OK) goto badwrite2; for (i=0; i ** Copyright (c) 2002-2003 The OSSP Project ** Copyright (c) 2002-2003 Ralf S. Engelschall @ 1.18 log @make pipes work on older systems (aka Linux) @ text @d156 11 a166 3 if (status != 0) { ts_test_fail(TS_CTX, "child returned status %08lx\n", status); d1148 11 a1158 3 if (status != 0) { ts_test_fail(TS_CTX, "child returned status %08lx\n", status); @ 1.17 log @fix left-overs from old EVAL0 macro fix return values from callback @ text @d147 2 a149 2 result = (*server)(NULL, pd[0], wcount); close(pd[0]); d152 2 a154 2 (*client)(_t, pd[1], wcount); close(pd[1]); @ 1.16 log @drop sleep() calls it's a BIO adapter, not necessarily a SSL adapter @ text @d90 4 d115 1 a115 1 typedef int (*func)(ts_test_t *, int, int); d319 1 a319 1 EVAL0(rc = sio_destroy(sio)); d660 1 a660 1 EVAL0(rc = sio_destroy(C_sio)); d1217 1 a1217 1 return; d1300 1 a1300 1 return; @ 1.15 log @add BIO(_ssl) test case @ text @a142 3 sleep(1); a1121 3 sleep(1); a1124 1 d1386 1 a1386 1 ts_suite_test(ts, test_sio_bio, "stream I/O ssl adapter"); @ 1.14 log @add SA library test case @ text @d41 1 d80 2 a81 2 #define EVAL0(name,block) EVAL(name,rc,SIO_OK,block,sio_error) #define EVALS(name,block) EVAL(name,rc,SA_OK,block,sa_error) d87 2 a88 2 static int test_sio_hello_client(ts_test_t *, int); static int test_sio_hello_server(ts_test_t *, int); d99 2 d111 51 d172 1 a172 3 EVAL0("sio_create", { rc = sio_create(&sio); }); d174 1 a174 3 EVAL0("sio_create_stage(&sios_hole)", { rc = sio_create_stage(sio, &sio_module_hole, &sios_hole); }); d176 1 a176 3 EVAL0("sio_create_stage(&sios_buffer)", { rc = sio_create_stage(sio, &sio_module_buffer, &sios_buffer); }); d179 1 a179 3 EVAL0("sio_configure_stage(sios_buffer, outputsize)", { rc = sio_configure_stage(sio, sios_buffer, "outputsize", &bufsize); }); d182 1 a182 3 EVAL0("sio_attach(sios_hole)", { rc = sio_attach(sio, sios_hole, SIO_MODE_WRITE); }); d184 1 a184 3 EVAL0("sio_attach(sios_buffer)", { rc = sio_attach(sio, sios_buffer, SIO_MODE_WRITE); }); d188 1 a188 3 EVAL0("sio_write", { rc = sio_write(sio, S, len, &actual); }); d197 5 a201 16 EVAL0("sio_detach(sios_hole)", { rc = sio_detach(sio, sios_hole); }); EVAL0("sio_detach(sios_buffer)", { rc = sio_detach(sio, sios_buffer); }); EVAL0("sio_destroy_stage", { rc = sio_destroy_stage(sio, sios_buffer); }); EVAL0("sio_destroy_stage(sios_hole)", { rc = sio_destroy_stage(sio, sios_hole); }); EVAL0("sio_destroy", { rc = sio_destroy(sio); }); d219 11 a229 24 EVAL0("sio_create", { rc = sio_create(&sio); }); if (rc != SIO_OK) return; EVAL0("sio_create_stage(&sios_fd)", { rc = sio_create_stage(sio, &sio_module_fd, &sios_fd); }); if (rc != SIO_OK) return; EVAL0("sio_create_stage(&sios_buffer)", { rc = sio_create_stage(sio, &sio_module_buffer, &sios_buffer); }); if (rc != SIO_OK) return; EVAL0("sio_configure_stage(sios_fd, buflen)", { rc = sio_configure_stage(sio, sios_fd, "buflen", &buflen); }); if (rc != SIO_OK) return; EVAL0("sio_configure_stage(sios_buffer)", { rc = sio_configure_stage(sio, sios_buffer, "outputsize", &bufsize); }); if (rc != SIO_OK) return; EVAL0("sio_configure_stage(sios_buffer, inputsize)", { rc = sio_configure_stage(sio, sios_buffer, "inputsize", &bufsize); }); d243 1 a243 3 EVAL0("sio_configure_stage(sios_fd, fd)", { rc = sio_configure_stage(sio, sios_fd, "fd", &fd); }); d245 1 a245 3 EVAL0("sio_attach(sios_fd)", { rc = sio_attach(sio, sios_fd, SIO_MODE_READWRITE); }); d247 1 a247 3 EVAL0("sio_attach(sios_buffer)", { rc = sio_attach(sio, sios_buffer, SIO_MODE_READWRITE); }); d251 1 a251 3 EVAL0("sio_write", { rc = sio_write(sio, S, len, &actual); }); d260 2 a261 7 EVAL0("sio_push", { rc = sio_push(sio); }); EVAL0("sio_detach(sios_buffer)", { rc = sio_detach(sio, sios_buffer); }); d264 1 a264 3 EVAL0("sio_detach(sios_fd)", { rc = sio_detach(sio, sios_fd); }); d275 1 a275 3 EVAL0("sio_configure_stage(sios_fd, fd)", { rc = sio_configure_stage(sio, sios_fd, "fd", &fd); }); d277 1 a277 4 EVAL0("sio_attach(sios_fd)", { rc = sio_attach(sio, sios_fd, SIO_MODE_READWRITE); }); d279 1 a279 3 EVAL0("sio_attach(sios_buffer)", { rc = sio_attach(sio, sios_buffer, SIO_MODE_READWRITE); }); d283 1 a283 3 EVAL0("sio_read", { rc = sreadloop(sio, buf, len, &actual); }); d298 1 a298 3 EVAL0("sio_detach(sios_buffer)", { rc = sio_detach(sio, sios_buffer); }); d301 1 a301 3 EVAL0("sio_detach(sios_fd)", { rc = sio_detach(sio, sios_fd); }); d316 3 a318 9 EVAL0("sio_destroy_stage", { rc = sio_destroy_stage(sio, sios_buffer); }); EVAL0("sio_destroy_stage(sios_fd)", { rc = sio_destroy_stage(sio, sios_fd); }); EVAL0("sio_destroy", { rc = sio_destroy(sio); }); d335 1 a335 3 EVAL0("sio_create", { rc = sio_create(&sio); }); d337 1 a337 3 EVAL0("sio_create_stage(&sios_fd)", { rc = sio_create_stage(sio, &sio_module_fd, &sios_fd); }); d339 1 a339 3 EVAL0("sio_create_stage(&sios_buffer)", { rc = sio_create_stage(sio, &sio_module_buffer, &sios_buffer); }); d341 1 a341 4 EVAL0("sio_configure_stage(sios_fd, buflen)", { rc = sio_configure_stage(sio, sios_fd, "buflen", &buflen); }); d343 1 a343 3 EVAL0("sio_configure_stage(sios_buffer)", { rc = sio_configure_stage(sio, sios_buffer, "outputsize", &buflen); }); d345 1 a345 3 EVAL0("sio_configure_stage(sios_buffer, inputsize)", { rc = sio_configure_stage(sio, sios_buffer, "inputsize", &bufsize); }); d347 1 a347 4 EVAL0("sio_configure_stage(sios_fd, fd)", { rc = sio_configure_stage(sio, sios_fd, "fd", &fd); }); d349 1 a349 4 EVAL0("sio_attach(sios_fd)", { rc = sio_attach(sio, sios_fd, SIO_MODE_READWRITE); }); d351 1 a351 3 EVAL0("sio_attach(sios_buffer)", { rc = sio_attach(sio, sios_buffer, SIO_MODE_READWRITE); }); d355 5 a359 5 EVAL0("sio_read", { rc = sreadloop(sio, buf, len, &actual); }); if (rc != SIO_OK) error = 1; if (rc != SIO_OK) break; d363 1 d370 1 d375 1 a375 3 EVAL0("sio_detach(sios_buffer)", { rc = sio_detach(sio, sios_buffer); }); a376 1 d380 1 a380 4 EVAL0("sio_detach(sios_fd)", { rc = sio_detach(sio, sios_fd); }); d384 5 a388 12 EVAL0("sio_destroy_stage", { rc = sio_destroy_stage(sio, sios_buffer); }); if (rc != SIO_OK) result = -1; EVAL0("sio_destroy_stage(sios_fd)", { rc = sio_destroy_stage(sio, sios_fd); }); if (rc != SIO_OK) result = -1; EVAL0("sio_destroy", { rc = sio_destroy(sio); }); d407 12 a418 24 EVAL0("sio_create", { rc = sio_create(&sio); }); if (rc != SIO_OK) return -1; EVAL0("sio_create_stage(&sios_fd)", { rc = sio_create_stage(sio, &sio_module_fd, &sios_fd); }); if (rc != SIO_OK) return -1; EVAL0("sio_create_stage(&sios_buffer)", { rc = sio_create_stage(sio, &sio_module_buffer, &sios_buffer); }); if (rc != SIO_OK) return -1; EVAL0("sio_configure_stage(sios_fd, buflen)", { rc = sio_configure_stage(sio, sios_fd, "buflen", &buflen); }); if (rc != SIO_OK) return -1; EVAL0("sio_configure_stage(sios_buffer)", { rc = sio_configure_stage(sio, sios_buffer, "outputsize", &buflen); }); if (rc != SIO_OK) return -1; EVAL0("sio_configure_stage(sios_buffer, inputsize)", { rc = sio_configure_stage(sio, sios_buffer, "inputsize", &bufsize); }); d425 1 a425 3 EVAL0("sio_configure_stage(sios_fd, fd)", { rc = sio_configure_stage(sio, sios_fd, "fd", &fd); }); d427 1 a427 3 EVAL0("sio_attach(sios_fd)", { rc = sio_attach(sio, sios_fd, SIO_MODE_READWRITE); }); d429 1 a429 3 EVAL0("sio_attach(sios_buffer)", { rc = sio_attach(sio, sios_buffer, SIO_MODE_READWRITE); }); d433 5 a437 5 EVAL0("sio_write", { rc = sio_write(sio, S, len, &actual); }); if (rc != SIO_OK) error = 1; if (rc != SIO_OK) break; d441 1 d446 1 a446 3 EVAL0("sio_push", { rc = sio_push(sio); }); d448 1 a448 4 EVAL0("sio_detach(sios_buffer)", { rc = sio_detach(sio, sios_buffer); }); a449 1 d453 1 a453 3 EVAL0("sio_detach(sios_fd)", { rc = sio_detach(sio, sios_fd); }); d457 5 a461 16 /* * common cleanup */ EVAL0("sio_destroy_stage", { rc = sio_destroy_stage(sio, sios_buffer); }); if (rc != SIO_OK) result = -1; EVAL0("sio_destroy_stage(sios_fd)", { rc = sio_destroy_stage(sio, sios_fd); }); if (rc != SIO_OK) result = -1; EVAL0("sio_destroy", { rc = sio_destroy(sio); }); d469 1 a469 38 pid_t child; int pd[2]; int wcount = 147; int status; fflush(stdout); fflush(stderr); if (pipe(pd) == -1) { ts_test_fail(TS_CTX, "cannot create pipe (%s)\n", strerror(errno)); } child = fork(); if (child == -1) { ts_test_fail(TS_CTX, "cannot fork (%s)\n", strerror(errno)); } if (child == 0) { int result; sleep(1); close(pd[1]); result = test_sio_pipe_write(NULL, pd[0], wcount); close(pd[0]); exit(result ? 1 : 0); } else { close(pd[0]); test_sio_pipe_read(_t, pd[1], wcount); close(pd[1]); waitpid(child, &status, 0); if (status != 0) { ts_test_fail(TS_CTX, "child returned status %08lx\n", status); } } d522 17 a538 35 EVAL0("sio_create(&A_sio)", { rc = sio_create(&A_sio); }); if (rc != SIO_OK) return; EVAL0("sio_create_stage(&A_sios_fd)", { rc = sio_create_stage(A_sio, &sio_module_fd, &A_sios_fd); }); if (rc != SIO_OK) return; EVAL0("sio_configure_stage(A_sios_fd, fd)", { rc = sio_configure_stage(A_sio, A_sios_fd, "fd", &fd); }); if (rc != SIO_OK) return; EVAL0("sio_configure_stage(A_sios_fd, buflen)", { rc = sio_configure_stage(A_sio, A_sios_fd, "buflen", &buflen); }); if (rc != SIO_OK) return; EVAL0("sio_create_stage(&A_sios_sillymux)", { rc = sio_create_stage(A_sio, &sio_module_sillymux, &A_sios_sillymux); }); if (rc != SIO_OK) return; EVAL0("sio_configure_stage(A_sios_sillymux, oddlabel)", { rc = sio_configure_stage(A_sio, A_sios_sillymux, "oddlabel", ODD); }); if (rc != SIO_OK) return; EVAL0("sio_configure_stage(A_sios_sillymux, evenlabel)", { rc = sio_configure_stage(A_sio, A_sios_sillymux, "evenlabel", EVEN); }); if (rc != SIO_OK) return; EVAL0("sio_attach(A_sios_fd)", { rc = sio_attach(A_sio, A_sios_fd, SIO_MODE_READWRITE); }); if (rc != SIO_OK) return; EVAL0("sio_attach(A_sios_sillymux)", { rc = sio_attach(A_sio, A_sios_sillymux, SIO_MODE_READWRITE); }); d544 9 a552 19 EVAL0("sio_create(&B_sio)", { rc = sio_create(&B_sio); }); if (rc != SIO_OK) return; EVAL0("sio_create_stage(&B_sios_sio)", { rc = sio_create_stage(B_sio, &sio_module_sio, &B_sios_sio); }); if (rc != SIO_OK) return; EVAL0("sio_configure_stage(B_sios_sio, upstream)", { rc = sio_configure_stage(B_sio, B_sios_sio, "upstream", A_sio); }); if (rc != SIO_OK) return; EVAL0("sio_configure_stage(B_sios_sio, mydatalabel)", { rc = sio_configure_stage(B_sio, B_sios_sio, "mydatalabel", ODD); }); if (rc != SIO_OK) return; EVAL0("sio_attach(B_sios_sio)", { rc = sio_attach(B_sio, B_sios_sio, SIO_MODE_READWRITE); }); d558 9 a566 19 EVAL0("sio_create(&C_sio)", { rc = sio_create(&C_sio); }); if (rc != SIO_OK) return; EVAL0("sio_create_stage(&C_sios_sio)", { rc = sio_create_stage(C_sio, &sio_module_sio, &C_sios_sio); }); if (rc != SIO_OK) return; EVAL0("sio_configure_stage(C_sios_sio, upstream)", { rc = sio_configure_stage(C_sio, C_sios_sio, "upstream", A_sio); }); if (rc != SIO_OK) return; EVAL0("sio_configure_stage(C_sios_sio, mydatalabel)", { rc = sio_configure_stage(C_sio, C_sios_sio, "mydatalabel", EVEN); }); if (rc != SIO_OK) return; EVAL0("sio_attach(C_sios_sio)", { rc = sio_attach(C_sio, C_sios_sio, SIO_MODE_READWRITE); }); d588 4 a591 7 EVAL0("sio_read(B_sio)", { rc = sreadloop(B_sio, buf, sizeof(buf), &actual); if (rc == SIO_ERR_EOF) { --nstreams; rc = SIO_OK; } }); d615 4 a618 7 EVAL0("sio_read(C_sio)", { rc = sreadloop(C_sio, buf, sizeof(buf), &actual); if (rc == SIO_ERR_EOF) { --nstreams; rc = SIO_OK; } }); d657 3 a659 9 EVAL0("sio_detach(C_sios_sio)", { rc = sio_detach(C_sio, C_sios_sio); }); EVAL0("sio_destroy_stage(C_sios_sio)", { rc = sio_destroy_stage(C_sio, C_sios_sio); }); EVAL0("sio_destroy(C_sio)", { rc = sio_destroy(C_sio); }); d664 3 a666 9 EVAL0("sio_detach(B_sios_sio)", { rc = sio_detach(B_sio, B_sios_sio); }); EVAL0("sio_destroy_stage(B_sios_sio)", { rc = sio_destroy_stage(B_sio, B_sios_sio); }); EVAL0("sio_destroy(B_sio)", { rc = sio_destroy(B_sio); }); d671 5 a675 15 EVAL0("sio_detach(A_sios_sillymux)", { rc = sio_detach(A_sio, A_sios_sillymux); }); EVAL0("sio_detach(A_sios_fd)", { rc = sio_detach(A_sio, A_sios_fd); }); EVAL0("sio_destroy_stage(A_sios_sillymux)", { rc = sio_destroy_stage(A_sio, A_sios_sillymux); }); EVAL0("sio_destroy_stage(A_sios_fd)", { rc = sio_destroy_stage(A_sio, A_sios_fd); }); EVAL0("sio_destroy(A_sio)", { rc = sio_destroy(A_sio); }); d686 1 a686 1 int test_sio_hello_client(ts_test_t *_t, int fd) d743 1 a743 1 int test_sio_hello_server(ts_test_t *_t, int fd) d753 1 a753 3 EVAL0("sio_create", { rc = sio_create(&sio); }); d755 1 a755 3 EVAL0("sio_create_stage(&sios_fd)", { rc = sio_create_stage(sio, &sio_module_fd, &sios_fd); }); d757 1 a757 3 EVAL0("sio_create_stage(&sios_hello)", { rc = sio_create_stage(sio, &sio_module_hello, &sios_hello); }); d759 1 a759 4 EVAL0("sio_configure_stage(sios_fd, buflen)", { rc = sio_configure_stage(sio, sios_fd, "buflen", &buflen); }); d762 1 a762 3 EVAL0("sio_configure_stage(sios_fd, fd)", { rc = sio_configure_stage(sio, sios_fd, "fd", &fd); }); d764 1 a764 3 EVAL0("sio_attach(sios_fd)", { rc = sio_attach(sio, sios_fd, SIO_MODE_READWRITE); }); d766 1 a766 3 EVAL0("sio_attach(sios_hello)", { rc = sio_attach(sio, sios_hello, SIO_MODE_READWRITE); }); d768 1 a769 3 EVAL0("sio_write", { rc = sio_write(sio, S, len, &actual); }); d771 1 a771 3 EVAL0("sio_push", { rc = sio_push(sio); }); d773 1 a773 4 EVAL0("sio_detach(sios_hello)", { rc = sio_detach(sio, sios_hello); }); d779 1 a779 3 EVAL0("sio_detach(sios_fd)", { rc = sio_detach(sio, sios_fd); }); d788 5 a792 11 EVAL0("sio_destroy_stage", { rc = sio_destroy_stage(sio, sios_hello); }); if (rc != SIO_OK) result = -1; EVAL0("sio_destroy_stage(sios_fd)", { rc = sio_destroy_stage(sio, sios_fd); }); if (rc != SIO_OK) result = -1; EVAL0("sio_destroy", { rc = sio_destroy(sio); }); d800 1 a800 37 pid_t child; int pd[2]; int status; fflush(stdout); fflush(stderr); if (socketpair(AF_UNIX, SOCK_STREAM, 0, pd) == -1) { ts_test_fail(TS_CTX, "cannot create pipe (%s)\n", strerror(errno)); } child = fork(); if (child == -1) { ts_test_fail(TS_CTX, "cannot fork (%s)\n", strerror(errno)); } if (child == 0) { int result; sleep(1); close(pd[1]); result = test_sio_hello_client(NULL, pd[0]); close(pd[0]); exit(result ? 1 : 0); } else { close(pd[0]); test_sio_hello_server(_t, pd[1]); close(pd[1]); waitpid(child, &status, 0); if (status != 0) { ts_test_fail(TS_CTX, "child returned status %08lx\n", status); } } a802 1 d821 15 a835 32 EVAL0("sio_create", { rc = sio_create(&sio); }); if (rc != SIO_OK) return; EVAL0("sio_create_stage(&sios_fd)", { rc = sio_create_stage(sio, &sio_module_fd, &sios_fd); }); if (rc != SIO_OK) return; EVAL0("sio_create_stage(&sios_zlib)", { rc = sio_create_stage(sio, &sio_module_zlib, &sios_zlib); }); if (rc != SIO_OK) return; EVAL0("sio_configure_stage(sios_fd, buflen)", { rc = sio_configure_stage(sio, sios_fd, "buflen", &buflen); }); if (rc != SIO_OK) return; EVAL0("sio_configure_stage(sios_zlib)", { rc = sio_configure_stage(sio, sios_zlib, "outputsize", &bufsize); }); if (rc != SIO_OK) return; EVAL0("sio_configure_stage(sios_zlib, inputsize)", { rc = sio_configure_stage(sio, sios_zlib, "inputsize", &bufsize); }); if (rc != SIO_OK) return; EVAL0("sio_configure_stage(sios_zlib, outputlevel)", { rc = sio_configure_stage(sio, sios_zlib, "outputlevel", &zoutlevel); }); if (rc != SIO_OK) return; EVAL0("sio_configure_stage(sios_zlib, inputlevel)", { rc = sio_configure_stage(sio, sios_zlib, "inputlevel", &zinlevel); }); d849 1 a849 3 EVAL0("sio_configure_stage(sios_fd, fd)", { rc = sio_configure_stage(sio, sios_fd, "fd", &fd); }); d851 1 a851 3 EVAL0("sio_attach(sios_fd)", { rc = sio_attach(sio, sios_fd, SIO_MODE_READWRITE); }); d853 1 a853 3 EVAL0("sio_attach(sios_zlib)", { rc = sio_attach(sio, sios_zlib, SIO_MODE_READWRITE); }); d857 1 a857 3 EVAL0("sio_write", { rc = sio_write(sio, S, len, &actual); }); d866 2 a867 7 EVAL0("sio_push", { rc = sio_push(sio); }); EVAL0("sio_detach(sios_zlib)", { rc = sio_detach(sio, sios_zlib); }); d870 1 a870 3 EVAL0("sio_detach(sios_fd)", { rc = sio_detach(sio, sios_fd); }); d881 1 a881 3 EVAL0("sio_configure_stage(sios_fd, fd)", { rc = sio_configure_stage(sio, sios_fd, "fd", &fd); }); d883 1 a883 4 EVAL0("sio_attach(sios_fd)", { rc = sio_attach(sio, sios_fd, SIO_MODE_READWRITE); }); d885 1 a885 3 EVAL0("sio_attach(sios_zlib)", { rc = sio_attach(sio, sios_zlib, SIO_MODE_READWRITE); }); d889 1 a889 3 EVAL0("sio_read", { rc = sreadloop(sio, buf, len, &actual); }); d904 1 a904 3 EVAL0("sio_detach(sios_zlib)", { rc = sio_detach(sio, sios_zlib); }); d907 1 a907 3 EVAL0("sio_detach(sios_fd)", { rc = sio_detach(sio, sios_fd); }); d922 3 a924 9 EVAL0("sio_destroy_stage", { rc = sio_destroy_stage(sio, sios_zlib); }); EVAL0("sio_destroy_stage(sios_fd)", { rc = sio_destroy_stage(sio, sios_fd); }); EVAL0("sio_destroy", { rc = sio_destroy(sio); }); d943 1 a943 3 EVAL0("sio_create", { rc = sio_create(&sio); }); d945 1 a945 3 EVAL0("sio_create_stage(&sios_sa)", { rc = sio_create_stage(sio, &sio_module_sa, &sios_sa); }); d947 1 a947 3 EVAL0("sio_create_stage(&sios_buffer)", { rc = sio_create_stage(sio, &sio_module_buffer, &sios_buffer); }); d949 1 a949 4 EVAL0("sio_configure_stage(sios_sa, buflen)", { rc = sio_configure_stage(sio, sios_sa, "buflen", &buflen); }); d951 1 a951 3 EVAL0("sio_configure_stage(sios_buffer)", { rc = sio_configure_stage(sio, sios_buffer, "outputsize", &buflen); }); d953 1 a953 3 EVAL0("sio_configure_stage(sios_buffer, inputsize)", { rc = sio_configure_stage(sio, sios_buffer, "inputsize", &bufsize); }); d956 1 a956 3 EVAL0("sio_configure_stage(sios_sa, sa)", { rc = sio_configure_stage(sio, sios_sa, "sa", sa); }); d958 1 a958 4 EVAL0("sio_attach(sios_sa)", { rc = sio_attach(sio, sios_sa, SIO_MODE_READWRITE); }); d960 1 a960 3 EVAL0("sio_attach(sios_buffer)", { rc = sio_attach(sio, sios_buffer, SIO_MODE_READWRITE); }); d964 5 a968 5 EVAL0("sio_read", { rc = sreadloop(sio, buf, len, &actual); }); if (rc != SIO_OK) error = 1; if (rc != SIO_OK) break; d972 1 d979 1 d984 1 a984 3 EVAL0("sio_detach(sios_buffer)", { rc = sio_detach(sio, sios_buffer); }); d990 1 a990 4 EVAL0("sio_detach(sios_sa)", { rc = sio_detach(sio, sios_sa); }); d994 5 a998 12 EVAL0("sio_destroy_stage", { rc = sio_destroy_stage(sio, sios_buffer); }); if (rc != SIO_OK) result = -1; EVAL0("sio_destroy_stage(sios_sa)", { rc = sio_destroy_stage(sio, sios_sa); }); if (rc != SIO_OK) result = -1; EVAL0("sio_destroy", { rc = sio_destroy(sio); }); d1017 11 a1027 24 EVAL0("sio_create", { rc = sio_create(&sio); }); if (rc != SIO_OK) return -1; EVAL0("sio_create_stage(&sios_sa)", { rc = sio_create_stage(sio, &sio_module_sa, &sios_sa); }); if (rc != SIO_OK) return -1; EVAL0("sio_create_stage(&sios_buffer)", { rc = sio_create_stage(sio, &sio_module_buffer, &sios_buffer); }); if (rc != SIO_OK) return -1; EVAL0("sio_configure_stage(sios_sa, buflen)", { rc = sio_configure_stage(sio, sios_sa, "buflen", &buflen); }); if (rc != SIO_OK) return -1; EVAL0("sio_configure_stage(sios_buffer)", { rc = sio_configure_stage(sio, sios_buffer, "outputsize", &buflen); }); if (rc != SIO_OK) return -1; EVAL0("sio_configure_stage(sios_buffer, inputsize)", { rc = sio_configure_stage(sio, sios_buffer, "inputsize", &bufsize); }); d1034 1 a1034 3 EVAL0("sio_configure_stage(sios_sa, sa)", { rc = sio_configure_stage(sio, sios_sa, "sa", sa); }); d1036 1 a1036 3 EVAL0("sio_attach(sios_sa)", { rc = sio_attach(sio, sios_sa, SIO_MODE_READWRITE); }); d1038 1 a1038 3 EVAL0("sio_attach(sios_buffer)", { rc = sio_attach(sio, sios_buffer, SIO_MODE_READWRITE); }); d1042 5 a1046 5 EVAL0("sio_write", { rc = sio_write(sio, S, len, &actual); }); if (rc != SIO_OK) error = 1; if (rc != SIO_OK) break; d1050 1 d1055 1 a1055 3 EVAL0("sio_push", { rc = sio_push(sio); }); d1057 1 a1057 4 EVAL0("sio_detach(sios_buffer)", { rc = sio_detach(sio, sios_buffer); }); a1058 1 d1062 1 a1062 3 EVAL0("sio_detach(sios_sa)", { rc = sio_detach(sio, sios_sa); }); d1071 5 a1075 11 EVAL0("sio_destroy_stage", { rc = sio_destroy_stage(sio, sios_buffer); }); if (rc != SIO_OK) result = -1; EVAL0("sio_destroy_stage(sios_sa)", { rc = sio_destroy_stage(sio, sios_sa); }); if (rc != SIO_OK) result = -1; EVAL0("sio_destroy", { rc = sio_destroy(sio); }); d1093 1 a1093 3 EVALS("sa_create(sa_server)", { rc = sa_create(&sa_server); }); d1095 1 a1095 3 EVALS("sa_timeout(sa_server, SA_TIMEOUT_ALL, 5, 0)", { rc = sa_timeout(sa_server, SA_TIMEOUT_ALL, 5, 0); }); d1097 1 a1097 3 EVALS("sa_option(sa_server, SA_OPTION_REUSEADDR, 1)", { rc = sa_option(sa_server, SA_OPTION_REUSEADDR, 1); }); d1099 1 a1099 3 EVALS("sa_addr_create(&saa_b)", { rc = sa_addr_create(&saa_b); }); d1101 1 a1101 3 EVALS("sa_addr_u2a(saa_b, uri)", { rc = sa_addr_u2a(saa_b, "inet://127.0.0.1:0"); }); d1103 1 a1103 3 EVALS("sa_bind(sa_server, saa_b)", { rc = sa_bind(sa_server, saa_b); }); d1105 1 a1105 3 EVALS("sa_listen(sa_server, 128)", { rc = sa_listen(sa_server, 128); }); d1107 1 a1107 3 EVALS("sa_getlocal(sa_server, &saa_p)", { rc = sa_getlocal(sa_server, &saa_p); }); d1109 1 a1109 3 EVALS("sa_create(sa_client)", { rc = sa_create(&sa_client); }); d1111 1 a1111 3 EVALS("sa_timeout(sa_client, SA_TIMEOUT_ALL, 5, 0)", { rc = sa_timeout(sa_client, SA_TIMEOUT_ALL, 5, 0); }); d1118 1 d1138 1 a1138 3 EVALS("sa_connect(sa_client, saa_p)", { rc = sa_connect(sa_client, saa_p); }); d1150 1 a1150 1 sa_destroy(sa_client); d1152 1 a1152 1 sa_addr_destroy(saa_p); d1154 1 a1154 1 sa_addr_destroy(saa_b); d1156 1 a1156 1 sa_destroy(sa_server); d1164 203 d1369 1 d1377 2 @ 1.13 log @test zlib module @ text @d72 1 a72 1 #define EVAL(name,rc,rc0,block) \ d77 1 a77 1 name, rc, sio_error(rc), rc0, sio_error(rc0)) d79 2 a80 1 #define EVAL0(name,block) EVAL(name,rc,SIO_OK,block) d576 3 d1039 3 d1236 214 d1452 97 d1550 1 @ 1.12 log @add protocol test, client-server connection via socketpair() @ text @d207 1 a207 1 rc = sio_configure_stage(sio, sios_buffer, "outputsize", &buflen); d1055 170 @ 1.11 log @some explanations @ text @d44 1 d81 3 a83 3 sio_rc_t readloop(sio_t *, char *, size_t, size_t *); int test_sio_pipe_read(ts_test_t *, int, int); int test_sio_pipe_write(ts_test_t *, int, int); d85 4 a88 1 sio_rc_t readloop(sio_t *sio, char *buf, size_t len, size_t *actualp) d289 1 a289 1 rc = readloop(sio, buf, len, &actual); d338 1 d394 1 a394 1 rc = readloop(sio, buf, len, &actual); d443 1 d746 1 a746 1 rc = readloop(B_sio, buf, sizeof(buf), &actual); d776 1 a776 1 rc = readloop(C_sio, buf, sizeof(buf), &actual); d870 143 d1015 34 d1050 1 @ 1.10 log @better stream reading @ text @d722 10 @ 1.9 log @functional multiplex test for reading @ text @d99 1 d725 1 a725 1 while (nodd < wcount || neven < wcount) { d752 2 d782 2 d789 1 a789 7 if (nstreams == 0) { if (neven != wcount || ceven != 0 || nodd != wcount || codd != 0) { ts_test_fail(TS_CTX, "data missing from streams\n"); } a790 1 } d792 8 @ 1.8 log @test suite (still incomplete) @ text @d36 1 d42 3 d76 1 a76 1 rc, sio_error(rc), rc0, sio_error(rc0)) d80 4 d86 1 a86 1 sio_rc_t rc; d333 212 d547 35 d586 260 d852 1 d856 1 @ 1.7 log @make external references optional @ text @d28 1 a28 1 ** sio_test.c: test suite a34 4 #ifndef ENABLE_BIO #error Test requires BIO + SSL #endif d36 4 d41 1 d45 1 a45 2 #include "sa.h" a48 1 a49 4 extern sio_module_t sio_module_hello; extern sio_module_t sio_module_buffer; #ifndef SINK extern sio_module_t sio_module_sa; d52 3 a54 13 #define e(f) rc = f; printf("%s = %s\n",#f, sio_error(rc)); fflush(stdout); #define s(f) src = f; printf("%s = %s\n",#f, sa_error(src)); fflush(stdout); #define n(f) rn = f; printf("%s = %d\n",#f, rn); fflush(stdout); #define p(f) rp = f; printf("%s = %p\n",#f, rp); fflush(stdout); int main(int argc, char *argv[]) { int rn; void *rp; sio_rc_t rc; sio_t *sio; #ifndef SINK sio_stage_t *sios_sa; a55 1 sio_stage_t *sios_bio, *sios_hello, *sios_buffer; d57 8 a64 4 sa_rc_t src; sa_addr_t *saa; sa_t *msa, *sa; char *uri; a65 6 int fd; SSL_CTX *ctx; #ifdef SINK BIO *bio; #endif BIO *sbio; d67 6 a72 1 char buf[] = "Hello world\n"; d74 1 a74 4 size_t actual; size_t buflen; int no = 0; int yes = 1; d76 4 a79 2 s(sa_create(&msa)); s(sa_option(msa, SA_OPTION_REUSEADDR, 1)); d81 8 a88 6 s(sa_addr_create(&saa)); uri = "inet://localhost:25001#tcp"; s(sa_addr_u2a(saa, uri)); s(sa_bind(msa,saa)); s(sa_addr_destroy(saa)); uri = NULL; d90 3 a92 3 ERR_load_BIO_strings(); OpenSSL_add_ssl_algorithms(); ctx = SSL_CTX_new(SSLv23_server_method()); d94 48 a141 4 if (!SSL_CTX_use_certificate_file(ctx, "/u/mlelstv/ssl/server.crt", SSL_FILETYPE_PEM)) exit(98); if (!SSL_CTX_use_PrivateKey_file(ctx, "/u/mlelstv/ssl/server.key", SSL_FILETYPE_PEM)) exit(99); d143 17 a159 7 e(sio_create(&sio)); 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)); #ifndef SINK e(sio_create_stage(sio, &sio_module_sa, &sios_sa)); #endif d161 89 a249 2 buflen = 256; e(sio_configure_stage(sio, sios_bio, "inputsize", &buflen)); d251 3 a253 2 buflen = 1000; e(sio_configure_stage(sio, sios_buffer, "outputsize", &buflen)); d255 45 a299 1 s(sa_listen(msa, 5)); d301 3 a303 1 for(;;) { d305 4 a308 4 s(sa_accept(msa, &saa, &sa)); s(sa_addr_a2u(saa, &uri)); printf("Connection from %s\n",uri); s(sa_addr_destroy(saa)); d310 14 a323 2 p(sbio = BIO_new_ssl(ctx,0)); e(sio_configure_stage(sio, sios_bio, "bio", sbio)); d325 3 a327 11 #ifdef SINK s(sa_getfd(sa, &fd)); p(bio = BIO_new_socket(fd, 0)); p(BIO_push(sbio,bio)); #else e(sio_configure_stage(sio, sios_sa, "sa", sa)); buflen = 256; e(sio_configure_stage(sio, sios_sa, "buflen", &buflen)); e(sio_configure_stage(sio, sios_bio, "issink", &no)); #endif e(sio_configure_stage(sio, sios_bio, "freebio", &yes)); d329 3 d333 3 a335 6 #ifndef SINK e(sio_attach(sio, sios_sa, SIO_MODE_READWRITE)); #endif e(sio_attach(sio, sios_bio, SIO_MODE_READWRITE)); e(sio_attach(sio, sios_hello, SIO_MODE_READWRITE)); e(sio_attach(sio, sios_buffer, SIO_MODE_WRITE)); d337 3 a339 2 e(sio_write(sio, buf, sizeof(buf)-1, &actual)); e(sio_push(sio)); d341 4 a344 5 e(sio_detach(sio, sios_buffer)); e(sio_detach(sio, sios_hello)); e(sio_detach(sio, sios_bio)); #ifndef SINK e(sio_detach(sio, sios_sa)); d347 4 a350 6 #ifdef SINK BIO_pop(bio); #endif /* BIO_free(sbio); */ #ifdef SINK BIO_free(bio); d353 4 a356 14 sa_destroy(sa); } #ifndef SINK e(sio_destroy_stage(sio, sios_sa)); #endif e(sio_destroy_stage(sio, sios_buffer)); e(sio_destroy_stage(sio, sios_hello)); e(sio_destroy_stage(sio, sios_bio)); e(sio_destroy(sio)); sa_destroy(msa); d358 18 a375 1 return 0; @ 1.6 log @- consistently use standard OSSP copyright message everywhere - strip trailing whitespaces @ text @d31 8 d45 1 @ 1.5 log @add optional shutdown function to modules. On detach, it is called and if returning SIO_OK another round through output and input is done. modules are now pushed at pipe head instead of appended so that a module can do upstream I/O while being wound up. PR: Submitted by: Reviewed by: Approved by: Obtained from: @ text @d1 30 @ 1.4 log @use BIO_f_ssl as source/sink on top of sa socket PR: Submitted by: Reviewed by: Approved by: Obtained from: @ text @d14 3 d29 3 d41 4 a44 1 BIO *bio, *sbio; d50 2 d63 1 d67 4 a70 2 SSL_CTX_use_certificate_file(ctx, "/u/mlelstv/ssl/server.crt", SSL_FILETYPE_PEM); SSL_CTX_use_PrivateKey_file(ctx, "/u/mlelstv/ssl/server.key", SSL_FILETYPE_PEM); d73 2 a74 2 e(sio_create_stage(sio, &sio_module_bio, &sios_bio)); e(sio_create_stage(sio, &sio_module_hello, &sios_hello)); d76 3 d95 4 a100 2 p(sbio = BIO_new_ssl(ctx,0)); d102 7 a109 1 e(sio_configure_stage(sio, sios_bio, "bio", sbio)); d111 5 a116 2 e(sio_attach(sio, sios_hello, SIO_MODE_READWRITE)); e(sio_attach(sio, sios_bio, SIO_MODE_READWRITE)); d121 2 d124 3 a126 2 e(sio_detach(sio, sios_hello)); e(sio_detach(sio, sios_buffer)); d128 1 d130 3 a132 1 BIO_free(sbio); d134 1 d140 3 @ 1.3 log @wrap BIO objects from libcrypto as an endpoint adjust test program to use sio_bio instead of sio_sa PR: Submitted by: Reviewed by: Approved by: Obtained from: @ text @d17 2 d22 2 d34 2 a35 1 BIO *bio; d52 6 d78 2 d81 2 a82 3 bio = BIO_new(BIO_s_socket()); sa_getfd(sa, &fd); BIO_set_fd(bio, fd, 0); d84 1 a84 1 e(sio_configure_stage(sio, sios_bio, "bio", bio)); d96 4 @ 1.2 log @snapshot - sio_strategy now has a default direction triggered by SIO_OK result - added structure tag to aid debugging - sio_hole eats all data and returns downstream (correct ?) - sio_null now uses default directio - sio_sa puts wrapper on sa objects - sio_hello.c implements a trivial protocol handler PR: Submitted by: Reviewed by: Approved by: Obtained from: @ text @d7 3 d11 1 a11 1 extern sio_module_t sio_module_sa; d22 1 a22 1 sio_stage_t *sios_sa, *sios_hello, *sios_buffer; d29 3 d48 1 a48 1 e(sio_create_stage(sio, &sio_module_sa, &sios_sa)); d53 1 a53 1 e(sio_configure_stage(sio, sios_sa, "buflen", &buflen)); d67 6 a72 1 e(sio_configure_stage(sio, sios_sa, "sa", sa)); d76 1 a76 1 e(sio_attach(sio, sios_sa, SIO_MODE_READWRITE)); d81 1 a81 1 e(sio_detach(sio, sios_sa)); d91 1 a91 1 e(sio_destroy_stage(sio, sios_sa)); @ 1.1 log @snapshot PR: Submitted by: Reviewed by: Approved by: Obtained from: @ text @d6 4 a9 1 extern sio_module_t sio_module_fd; d13 1 d19 7 a25 2 sio_stage_t *sios_fd, *sios_buffer; int fd; d27 1 d29 1 a29 1 size_t buflen = 1000; d31 9 a39 1 fd = fileno(stdout); d42 6 d49 1 a49 1 e(sio_create_stage(sio, &sio_module_buffer, &sios_buffer)); a50 2 e(sio_create_stage(sio, &sio_module_fd, &sios_fd)); e(sio_configure_stage(sio, sios_fd, "fd", &fd)); d52 10 a61 2 e(sio_attach(sio, sios_buffer, SIO_MODE_WRITE)); e(sio_attach(sio, sios_fd, SIO_MODE_WRITE)); d63 3 a65 1 e(sio_write(sio, buf, sizeof(buf)-1, &actual)); d67 9 a75 1 e(sio_push(sio)); a76 2 e(sio_detach(sio, sios_fd)); e(sio_detach(sio, sios_buffer)); a77 1 e(sio_destroy_stage(sio, sios_fd)); d79 2 d83 2 @