ソースを参照

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 週間 前
親
コミット
baf27c5993
2 ファイル変更、2 行追加、9 行削除
  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;
         return;
       }
       }
       lock.unlock();
       lock.unlock();
-      if (!send_frame(Opcode::Ping, nullptr, 0)) {
-        lock.lock();
-        closed_ = true;
-        break;
-      }
+      if (!send_frame(Opcode::Ping, nullptr, 0)) { return; }
       lock.lock();
       lock.lock();
       unacked_pings_++;
       unacked_pings_++;
     }
     }

+ 1 - 4
test/test.cc

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