diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index f2ecbe1a..682c61d3 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,6 +2,11 @@ All changes to this project will be documented in this file. + +## [10.3.5] - 2020-09-09 + +(ws) autoroute command exit on its own once all messages have been received + ## [10.3.4] - 2020-09-04 (docker) ws docker file installs strace diff --git a/ixwebsocket/IXWebSocketVersion.h b/ixwebsocket/IXWebSocketVersion.h index 61df79cb..b5ba933b 100644 --- a/ixwebsocket/IXWebSocketVersion.h +++ b/ixwebsocket/IXWebSocketVersion.h @@ -6,4 +6,4 @@ #pragma once -#define IX_WEBSOCKET_VERSION "10.3.4" +#define IX_WEBSOCKET_VERSION "10.3.5" diff --git a/ws/ws.cpp b/ws/ws.cpp index 7caa3481..f141650a 100644 --- a/ws/ws.cpp +++ b/ws/ws.cpp @@ -1134,8 +1134,8 @@ namespace ix webSocket.addSubProtocol(subprotocol); } - std::atomic receivedCountTotal(0); std::atomic receivedCountPerSecs(0); + std::atomic target(msgCount); std::mutex conditionVariableMutex; std::condition_variable condition; @@ -1144,12 +1144,20 @@ namespace ix // Setup a callback to be fired // when a message or an event (open, close, ping, pong, error) is received webSocket.setOnMessageCallback( - [&webSocket, &receivedCountPerSecs, &receivedCountTotal, &stop, &condition, &bench]( + [&webSocket, &receivedCountPerSecs, &target, &stop, &condition, &bench]( const ix::WebSocketMessagePtr& msg) { if (msg->type == ix::WebSocketMessageType::Message) { receivedCountPerSecs++; - receivedCountTotal++; + + target -= 1; + if (target == 0) + { + stop = true; + condition.notify_one(); + + bench.report(); + } } else if (msg->type == ix::WebSocketMessageType::Open) { @@ -1170,14 +1178,10 @@ namespace ix else if (msg->type == ix::WebSocketMessageType::Close) { spdlog::info("ws_autoroute: connection closed"); - stop = true; - condition.notify_one(); - - bench.report(); } }); - auto timer = [&receivedCountTotal, &receivedCountPerSecs, &stop] { + auto timer = [&receivedCountPerSecs, &stop] { setThreadName("Timer"); while (!stop) { @@ -1187,8 +1191,7 @@ namespace ix // our own counters // std::stringstream ss; - ss << "messages received: " << receivedCountPerSecs << " per second " - << receivedCountTotal << " total"; + ss << "messages received per second: " << receivedCountPerSecs; CoreLogger::info(ss.str()); @@ -1212,11 +1215,6 @@ namespace ix t1.join(); webSocket.stop(); - std::stringstream ss; - ss << "messages received: " << receivedCountTotal << " total"; - - CoreLogger::info(ss.str()); - return 0; }