]> git.seodisparate.com - UDPConnection/commitdiff
Refactor heartbeat related code (constants)
authorStephen Seo <seo.disparate@gmail.com>
Wed, 12 Mar 2025 12:16:19 +0000 (21:16 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Wed, 12 Mar 2025 12:16:19 +0000 (21:16 +0900)
src/UDPC_Defines.hpp
src/UDPConnection.cpp

index cefaa9e6b8598c9b528e27962d5e025642faed2b..08779aa8aedc9af75e17f61439c053492851862b 100644 (file)
@@ -63,7 +63,9 @@ constexpr auto TEN_SECONDS = std::chrono::seconds(10);
 constexpr auto THIRTY_SECONDS = std::chrono::seconds(30);
 
 constexpr auto INIT_PKT_INTERVAL_DT = std::chrono::seconds(5);
-constexpr auto HEARTBEAT_PKT_INTERVAL_DT = std::chrono::milliseconds(150);
+constexpr unsigned int HEARTBEAT_PKT_INT_MIN_MILLIS = 150;
+constexpr unsigned int HEARTBEAT_PKT_INT_MAX_MILLIS = 5000;
+constexpr auto HEARTBEAT_PKT_INTERVAL_DT = std::chrono::milliseconds(HEARTBEAT_PKT_INT_MIN_MILLIS);
 constexpr auto PACKET_TIMEOUT_TIME = ONE_SECOND;
 constexpr auto GOOD_RTT_LIMIT = std::chrono::milliseconds(250);
 constexpr auto CONNECTION_TIMEOUT = TEN_SECONDS;
index 02676b507ceb552e427bebf87ba6787c8005c6ef..8c1934f4acb31a09c15ecd127b27e4e26404b7b7 100644 (file)
@@ -2847,11 +2847,11 @@ int UDPC_set_heartbeat_millis(UDPC_HContext ctx, unsigned int millis) {
 
     int ret = 0;
 
-    if (millis < 150) {
-        millis = 150;
+    if (millis < UDPC::HEARTBEAT_PKT_INT_MIN_MILLIS) {
+        millis = UDPC::HEARTBEAT_PKT_INT_MIN_MILLIS;
         ret = 1;
-    } else if (millis > 5000) {
-        millis = 5000;
+    } else if (millis > UDPC::HEARTBEAT_PKT_INT_MAX_MILLIS) {
+        millis = UDPC::HEARTBEAT_PKT_INT_MAX_MILLIS;
         ret = 2;
     }