From 262f32857f95994334f837c6768dba1c0b1b132c Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Sat, 7 Nov 2020 09:34:47 -0800 Subject: [PATCH] (ws autoroute) Display result in compliant way (AUTOROUTE IXWebSocket :: N ms) so that result can be parsed easily --- docs/CHANGELOG.md | 4 ++ ixwebsocket/IXWebSocketVersion.h | 2 +- test/IXTest.cpp | 4 +- test/IXTest.h | 2 +- test/IXWebSocketBroadcastTest.cpp | 7 ++- ws/ws.cpp | 73 ++++++++++++++++++------------- 6 files changed, 55 insertions(+), 37 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 77d6fcbe..0d99a43e 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,6 +2,10 @@ All changes to this project will be documented in this file. +## [10.5.5] - 2020-11-07 + +(ws autoroute) Display result in compliant way (AUTOROUTE IXWebSocket :: N ms) so that result can be parsed easily + ## [10.5.4] - 2020-10-30 (ws gunzip + IXGZipCodec) Can decompress gziped data with libdeflate. ws gunzip computed output filename was incorrect (was the extension aka gz) instead of the file without the extension. Also check whether the output file is writeable. diff --git a/ixwebsocket/IXWebSocketVersion.h b/ixwebsocket/IXWebSocketVersion.h index 106dbfb7..663ec7e2 100644 --- a/ixwebsocket/IXWebSocketVersion.h +++ b/ixwebsocket/IXWebSocketVersion.h @@ -6,4 +6,4 @@ #pragma once -#define IX_WEBSOCKET_VERSION "10.5.4" +#define IX_WEBSOCKET_VERSION "10.5.5" diff --git a/test/IXTest.cpp b/test/IXTest.cpp index ae289d68..8c9e5ff2 100644 --- a/test/IXTest.cpp +++ b/test/IXTest.cpp @@ -10,10 +10,10 @@ #include #include #include -#include -#include #include #include +#include +#include #include #include #include diff --git a/test/IXTest.h b/test/IXTest.h index 6f9e394b..c56df2fc 100644 --- a/test/IXTest.h +++ b/test/IXTest.h @@ -7,8 +7,8 @@ #pragma once #include -#include #include +#include #include #include #include diff --git a/test/IXWebSocketBroadcastTest.cpp b/test/IXWebSocketBroadcastTest.cpp index fcabcb82..29569e7e 100644 --- a/test/IXWebSocketBroadcastTest.cpp +++ b/test/IXWebSocketBroadcastTest.cpp @@ -47,7 +47,9 @@ namespace mutable std::mutex _mutex; }; - WebSocketBroadcastChat::WebSocketBroadcastChat(const std::string& user, const std::string& session, int port) + WebSocketBroadcastChat::WebSocketBroadcastChat(const std::string& user, + const std::string& session, + int port) : _user(user) , _session(session) , _port(port) @@ -156,7 +158,8 @@ namespace _webSocket.start(); } - std::pair WebSocketBroadcastChat::decodeMessage(const std::string& str) + std::pair WebSocketBroadcastChat::decodeMessage( + const std::string& str) { std::string errMsg; MsgPack msg = MsgPack::parse(str, errMsg); diff --git a/ws/ws.cpp b/ws/ws.cpp index 7f9a9f69..6a393bf5 100644 --- a/ws/ws.cpp +++ b/ws/ws.cpp @@ -1273,45 +1273,56 @@ namespace ix std::condition_variable condition; std::atomic stop(false); + std::chrono::time_point start; // Setup a callback to be fired // when a message or an event (open, close, ping, pong, error) is received - webSocket.setOnMessageCallback([&receivedCountPerSecs, &target, &stop, &condition, &bench]( - const ix::WebSocketMessagePtr& msg) { - if (msg->type == ix::WebSocketMessageType::Message) - { - receivedCountPerSecs++; - - target -= 1; - if (target == 0) + webSocket.setOnMessageCallback( + [&receivedCountPerSecs, &target, &stop, &condition, &bench, &start]( + const ix::WebSocketMessagePtr& msg) { + if (msg->type == ix::WebSocketMessageType::Message) { - stop = true; - condition.notify_one(); + receivedCountPerSecs++; - bench.report(); + target -= 1; + if (target == 0) + { + stop = true; + condition.notify_one(); + + bench.report(); + + auto now = std::chrono::high_resolution_clock::now(); + auto milliseconds = + std::chrono::duration_cast(now - start); + auto duration = milliseconds.count(); + + spdlog::info("AUTOROUTE IXWebSocket :: {} ms", duration); + } } - } - else if (msg->type == ix::WebSocketMessageType::Open) - { - bench.reset(); - - spdlog::info("ws_autoroute: connected"); - spdlog::info("Uri: {}", msg->openInfo.uri); - spdlog::info("Headers:"); - for (auto it : msg->openInfo.headers) + else if (msg->type == ix::WebSocketMessageType::Open) { - spdlog::info("{}: {}", it.first, it.second); + bench.reset(); + + spdlog::info("ws_autoroute: connected"); + spdlog::info("Uri: {}", msg->openInfo.uri); + spdlog::info("Headers:"); + for (auto it : msg->openInfo.headers) + { + spdlog::info("{}: {}", it.first, it.second); + } + + start = std::chrono::high_resolution_clock::now(); } - } - else if (msg->type == ix::WebSocketMessageType::Pong) - { - spdlog::info("Received pong {}", msg->str); - } - else if (msg->type == ix::WebSocketMessageType::Close) - { - spdlog::info("ws_autoroute: connection closed"); - } - }); + else if (msg->type == ix::WebSocketMessageType::Pong) + { + spdlog::info("Received pong {}", msg->str); + } + else if (msg->type == ix::WebSocketMessageType::Close) + { + spdlog::info("ws_autoroute: connection closed"); + } + }); auto timer = [&receivedCountPerSecs, &stop] { setThreadName("Timer");