diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-09-19 03:39:37 +0430 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-09-19 21:10:23 +0430 |
commit | d3ea0818f3dc6f744e6176e9bd1633e3085d6b71 (patch) | |
tree | 6e92c02703bf655112017652cdaf9970c469e82e /Userland | |
parent | e780ee2832bf1c6a6150a87cfe439dbe0d49d7a7 (diff) | |
download | serenity-d3ea0818f3dc6f744e6176e9bd1633e3085d6b71.zip |
LibTLS: Don't close the underlying socket on EOF
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibTLS/Socket.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
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; } } |