From 0e280da525d18b9ca2da5e36f16b6b29993a6d75 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Sat, 8 Feb 2020 21:59:47 +0100 Subject: [PATCH] SecureSocket: fix non-blocking reads OpenSSL says we should retry when a non-blocking read finds no data is pending. But in that case we should not retry immediately, because the operation should be non-blocking. --- src/kits/network/libnetapi/SecureSocket.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/kits/network/libnetapi/SecureSocket.cpp b/src/kits/network/libnetapi/SecureSocket.cpp index c2c3dc7618..fdd77311ca 100644 --- a/src/kits/network/libnetapi/SecureSocket.cpp +++ b/src/kits/network/libnetapi/SecureSocket.cpp @@ -551,6 +551,12 @@ BSecureSocket::Read(void* buffer, size_t size) bytesRead = SSL_read(fPrivate->fSSL, buffer, size); if (bytesRead >= 0) return bytesRead; + // Don't retry in cases of "no data available" for non-blocking sockets + int error = SSL_get_error(fPrivate->fSSL, bytesRead); + if (error == SSL_ERROR_WANT_READ || error == SSL_ERROR_WANT_WRITE) + return B_WOULD_BLOCK; + // Otherwise, check if we should retry (maybe we were interrupted by + // a signal, for example) retry = BIO_should_retry(SSL_get_rbio(fPrivate->fSSL)); } while(retry != 0);