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.
This commit is contained in:
Adrien Destugues 2020-02-08 21:59:47 +01:00
parent 3a63d1efff
commit 0e280da525

View File

@ -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);