diff --git a/Userland/Libraries/LibTLS/Socket.cpp b/Userland/Libraries/LibTLS/Socket.cpp index 58bc5c1086..68417d5cf4 100644 --- a/Userland/Libraries/LibTLS/Socket.cpp +++ b/Userland/Libraries/LibTLS/Socket.cpp @@ -202,13 +202,24 @@ bool TLSv12::check_connection_state(bool read) if (m_context.connection_finished) return false; - if (!Core::Socket::is_open() || !Core::Socket::is_connected() || Core::Socket::eof()) { + if (!Core::Socket::is_open() || !Core::Socket::is_connected()) { // an abrupt closure (the server is a jerk) dbgln_if(TLS_DEBUG, "Socket not open, assuming abrupt closure"); m_context.connection_finished = true; + m_context.connection_status = ConnectionStatus::Disconnected; Core::Socket::close(); return false; } + + if (read && Core::Socket::eof()) { + if (m_context.application_buffer.size() == 0 && m_context.connection_status != ConnectionStatus::Disconnected) { + m_context.has_invoked_finish_or_error_callback = true; + if (on_tls_finished) + on_tls_finished(); + } + return false; + } + if (m_context.critical_error) { dbgln_if(TLS_DEBUG, "CRITICAL ERROR {} :(", m_context.critical_error); @@ -227,12 +238,8 @@ bool TLSv12::check_connection_state(bool read) dbgln_if(TLS_DEBUG, "connection closed without finishing data transfer, {} bytes still in buffer and {} bytes in application buffer", m_context.tls_buffer.size(), m_context.application_buffer.size()); - } else { - m_context.connection_finished = true; - dbgln_if(TLS_DEBUG, "FINISHED"); } if (!m_context.application_buffer.size()) { - m_context.connection_status = ConnectionStatus::Disconnected; return false; } }