From 2e65dafbccbfa44f585320efc0d1cca8943da627 Mon Sep 17 00:00:00 2001 From: David Garske Date: Thu, 17 Nov 2016 19:15:47 -0800 Subject: [PATCH] Fixes issue with client-tis-perf and async by splitting read wait and read (async return was waiting again and blocking). Added debug enable option. Cleanup mutex locking around total bytes, so only is done once. Fix for Makefile to include math lib (required for DH pow/log. --- tls/Makefile | 4 +++- tls/client-tls-perf.c | 12 +++++++++--- tls/server-tls-epoll-perf.c | 4 ++++ tls/server-tls-epoll-threaded.c | 12 ++++++------ 4 files changed, 22 insertions(+), 10 deletions(-) mode change 100644 => 100755 tls/Makefile mode change 100644 => 100755 tls/client-tls-perf.c mode change 100644 => 100755 tls/server-tls-epoll-perf.c mode change 100644 => 100755 tls/server-tls-epoll-threaded.c diff --git a/tls/Makefile b/tls/Makefile old mode 100644 new mode 100755 index d719b7da..859802be --- a/tls/Makefile +++ b/tls/Makefile @@ -1,6 +1,8 @@ CC=gcc CFLAGS=-Wall -LIBS=-lwolfssl +LIBS=-lwolfssl -lm +DEBUG_FLAGS=-g -DDEBUG +#CFLAGS+=$(DEBUG_FLAGS) OS_DET=UNKNOWN CPU_DET=UNKNOWN diff --git a/tls/client-tls-perf.c b/tls/client-tls-perf.c old mode 100644 new mode 100755 index 37ac93c5..50abf6f0 --- a/tls/client-tls-perf.c +++ b/tls/client-tls-perf.c @@ -56,7 +56,7 @@ /* The states of the SSL connection. */ -typedef enum SSLState { INIT, CONNECT, WRITE, READ, CLOSE } SSLState; +typedef enum SSLState { INIT, CONNECT, WRITE, READ_WAIT, READ, CLOSE } SSLState; /* Data for each active connection. */ typedef struct SSLConn { @@ -572,14 +572,16 @@ static int SSLConn_ReadWrite(SSLConn_CTX* ctx, SSLConn* sslConn) } if (ret == 1) - sslConn->state = READ; + sslConn->state = READ_WAIT; break; - case READ: + case READ_WAIT: ret = TCP_Select(sslConn->sockfd, 0); if (ret != 1) break; + sslConn->state = READ; + case READ: len = ctx->bufferLen; if (ctx->maxBytes > 0) { len = min(len, ctx->maxBytes - ctx->totalReadBytes); @@ -675,6 +677,10 @@ static int WolfSSLCtx_Init(int version, char* cert, char* key, char* verifyCert, WOLFSSL_CTX* ctx; wolfSSL_method_func method = NULL; +#ifdef DEBUG_WOLFSSL + wolfSSL_Debugging_ON(); +#endif + /* Initialize wolfSSL */ wolfSSL_Init(); diff --git a/tls/server-tls-epoll-perf.c b/tls/server-tls-epoll-perf.c old mode 100644 new mode 100755 index 574ce6fc..6125c50a --- a/tls/server-tls-epoll-perf.c +++ b/tls/server-tls-epoll-perf.c @@ -638,6 +638,10 @@ static int WolfSSLCtx_Init(int version, char* cert, char* key, char* verifyCert, WOLFSSL_CTX* ctx; wolfSSL_method_func method = NULL; +#ifdef DEBUG_WOLFSSL + wolfSSL_Debugging_ON(); +#endif + /* Initialize wolfSSL */ wolfSSL_Init(); diff --git a/tls/server-tls-epoll-threaded.c b/tls/server-tls-epoll-threaded.c old mode 100644 new mode 100755 index 849d6175..343dfe5d --- a/tls/server-tls-epoll-threaded.c +++ b/tls/server-tls-epoll-threaded.c @@ -305,18 +305,14 @@ static int SSL_Read(WOLFSSL* ssl, char* buffer, int len, int* totalBytes, pthread_mutex_lock(&sslConnMutex); *readTime += diff; + if (rwret > 0) + *totalBytes += rwret; pthread_mutex_unlock(&sslConnMutex); if (rwret == 0) { return 0; } - if (rwret > 0) { - pthread_mutex_lock(&sslConnMutex); - *totalBytes += rwret; - pthread_mutex_unlock(&sslConnMutex); - } - error = wolfSSL_get_error(ssl, 0); if (error == SSL_ERROR_WANT_READ) return 2; @@ -1194,6 +1190,10 @@ int main(int argc, char* argv[]) } } +#ifdef DEBUG_WOLFSSL + wolfSSL_Debugging_ON(); +#endif + /* Initialize wolfSSL */ wolfSSL_Init();