From 2b62c675fa2d533eeb6f65b7ae33e6ddeb2f17a0 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Tue, 17 Dec 2013 22:10:08 +0100 Subject: Loop on recv and send operations for non-blocking sockets with OpenSSL. --- src/net/tls/openssl/TLSSocket_OpenSSL.cpp | 36 ++++++++++++++----------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'src/net/tls/openssl/TLSSocket_OpenSSL.cpp') diff --git a/src/net/tls/openssl/TLSSocket_OpenSSL.cpp b/src/net/tls/openssl/TLSSocket_OpenSSL.cpp index 8f304c78..e08041bf 100644 --- a/src/net/tls/openssl/TLSSocket_OpenSSL.cpp +++ b/src/net/tls/openssl/TLSSocket_OpenSSL.cpp @@ -319,6 +319,8 @@ void TLSSocket_OpenSSL::handleError(int rc) { if (rc > 0) return; + internalThrow(); + int sslError = SSL_get_error(m_ssl, rc); long lastError = ERR_get_error(); @@ -401,20 +403,16 @@ int TLSSocket_OpenSSL::bio_write(BIO* bio, const char* buf, int len) try { - BIO_clear_retry_flags(bio); - - const size_t n = sok->m_wrapped->sendRawNonBlocking - (reinterpret_cast (buf), len); + while (true) + { + const size_t n = sok->m_wrapped->sendRawNonBlocking + (reinterpret_cast (buf), len); - BIO_clear_retry_flags(bio); + if (n == 0 && sok->m_wrapped->getStatus() & socket::STATUS_WOULDBLOCK) + continue; - if (n == 0 && sok->m_wrapped->getStatus() & socket::STATUS_WOULDBLOCK) - { - BIO_set_retry_write(bio); - return -1; + return static_cast (len); } - - return static_cast (len); } catch (exception& e) { @@ -435,18 +433,16 @@ int TLSSocket_OpenSSL::bio_read(BIO* bio, char* buf, int len) try { - const size_t n = sok->m_wrapped->receiveRaw - (reinterpret_cast (buf), len); + while (true) + { + const size_t n = sok->m_wrapped->receiveRaw + (reinterpret_cast (buf), len); - BIO_clear_retry_flags(bio); + if (n == 0 && sok->m_wrapped->getStatus() & socket::STATUS_WOULDBLOCK) + continue; - if (sok->m_wrapped->getStatus() & socket::STATUS_WOULDBLOCK) - { - BIO_set_retry_read(bio); - return -1; + return static_cast (n); } - - return static_cast (n); } catch (exception& e) { -- cgit v1.2.3