IXWebSocket/test/IXTest.h

63 lines
1.4 KiB
C
Raw Normal View History

2018-12-30 03:33:15 +01:00
/*
* IXTest.h
* Author: Benjamin Sergeant
* Copyright (c) 2018 Machine Zone. All rights reserved.
*/
#pragma once
2019-08-13 19:59:18 +02:00
#include "IXGetFreePort.h"
2019-01-08 03:04:28 +01:00
#include <iostream>
#include <ixsnake/IXAppConfig.h>
#include <ixwebsocket/IXSocketTLSOptions.h>
2020-03-21 01:00:18 +01:00
#include <ixwebsocket/IXWebSocketServer.h>
#include <mutex>
2019-05-14 02:32:57 +02:00
#include <spdlog/spdlog.h>
#include <sstream>
#include <string>
#include <vector>
2018-12-30 03:33:15 +01: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-08 03:04:28 +01:00
2020-03-12 17:07:01 +01:00
struct TLogger
2019-01-08 03:04:28 +01:00
{
public:
template<typename T>
2020-03-12 17:07:01 +01:00
TLogger& operator<<(T const& obj)
{
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-08 03:04:28 +01:00
};
void log(const std::string& msg);
bool startWebSocketEchoServer(ix::WebSocketServer& server);
snake::AppConfig makeSnakeServerConfig(int port, bool preferTLS);
SocketTLSOptions makeClientTLSOptions();
SocketTLSOptions makeServerTLSOptions(bool preferTLS);
std::string getHttpScheme();
std::string getWsScheme(bool preferTLS);
std::string makeCobraEndpoint(int port, bool preferTLS);
} // namespace ix