LibTLS: Make TLSv12::can_read_without_blocking() actually work

Previously this function's return value was not reliable, as available
data on the underlying socket did not necessarily translate to available
application data on the TLS socket.
This commit makes it so this function only returns true when we actually
have data buffered and/or available.
This commit is contained in:
Ali Mohammad Pur 2025-02-24 11:24:20 +01:00
commit 516d68f7eb

View file

@ -134,7 +134,13 @@ ErrorOr<bool> TLSv12::can_read_without_blocking(int timeout) const
if (!m_ssl)
return Error::from_string_literal("SSL connection is closed");
return m_socket->can_read_without_blocking(timeout);
if (SSL_has_pending(m_ssl))
return true;
if (timeout > 0)
return TRY(m_socket->can_read_without_blocking(timeout)) && SSL_has_pending(m_ssl);
return false;
}
ErrorOr<void> TLSv12::set_blocking(bool)