From f8b2906929435d439450d8ac607d8d788d66a502 Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Sat, 31 Dec 2011 12:49:18 +0100 Subject: Use the TLS socket splicing in tls_test script --- scripts/tls_test.c | 56 ++---------------------------------------------------- 1 file changed, 2 insertions(+), 54 deletions(-) (limited to 'scripts/tls_test.c') diff --git a/scripts/tls_test.c b/scripts/tls_test.c index 9e0b4e256..560c4a4ba 100644 --- a/scripts/tls_test.c +++ b/scripts/tls_test.c @@ -37,58 +37,6 @@ static void usage(FILE *out, char *cmd) fprintf(out, " %s --listen
--port --key [--cert ]+ [--times ]\n", cmd); } -/** - * Stream between stdio and TLS socket - */ -static int stream(int fd, tls_socket_t *tls) -{ - while (TRUE) - { - fd_set set; - chunk_t data; - - FD_ZERO(&set); - FD_SET(fd, &set); - FD_SET(0, &set); - - if (select(fd + 1, &set, NULL, NULL, NULL) == -1) - { - return 1; - } - if (FD_ISSET(fd, &set)) - { - if (!tls->read(tls, &data)) - { - return 0; - } - if (data.len) - { - ignore_result(write(1, data.ptr, data.len)); - free(data.ptr); - } - } - if (FD_ISSET(0, &set)) - { - char buf[1024]; - ssize_t len; - - len = read(0, buf, sizeof(buf)); - if (len == 0) - { - return 0; - } - if (len > 0) - { - if (!tls->write(tls, chunk_create(buf, len))) - { - DBG1(DBG_TLS, "TLS write error"); - return 1; - } - } - } - } -} - /** * Client routine */ @@ -119,7 +67,7 @@ static int client(host_t *host, identification_t *server, close(fd); return 1; } - res = stream(fd, tls); + res = tls->splice(tls, 0, 1) ? 0 : 1; tls->destroy(tls); close(fd); if (res) @@ -176,7 +124,7 @@ static int serve(host_t *host, identification_t *server, close(fd); return 1; } - stream(cfd, tls); + tls->splice(tls, 0, 1); DBG1(DBG_TLS, "%#H disconnected", host); tls->destroy(tls); } -- cgit v1.2.3