Bladeren bron

LibTLS: Don't close the underlying socket on EOF

Ali Mohammad Pur 3 jaren geleden
bovenliggende
commit
d3ea0818f3
1 gewijzigde bestanden met toevoegingen van 12 en 5 verwijderingen
  1. 12 5
      Userland/Libraries/LibTLS/Socket.cpp

+ 12 - 5
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;
         }
     }