2018-12-29 18:33:15 -08:00
|
|
|
/*
|
|
|
|
* IXTest.h
|
|
|
|
* Author: Benjamin Sergeant
|
|
|
|
* Copyright (c) 2018 Machine Zone. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-01-07 18:04:28 -08:00
|
|
|
#include <iostream>
|
2020-07-27 18:17:13 -07:00
|
|
|
#include <ixwebsocket/IXGetFreePort.h>
|
2020-03-20 12:21:45 -07:00
|
|
|
#include <ixwebsocket/IXSocketTLSOptions.h>
|
2020-03-20 17:00:18 -07:00
|
|
|
#include <ixwebsocket/IXWebSocketServer.h>
|
2019-01-07 18:08:11 -08:00
|
|
|
#include <mutex>
|
2019-05-13 17:32:57 -07:00
|
|
|
#include <spdlog/spdlog.h>
|
2019-06-06 13:48:53 -07:00
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2018-12-29 18:33:15 -08:00
|
|
|
|
|
|
|
namespace ix
|
|
|
|
{
|
|
|
|
// Sleep for ms milliseconds.
|
|
|
|
void msleep(int ms);
|
|
|
|
|
|
|
|
// Generate a relatively random string
|
|
|
|
std::string generateSessionId();
|
|
|
|
|
|
|
|
// Record and report websocket traffic
|
|
|
|
void setupWebSocketTrafficTrackerCallback();
|
|
|
|
void reportWebSocketTraffic();
|
2019-01-07 18:04:28 -08:00
|
|
|
|
2020-03-12 09:07:01 -07:00
|
|
|
struct TLogger
|
2019-01-07 18:04:28 -08:00
|
|
|
{
|
2019-06-06 13:48:53 -07:00
|
|
|
public:
|
|
|
|
template<typename T>
|
2020-03-12 09:07:01 -07:00
|
|
|
TLogger& operator<<(T const& obj)
|
2019-06-06 13:48:53 -07:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(_mutex);
|
|
|
|
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << obj;
|
|
|
|
spdlog::info(ss.str());
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static std::mutex _mutex;
|
2019-01-07 18:04:28 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
void log(const std::string& msg);
|
2019-01-28 15:14:49 -08:00
|
|
|
|
2019-05-16 14:25:31 -07:00
|
|
|
bool startWebSocketEchoServer(ix::WebSocketServer& server);
|
2019-09-05 20:48:38 -07:00
|
|
|
|
2020-03-20 12:21:45 -07:00
|
|
|
SocketTLSOptions makeClientTLSOptions();
|
|
|
|
SocketTLSOptions makeServerTLSOptions(bool preferTLS);
|
|
|
|
std::string getHttpScheme();
|
|
|
|
std::string getWsScheme(bool preferTLS);
|
2019-06-06 13:48:53 -07:00
|
|
|
} // namespace ix
|