Skip to content

Commit

Permalink
LibTLS: Call the read hooks after processing messages too
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alimpfard authored and linusg committed Apr 23, 2021
1 parent e72235b commit cb134cd
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions Userland/Libraries/LibTLS/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit cb134cd

Please sign in to comment.