Kaynağa Gözat

Drop the heartbeat's own closed_ update and the vacuous test check

send_frame now marks the connection closed whenever it returns false,
so the heartbeat no longer needs to. The second send() in the test
fails before the fix too, since the client is not reading, so it does
not check anything; large_sent becomes an ASSERT as the precondition.
yhirose 1 hafta önce
ebeveyn
işleme
baf27c5993
2 değiştirilmiş dosya ile 2 ekleme ve 9 silme
  1. 1 5
      httplib.h
  2. 1 4
      test/test.cc

+ 1 - 5
httplib.h

@@ -25052,11 +25052,7 @@ inline void WebSocket::start_heartbeat() {
         return;
       }
       lock.unlock();
-      if (!send_frame(Opcode::Ping, nullptr, 0)) {
-        lock.lock();
-        closed_ = true;
-        break;
-      }
+      if (!send_frame(Opcode::Ping, nullptr, 0)) { return; }
       lock.lock();
       unacked_pings_++;
     }

+ 1 - 4
test/test.cc

@@ -29625,7 +29625,6 @@ TEST(WebSocketPartialWriteTest, FailedWriteClosesConnection) {
   const std::string large(4 * 1024 * 1024, 'A');
   std::atomic<bool> large_sent{true};
   std::atomic<bool> open_after_failure{true};
-  std::atomic<bool> small_sent{true};
   std::atomic<bool> handler_done{false};
 
   Server svr;
@@ -29638,7 +29637,6 @@ TEST(WebSocketPartialWriteTest, FailedWriteClosesConnection) {
   svr.WebSocket("/ws", [&](const Request &, ws::WebSocket &ws) {
     large_sent = ws.send(large.data(), large.size());
     open_after_failure = ws.is_open();
-    small_sent = ws.send("after");
     handler_done = true;
   });
 
@@ -29665,9 +29663,8 @@ TEST(WebSocketPartialWriteTest, FailedWriteClosesConnection) {
   }
   ASSERT_TRUE(handler_done);
 
-  EXPECT_FALSE(large_sent);
+  ASSERT_FALSE(large_sent);
   EXPECT_FALSE(open_after_failure);
-  EXPECT_FALSE(small_sent);
 
   client.close();
 }