mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 17:19:13 +00:00
LibTLS: Make TLSv12::can_read_without_blocking() respect the timeout arg
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 is contained in:
parent
00f76ccbf4
commit
b374322e38
Notes:
github-actions[bot]
2025-06-11 16:18:20 +00:00
Author: https://github.com/alimpfard
Commit: b374322e38
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4709
Reviewed-by: https://github.com/ADKaster ✅
2 changed files with 18 additions and 2 deletions
|
@ -5,6 +5,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibCore/ElapsedTimer.h>
|
||||
#include <LibCore/Promise.h>
|
||||
#include <LibCrypto/OpenSSL.h>
|
||||
#include <LibTLS/TLSv12.h>
|
||||
|
@ -137,7 +138,22 @@ 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;
|
||||
|
||||
auto timer = Core::ElapsedTimer();
|
||||
while (timeout > 0) {
|
||||
auto elapsed = timer.elapsed_milliseconds();
|
||||
if (elapsed >= timeout)
|
||||
break;
|
||||
|
||||
if (!TRY(m_socket->can_read_without_blocking(timeout - elapsed)))
|
||||
return SSL_has_pending(m_ssl);
|
||||
if (SSL_has_pending(m_ssl))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
ErrorOr<void> TLSv12::set_blocking(bool)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue