LibTLS: Do not call on_tls_finished until the client has read app data

This commit is contained in:
AnotherTest 2020-05-21 00:35:19 +04:30 committed by Andreas Kling
parent ef49309807
commit 7d76299ca9
Notes: sideshowbarker 2024-07-19 06:18:04 +09:00
2 changed files with 22 additions and 11 deletions

View file

@ -113,13 +113,7 @@ bool TLSv12::common_connect(const struct sockaddr* saddr, socklen_t length)
Core::Socket::on_connected = [this] {
Core::Socket::on_ready_to_read = [this] {
if (!check_connection_state(true))
return;
flush();
consume(Core::Socket::read(4096));
if (is_established() && m_context.application_buffer.size())
if (on_tls_ready_to_read)
on_tls_ready_to_read(*this);
read_from_socket();
};
write_into_socket();
if (on_tls_connected)
@ -132,6 +126,20 @@ bool TLSv12::common_connect(const struct sockaddr* saddr, socklen_t length)
return true;
}
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);
}
if (!check_connection_state(true))
return;
flush();
consume(Core::Socket::read(4096));
}
void TLSv12::write_into_socket()
{
#ifdef TLS_DEBUG
@ -161,16 +169,18 @@ bool TLSv12::check_connection_state(bool read)
m_context.connection_finished = true;
}
if (m_context.critical_error) {
dbg() << "WRITE CRITICAL ERROR " << m_context.critical_error << " :(";
dbg() << "CRITICAL ERROR " << m_context.critical_error << " :(";
if (on_tls_error)
on_tls_error((AlertDescription)m_context.critical_error);
return false;
}
if (((read && m_context.application_buffer.size() == 0) || !read) && m_context.connection_finished) {
if (on_tls_finished)
on_tls_finished();
if (m_context.application_buffer.size() == 0) {
if (on_tls_finished)
on_tls_finished();
}
if (m_context.tls_buffer.size()) {
dbg() << "connection closed without finishing data transfer, " << m_context.tls_buffer.size() << " bytes still in buffer";
dbg() << "connection closed without finishing data transfer, " << m_context.tls_buffer.size() << " bytes still in buffer & " << m_context.application_buffer.size() << " bytes in application buffer";
} else {
m_context.connection_finished = false;
dbg() << "FINISHED";

View file

@ -376,6 +376,7 @@ private:
bool flush();
void write_into_socket();
void read_from_socket();
bool check_connection_state(bool read);