From 6acc9e53e1c4dda5c8c2995140d936b9706dffd3 Mon Sep 17 00:00:00 2001 From: Vic Lee Date: Sat, 25 Jun 2011 14:41:48 +0800 Subject: libfreerdp-core/openssl: fix high CPU usage when TLS is blocking. --- libfreerdp-core/crypto/openssl.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libfreerdp-core/crypto/openssl.c b/libfreerdp-core/crypto/openssl.c index 333585b..84417d7 100644 --- a/libfreerdp-core/crypto/openssl.c +++ b/libfreerdp-core/crypto/openssl.c @@ -21,6 +21,7 @@ #include "crypto.h" #include #include +#include #include "tls.h" #include "crypto/openssl.h" @@ -349,6 +350,7 @@ struct rdp_tls { SSL_CTX * ctx; SSL * ssl; + struct timespec ts; }; RD_BOOL @@ -428,6 +430,10 @@ tls_new(void) SSL_CTX_set_options(tls->ctx, SSL_OP_ALL); + /* a small 0.1ms delay when network blocking happens. */ + tls->ts.tv_sec = 0; + tls->ts.tv_nsec = 100000; + return tls; } @@ -515,6 +521,7 @@ tls_write(rdpTls * tls, char* b, int length) break; case SSL_ERROR_WANT_WRITE: + nanosleep(&tls->ts, NULL); break; default: @@ -543,6 +550,7 @@ tls_read(rdpTls * tls, char* b, int length) break; case SSL_ERROR_WANT_READ: + nanosleep(&tls->ts, NULL); break; default: -- cgit v1.2.3