From cb134cd702a753a70bbc241ab510069c8d32f451 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Fri, 23 Apr 2021 13:58:41 +0430 Subject: [PATCH] LibTLS: Call the read hooks after processing messages too Otherwise the notification would be deferred until the next read event, which means the client will not get any events if the server initiates the appdata transfers. --- Userland/Libraries/LibTLS/Socket.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibTLS/Socket.cpp b/Userland/Libraries/LibTLS/Socket.cpp index 8baf325bcc6..fc4ccf92089 100644 --- a/Userland/Libraries/LibTLS/Socket.cpp +++ b/Userland/Libraries/LibTLS/Socket.cpp @@ -140,16 +140,29 @@ bool TLSv12::common_connect(const struct sockaddr* saddr, socklen_t length) void TLSv12::read_from_socket() { - if (m_context.application_buffer.size() > 0) { - deferred_invoke([&](auto&) { read_from_socket(); }); - if (on_tls_ready_to_read) - on_tls_ready_to_read(*this); - } + auto did_schedule_read = false; + auto notify_client_for_app_data = [&] { + if (m_context.application_buffer.size() > 0) { + if (!did_schedule_read) { + deferred_invoke([&](auto&) { read_from_socket(); }); + did_schedule_read = true; + } + if (on_tls_ready_to_read) + on_tls_ready_to_read(*this); + } + }; + + // If there's anything before we consume stuff, let the client know + // since we won't be consuming things if the connection is terminated. + notify_client_for_app_data(); if (!check_connection_state(true)) return; consume(Core::Socket::read(4096)); + + // If anything new shows up, tell the client about the event. + notify_client_for_app_data(); } void TLSv12::write_into_socket()