From ecd98efa9d5cb1c6f3e14ee5c8a97d405d3a1ef9 Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Tue, 31 Aug 2010 08:57:26 +0200 Subject: Support output fragmentation of TLS records --- src/libtls/tls_socket.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'src/libtls/tls_socket.c') diff --git a/src/libtls/tls_socket.c b/src/libtls/tls_socket.c index 6aa776879..e0c440a4c 100644 --- a/src/libtls/tls_socket.c +++ b/src/libtls/tls_socket.c @@ -96,25 +96,31 @@ METHOD(tls_application_t, build, status_t, */ static bool exchange(private_tls_socket_t *this, bool wr) { - chunk_t data; - char buf[2048]; + char buf[1024]; ssize_t len; int round = 0; for (round = 0; TRUE; round++) { - if (this->tls->build(this->tls, &data) != NEED_MORE) - { - return FALSE; - } - if (data.len) + while (TRUE) { - len = write(this->fd, data.ptr, data.len); - free(data.ptr); - if (len != data.len) + len = sizeof(buf); + switch (this->tls->build(this->tls, buf, &len, NULL)) { - return FALSE; + case NEED_MORE: + case ALREADY_DONE: + len = write(this->fd, buf, len); + if (len == -1) + { + return FALSE; + } + continue; + case INVALID_STATE: + break; + default: + return FALSE; } + break; } if (wr) { @@ -139,7 +145,7 @@ static bool exchange(private_tls_socket_t *this, bool wr) { return FALSE; } - if (this->tls->process(this->tls, chunk_create(buf, len)) != NEED_MORE) + if (this->tls->process(this->tls, buf, len) != NEED_MORE) { return FALSE; } -- cgit v1.2.3