13
13
14
14
#include " NetUtil.hpp"
15
15
#include " Socket.hpp"
16
- #include " common/Common.hpp"
17
16
#include " common/Log.hpp"
18
17
#include " common/Protocol.hpp"
19
18
#include " common/Unit.hpp"
@@ -62,8 +61,6 @@ class WebSocketHandler : public ProtocolHandlerInterface
62
61
};
63
62
64
63
static constexpr std::chrono::microseconds InitialPingDelayMicroS = std::chrono::milliseconds(25 );
65
- static constexpr std::chrono::microseconds PingFrequencyMicroS = std::chrono::seconds(18 );
66
- static constexpr std::chrono::microseconds PingTimeoutMicroS = std::chrono::seconds(12 );
67
64
68
65
public:
69
66
// / Perform upgrade ourselves, or select a client web socket.
@@ -75,7 +72,7 @@ class WebSocketHandler : public ProtocolHandlerInterface
75
72
:
76
73
#if !MOBILEAPP
77
74
_lastPingSentTime (std::chrono::steady_clock::now() -
78
- PingFrequencyMicroS +
75
+ net::Defaults.wsPingInterval +
79
76
std::chrono::microseconds(InitialPingDelayMicroS))
80
77
, _isMasking(isClient && isMasking)
81
78
, _inFragmentBlock(false )
@@ -603,7 +600,7 @@ class WebSocketHandler : public ProtocolHandlerInterface
603
600
const auto timeSincePingMicroS
604
601
= std::chrono::duration_cast<std::chrono::microseconds>(now - _lastPingSentTime);
605
602
timeoutMaxMicroS
606
- = std::min (timeoutMaxMicroS, (int64_t )(PingFrequencyMicroS - timeSincePingMicroS).count ());
603
+ = std::min (timeoutMaxMicroS, (int64_t )(net::Defaults. wsPingInterval - timeSincePingMicroS).count ());
607
604
}
608
605
#endif
609
606
int events = POLLIN;
@@ -670,21 +667,21 @@ class WebSocketHandler : public ProtocolHandlerInterface
670
667
if (_isClient)
671
668
return false ;
672
669
673
- if (PingTimeoutMicroS. count () > std::numeric_limits< double >:: epsilon () &&
674
- _pingMicroS.average () >= PingTimeoutMicroS .count ())
670
+ if (net::Defaults. wsPingAvgTimeout > std::chrono::microseconds::zero () &&
671
+ _pingMicroS.average () >= net::Defaults. wsPingAvgTimeout .count ())
675
672
{
676
673
std::shared_ptr<StreamSocket> socket = _socket.lock ();
677
674
if (socket && socket->isIPType ()) // Exclude non-IP local sockets
678
675
{
679
676
LOG_WRN (" CheckTimeout: Timeout websocket: Ping: last " << _pingMicroS.last () << " us, avg "
680
- << _pingMicroS.average () << " us >= " << PingTimeoutMicroS .count () << " us over "
677
+ << _pingMicroS.average () << " us >= " << net::Defaults. wsPingAvgTimeout .count () << " us over "
681
678
<< (int )_pingMicroS.duration () << " s, " << *socket);
682
679
shutdownSilent (socket);
683
680
return true ;
684
681
}
685
682
}
686
- if (!_pingMicroS.initialized () || (PingFrequencyMicroS > std::chrono::microseconds::zero () &&
687
- now - _pingMicroS.lastTime () >= PingFrequencyMicroS ))
683
+ if (!_pingMicroS.initialized () || (net::Defaults. wsPingInterval > std::chrono::microseconds::zero () &&
684
+ now - _pingMicroS.lastTime () >= net::Defaults. wsPingInterval ))
688
685
{
689
686
const std::shared_ptr<StreamSocket> socket = _socket.lock ();
690
687
if (socket)
0 commit comments