diff options
author | Vincent Richard <[email protected]> | 2013-12-17 21:10:08 +0000 |
---|---|---|
committer | Vincent Richard <[email protected]> | 2013-12-17 21:10:08 +0000 |
commit | 2b62c675fa2d533eeb6f65b7ae33e6ddeb2f17a0 (patch) | |
tree | 3114dec7a7b5f13726a3c30aeb6fed956b5c0359 /src/net/tls/openssl/TLSSocket_OpenSSL.cpp | |
parent | More robust error checking. (diff) | |
download | vmime-2b62c675fa2d533eeb6f65b7ae33e6ddeb2f17a0.tar.gz vmime-2b62c675fa2d533eeb6f65b7ae33e6ddeb2f17a0.zip |
Loop on recv and send operations for non-blocking sockets with OpenSSL.
Diffstat (limited to 'src/net/tls/openssl/TLSSocket_OpenSSL.cpp')
-rw-r--r-- | src/net/tls/openssl/TLSSocket_OpenSSL.cpp | 36 |
1 files changed, 16 insertions, 20 deletions
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 <const byte_t*>(buf), len); + while (true) + { + const size_t n = sok->m_wrapped->sendRawNonBlocking + (reinterpret_cast <const byte_t*>(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 <int>(len); } - - return static_cast <int>(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 <byte_t*>(buf), len); + while (true) + { + const size_t n = sok->m_wrapped->receiveRaw + (reinterpret_cast <byte_t*>(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 <int>(n); } - - return static_cast <int>(n); } catch (exception& e) { |