Skip to content

Commit

Permalink
Add pingIntervalSeconds to constructor for WebSocketServer
Browse files Browse the repository at this point in the history
  • Loading branch information
dwymark-celestron committed Jan 18, 2024
1 parent cc9cc32 commit 14affbb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion ixwebsocket/IXWebSocketServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@ namespace ix
{
const int WebSocketServer::kDefaultHandShakeTimeoutSecs(3); // 3 seconds
const bool WebSocketServer::kDefaultEnablePong(true);
const int WebSocketServer::kPingIntervalSeconds(-1); // disable heartbeat

WebSocketServer::WebSocketServer(int port,
const std::string& host,
int backlog,
size_t maxConnections,
int handshakeTimeoutSecs,
int addressFamily)
int addressFamily,
int pingIntervalSeconds)
: SocketServer(port, host, backlog, maxConnections, addressFamily)
, _handshakeTimeoutSecs(handshakeTimeoutSecs)
, _enablePong(kDefaultEnablePong)
, _enablePerMessageDeflate(true)
, _pingIntervalSeconds(pingIntervalSeconds)
{
}

Expand Down Expand Up @@ -93,6 +96,7 @@ namespace ix
auto webSocket = std::make_shared<WebSocket>();

webSocket->setAutoThreadName(false);
webSocket->setPingInterval(_pingIntervalSeconds);

if (_onConnectionCallback)
{
Expand Down
5 changes: 4 additions & 1 deletion ixwebsocket/IXWebSocketServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ namespace ix
int backlog = SocketServer::kDefaultTcpBacklog,
size_t maxConnections = SocketServer::kDefaultMaxConnections,
int handshakeTimeoutSecs = WebSocketServer::kDefaultHandShakeTimeoutSecs,
int addressFamily = SocketServer::kDefaultAddressFamily);
int addressFamily = SocketServer::kDefaultAddressFamily,
int pingIntervalSeconds = WebSocketServer::kPingIntervalSeconds);
virtual ~WebSocketServer();
virtual void stop() final;

Expand Down Expand Up @@ -61,6 +62,7 @@ namespace ix
int _handshakeTimeoutSecs;
bool _enablePong;
bool _enablePerMessageDeflate;
int _pingIntervalSeconds;

OnConnectionCallback _onConnectionCallback;
OnClientMessageCallback _onClientMessageCallback;
Expand All @@ -69,6 +71,7 @@ namespace ix
std::set<std::shared_ptr<WebSocket>> _clients;

const static bool kDefaultEnablePong;
const static int kPingIntervalSeconds;

// Methods
virtual void handleConnection(std::unique_ptr<Socket> socket,
Expand Down

0 comments on commit 14affbb

Please sign in to comment.