(ws autoroute) Display result in compliant way (AUTOROUTE IXWebSocket :: N ms) so that result can be parsed easily
This commit is contained in:
		@@ -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.
 | 
			
		||||
 
 | 
			
		||||
@@ -6,4 +6,4 @@
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#define IX_WEBSOCKET_VERSION "10.5.4"
 | 
			
		||||
#define IX_WEBSOCKET_VERSION "10.5.5"
 | 
			
		||||
 
 | 
			
		||||
@@ -10,10 +10,10 @@
 | 
			
		||||
#include <fstream>
 | 
			
		||||
#include <iomanip>
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <ixwebsocket/IXNetSystem.h>
 | 
			
		||||
#include <ixwebsocket/IXWebSocket.h>
 | 
			
		||||
#include <ixcobra/IXCobraMetricsPublisher.h>
 | 
			
		||||
#include <ixcrypto/IXUuid.h>
 | 
			
		||||
#include <ixwebsocket/IXNetSystem.h>
 | 
			
		||||
#include <ixwebsocket/IXWebSocket.h>
 | 
			
		||||
#include <mutex>
 | 
			
		||||
#include <random>
 | 
			
		||||
#include <stack>
 | 
			
		||||
 
 | 
			
		||||
@@ -7,8 +7,8 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <ixsnake/IXAppConfig.h>
 | 
			
		||||
#include <ixcobra/IXCobraConfig.h>
 | 
			
		||||
#include <ixsnake/IXAppConfig.h>
 | 
			
		||||
#include <ixwebsocket/IXGetFreePort.h>
 | 
			
		||||
#include <ixwebsocket/IXSocketTLSOptions.h>
 | 
			
		||||
#include <ixwebsocket/IXWebSocketServer.h>
 | 
			
		||||
 
 | 
			
		||||
@@ -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<std::string, std::string> WebSocketBroadcastChat::decodeMessage(const std::string& str)
 | 
			
		||||
    std::pair<std::string, std::string> WebSocketBroadcastChat::decodeMessage(
 | 
			
		||||
        const std::string& str)
 | 
			
		||||
    {
 | 
			
		||||
        std::string errMsg;
 | 
			
		||||
        MsgPack msg = MsgPack::parse(str, errMsg);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										73
									
								
								ws/ws.cpp
									
									
									
									
									
								
							
							
						
						
									
										73
									
								
								ws/ws.cpp
									
									
									
									
									
								
							@@ -1273,45 +1273,56 @@ namespace ix
 | 
			
		||||
        std::condition_variable condition;
 | 
			
		||||
 | 
			
		||||
        std::atomic<bool> stop(false);
 | 
			
		||||
        std::chrono::time_point<std::chrono::high_resolution_clock> 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<std::chrono::milliseconds>(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");
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user