2018-12-30 03:33:15 +01:00
|
|
|
/*
|
|
|
|
* IXTest.cpp
|
|
|
|
* Author: Benjamin Sergeant
|
|
|
|
* Copyright (c) 2018 Machine Zone. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "IXTest.h"
|
|
|
|
#include <ixwebsocket/IXWebSocket.h>
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
#include <thread>
|
2019-01-08 03:04:28 +01:00
|
|
|
#include <mutex>
|
2018-12-30 03:33:15 +01:00
|
|
|
#include <string>
|
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
namespace ix
|
|
|
|
{
|
|
|
|
std::atomic<size_t> incomingBytes(0);
|
|
|
|
std::atomic<size_t> outgoingBytes(0);
|
2019-01-08 03:04:28 +01:00
|
|
|
std::mutex Logger::_mutex;
|
2018-12-30 03:33:15 +01:00
|
|
|
|
|
|
|
void setupWebSocketTrafficTrackerCallback()
|
|
|
|
{
|
|
|
|
ix::WebSocket::setTrafficTrackerCallback(
|
|
|
|
[](size_t size, bool incoming)
|
|
|
|
{
|
|
|
|
if (incoming)
|
|
|
|
{
|
|
|
|
incomingBytes += size;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
outgoingBytes += size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void reportWebSocketTraffic()
|
|
|
|
{
|
2019-01-08 03:04:28 +01:00
|
|
|
Logger() << incomingBytes;
|
|
|
|
Logger() << "Incoming bytes: " << incomingBytes;
|
|
|
|
Logger() << "Outgoing bytes: " << outgoingBytes;
|
2018-12-30 03:33:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void msleep(int ms)
|
|
|
|
{
|
|
|
|
std::chrono::duration<double, std::milli> duration(ms);
|
|
|
|
std::this_thread::sleep_for(duration);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string generateSessionId()
|
|
|
|
{
|
|
|
|
auto now = std::chrono::system_clock::now();
|
|
|
|
auto seconds =
|
|
|
|
std::chrono::duration_cast<std::chrono::seconds>(
|
|
|
|
now.time_since_epoch()).count();
|
|
|
|
|
|
|
|
return std::to_string(seconds);
|
|
|
|
}
|
2019-01-08 03:04:28 +01:00
|
|
|
|
|
|
|
void log(const std::string& msg)
|
|
|
|
{
|
|
|
|
Logger() << msg;
|
|
|
|
}
|
|
|
|
|
2018-12-30 03:33:15 +01:00
|
|
|
}
|