clang format
This commit is contained in:
parent
d5e51840ab
commit
3a673575dd
@ -103,9 +103,9 @@ namespace ix
|
|||||||
std::thread _thread;
|
std::thread _thread;
|
||||||
|
|
||||||
std::unique_ptr<Socket> _socket;
|
std::unique_ptr<Socket> _socket;
|
||||||
std::recursive_mutex _mutex; // to protect accessing the _socket (only one socket per client)
|
std::recursive_mutex _mutex; // to protect accessing the _socket (only one socket per
|
||||||
// the mutex needs to be recursive as this function might
|
// client) the mutex needs to be recursive as this function
|
||||||
// be called recursively to follow HTTP redirections
|
// might be called recursively to follow HTTP redirections
|
||||||
|
|
||||||
SocketTLSOptions _tlsOptions;
|
SocketTLSOptions _tlsOptions;
|
||||||
|
|
||||||
|
@ -9,11 +9,11 @@
|
|||||||
#include "IXNetSystem.h"
|
#include "IXNetSystem.h"
|
||||||
#include "IXSocketConnect.h"
|
#include "IXSocketConnect.h"
|
||||||
#include "IXUserAgent.h"
|
#include "IXUserAgent.h"
|
||||||
|
#include <cstring>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
@ -50,8 +50,11 @@ namespace
|
|||||||
const int windowBits = 15;
|
const int windowBits = 15;
|
||||||
const int GZIP_ENCODING = 16;
|
const int GZIP_ENCODING = 16;
|
||||||
|
|
||||||
deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
|
deflateInit2(&zs,
|
||||||
windowBits | GZIP_ENCODING, 8,
|
Z_DEFAULT_COMPRESSION,
|
||||||
|
Z_DEFLATED,
|
||||||
|
windowBits | GZIP_ENCODING,
|
||||||
|
8,
|
||||||
Z_DEFAULT_STRATEGY);
|
Z_DEFAULT_STRATEGY);
|
||||||
|
|
||||||
zs.next_in = (Bytef*) str.data();
|
zs.next_in = (Bytef*) str.data();
|
||||||
@ -69,13 +72,12 @@ namespace
|
|||||||
|
|
||||||
ret = deflate(&zs, Z_FINISH);
|
ret = deflate(&zs, Z_FINISH);
|
||||||
|
|
||||||
if(outstring.size() < zs.total_out)
|
if (outstring.size() < zs.total_out)
|
||||||
{
|
{
|
||||||
// append the block to the output string
|
// append the block to the output string
|
||||||
outstring.append(outbuffer,
|
outstring.append(outbuffer, zs.total_out - outstring.size());
|
||||||
zs.total_out - outstring.size());
|
|
||||||
}
|
}
|
||||||
} while(ret == Z_OK);
|
} while (ret == Z_OK);
|
||||||
|
|
||||||
deflateEnd(&zs);
|
deflateEnd(&zs);
|
||||||
|
|
||||||
|
@ -32,8 +32,8 @@
|
|||||||
#include "IXUrlParser.h"
|
#include "IXUrlParser.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstring>
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -75,22 +75,26 @@ namespace ix
|
|||||||
return compressData(in, out);
|
return compressData(in, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebSocketPerMessageDeflateCompressor::compress(const std::string& in, std::vector<uint8_t>& out)
|
bool WebSocketPerMessageDeflateCompressor::compress(const std::string& in,
|
||||||
|
std::vector<uint8_t>& out)
|
||||||
{
|
{
|
||||||
return compressData(in, out);
|
return compressData(in, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebSocketPerMessageDeflateCompressor::compress(const std::vector<uint8_t>& in, std::string& out)
|
bool WebSocketPerMessageDeflateCompressor::compress(const std::vector<uint8_t>& in,
|
||||||
|
std::string& out)
|
||||||
{
|
{
|
||||||
return compressData(in, out);
|
return compressData(in, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebSocketPerMessageDeflateCompressor::compress(const std::vector<uint8_t>& in, std::vector<uint8_t>& out)
|
bool WebSocketPerMessageDeflateCompressor::compress(const std::vector<uint8_t>& in,
|
||||||
|
std::vector<uint8_t>& out)
|
||||||
{
|
{
|
||||||
return compressData(in, out);
|
return compressData(in, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename S> bool WebSocketPerMessageDeflateCompressor::compressData(const T& in, S& out)
|
template<typename T, typename S>
|
||||||
|
bool WebSocketPerMessageDeflateCompressor::compressData(const T& in, S& out)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// 7.2.1. Compression
|
// 7.2.1. Compression
|
||||||
|
@ -26,8 +26,10 @@ namespace ix
|
|||||||
bool compress(const std::vector<uint8_t>& in, std::vector<uint8_t>& out);
|
bool compress(const std::vector<uint8_t>& in, std::vector<uint8_t>& out);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template<typename T, typename S> bool compressData(const T& in, S& out);
|
template<typename T, typename S>
|
||||||
template<typename T> bool endsWithEmptyUnCompressedBlock(const T& value);
|
bool compressData(const T& in, S& out);
|
||||||
|
template<typename T>
|
||||||
|
bool endsWithEmptyUnCompressedBlock(const T& value);
|
||||||
|
|
||||||
int _flush;
|
int _flush;
|
||||||
size_t _compressBufferSize;
|
size_t _compressBufferSize;
|
||||||
|
@ -246,11 +246,8 @@ namespace ix
|
|||||||
const OnProgressCallback& onProgressCallback = nullptr);
|
const OnProgressCallback& onProgressCallback = nullptr);
|
||||||
|
|
||||||
template<class Iterator>
|
template<class Iterator>
|
||||||
bool sendFragment(wsheader_type::opcode_type type,
|
bool sendFragment(
|
||||||
bool fin,
|
wsheader_type::opcode_type type, bool fin, Iterator begin, Iterator end, bool compress);
|
||||||
Iterator begin,
|
|
||||||
Iterator end,
|
|
||||||
bool compress);
|
|
||||||
|
|
||||||
void emitMessage(MessageKind messageKind,
|
void emitMessage(MessageKind messageKind,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
#include <ixcobra/IXCobraConnection.h>
|
#include <ixcobra/IXCobraConnection.h>
|
||||||
#include <ixcobra/IXCobraMetricsPublisher.h>
|
#include <ixcobra/IXCobraMetricsPublisher.h>
|
||||||
#include <ixcrypto/IXUuid.h>
|
#include <ixcrypto/IXUuid.h>
|
||||||
#include <ixsentry/IXSentryClient.h>
|
|
||||||
#include <ixredis/IXRedisServer.h>
|
#include <ixredis/IXRedisServer.h>
|
||||||
|
#include <ixsentry/IXSentryClient.h>
|
||||||
#include <ixsnake/IXSnakeServer.h>
|
#include <ixsnake/IXSnakeServer.h>
|
||||||
#include <ixwebsocket/IXHttpServer.h>
|
#include <ixwebsocket/IXHttpServer.h>
|
||||||
#include <ixwebsocket/IXUserAgent.h>
|
#include <ixwebsocket/IXUserAgent.h>
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
#include <ixcobra/IXCobraConnection.h>
|
#include <ixcobra/IXCobraConnection.h>
|
||||||
#include <ixcobra/IXCobraMetricsPublisher.h>
|
#include <ixcobra/IXCobraMetricsPublisher.h>
|
||||||
#include <ixcrypto/IXUuid.h>
|
#include <ixcrypto/IXUuid.h>
|
||||||
#include <ixsentry/IXSentryClient.h>
|
|
||||||
#include <ixredis/IXRedisServer.h>
|
#include <ixredis/IXRedisServer.h>
|
||||||
|
#include <ixsentry/IXSentryClient.h>
|
||||||
#include <ixsnake/IXSnakeServer.h>
|
#include <ixsnake/IXSnakeServer.h>
|
||||||
#include <ixwebsocket/IXHttpServer.h>
|
#include <ixwebsocket/IXHttpServer.h>
|
||||||
#include <ixwebsocket/IXUserAgent.h>
|
#include <ixwebsocket/IXUserAgent.h>
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
#include <ixcobra/IXCobraConnection.h>
|
#include <ixcobra/IXCobraConnection.h>
|
||||||
#include <ixcobra/IXCobraMetricsPublisher.h>
|
#include <ixcobra/IXCobraMetricsPublisher.h>
|
||||||
#include <ixcrypto/IXUuid.h>
|
#include <ixcrypto/IXUuid.h>
|
||||||
#include <ixsentry/IXSentryClient.h>
|
|
||||||
#include <ixredis/IXRedisServer.h>
|
#include <ixredis/IXRedisServer.h>
|
||||||
|
#include <ixsentry/IXSentryClient.h>
|
||||||
#include <ixsnake/IXSnakeServer.h>
|
#include <ixsnake/IXSnakeServer.h>
|
||||||
#include <ixwebsocket/IXHttpServer.h>
|
#include <ixwebsocket/IXHttpServer.h>
|
||||||
#include <ixwebsocket/IXUserAgent.h>
|
#include <ixwebsocket/IXUserAgent.h>
|
||||||
|
@ -67,7 +67,8 @@ TEST_CASE("http server", "[httpd]")
|
|||||||
|
|
||||||
TEST_CASE("http server redirection", "[httpd_redirect]")
|
TEST_CASE("http server redirection", "[httpd_redirect]")
|
||||||
{
|
{
|
||||||
SECTION("Connect to a local HTTP server, with redirection enabled, but we do not follow redirects")
|
SECTION(
|
||||||
|
"Connect to a local HTTP server, with redirection enabled, but we do not follow redirects")
|
||||||
{
|
{
|
||||||
int port = getFreePort();
|
int port = getFreePort();
|
||||||
ix::HttpServer server(port, "127.0.0.1");
|
ix::HttpServer server(port, "127.0.0.1");
|
||||||
|
@ -56,7 +56,8 @@ namespace ix
|
|||||||
REQUIRE(compressAndDecompress("foo") == "foo");
|
REQUIRE(compressAndDecompress("foo") == "foo");
|
||||||
REQUIRE(compressAndDecompress("bar") == "bar");
|
REQUIRE(compressAndDecompress("bar") == "bar");
|
||||||
REQUIRE(compressAndDecompress("asdcaseqw`21897dehqwed") == "asdcaseqw`21897dehqwed");
|
REQUIRE(compressAndDecompress("asdcaseqw`21897dehqwed") == "asdcaseqw`21897dehqwed");
|
||||||
REQUIRE(compressAndDecompress("/usr/local/include/ixwebsocket/IXSocketAppleSSL.h") == "/usr/local/include/ixwebsocket/IXSocketAppleSSL.h");
|
REQUIRE(compressAndDecompress("/usr/local/include/ixwebsocket/IXSocketAppleSSL.h") ==
|
||||||
|
"/usr/local/include/ixwebsocket/IXSocketAppleSSL.h");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("vector api")
|
SECTION("vector api")
|
||||||
@ -64,8 +65,11 @@ namespace ix
|
|||||||
REQUIRE(compressAndDecompressVector("") == "");
|
REQUIRE(compressAndDecompressVector("") == "");
|
||||||
REQUIRE(compressAndDecompressVector("foo") == "foo");
|
REQUIRE(compressAndDecompressVector("foo") == "foo");
|
||||||
REQUIRE(compressAndDecompressVector("bar") == "bar");
|
REQUIRE(compressAndDecompressVector("bar") == "bar");
|
||||||
REQUIRE(compressAndDecompressVector("asdcaseqw`21897dehqwed") == "asdcaseqw`21897dehqwed");
|
REQUIRE(compressAndDecompressVector("asdcaseqw`21897dehqwed") ==
|
||||||
REQUIRE(compressAndDecompressVector("/usr/local/include/ixwebsocket/IXSocketAppleSSL.h") == "/usr/local/include/ixwebsocket/IXSocketAppleSSL.h");
|
"asdcaseqw`21897dehqwed");
|
||||||
|
REQUIRE(
|
||||||
|
compressAndDecompressVector("/usr/local/include/ixwebsocket/IXSocketAppleSSL.h") ==
|
||||||
|
"/usr/local/include/ixwebsocket/IXSocketAppleSSL.h");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
19
ws/ws.cpp
19
ws/ws.cpp
@ -11,13 +11,13 @@
|
|||||||
|
|
||||||
#include <cli11/CLI11.hpp>
|
#include <cli11/CLI11.hpp>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <ixbots/IXCobraMetricsToRedisBot.h>
|
||||||
#include <ixbots/IXCobraToPythonBot.h>
|
#include <ixbots/IXCobraToPythonBot.h>
|
||||||
#include <ixbots/IXCobraToSentryBot.h>
|
#include <ixbots/IXCobraToSentryBot.h>
|
||||||
#include <ixbots/IXCobraToStatsdBot.h>
|
#include <ixbots/IXCobraToStatsdBot.h>
|
||||||
#include <ixbots/IXCobraToStdoutBot.h>
|
#include <ixbots/IXCobraToStdoutBot.h>
|
||||||
#include <ixbots/IXCobraMetricsToRedisBot.h>
|
|
||||||
#include <ixredis/IXRedisClient.h>
|
|
||||||
#include <ixcore/utils/IXCoreLogger.h>
|
#include <ixcore/utils/IXCoreLogger.h>
|
||||||
|
#include <ixredis/IXRedisClient.h>
|
||||||
#include <ixsentry/IXSentryClient.h>
|
#include <ixsentry/IXSentryClient.h>
|
||||||
#include <ixwebsocket/IXNetSystem.h>
|
#include <ixwebsocket/IXNetSystem.h>
|
||||||
#include <ixwebsocket/IXSocket.h>
|
#include <ixwebsocket/IXSocket.h>
|
||||||
@ -193,8 +193,7 @@ int main(int argc, char** argv)
|
|||||||
"--limit_received_events", cobraBotConfig.limitReceivedEvents, "Max events per minute");
|
"--limit_received_events", cobraBotConfig.limitReceivedEvents, "Max events per minute");
|
||||||
app->add_option(
|
app->add_option(
|
||||||
"--max_events_per_minute", cobraBotConfig.maxEventsPerMinute, "Max events per minute");
|
"--max_events_per_minute", cobraBotConfig.maxEventsPerMinute, "Max events per minute");
|
||||||
app->add_option(
|
app->add_option("--batch_size", cobraBotConfig.batchSize, "Subscription batch size");
|
||||||
"--batch_size", cobraBotConfig.batchSize, "Subscription batch size");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
app.add_flag("--version", version, "Print ws version");
|
app.add_flag("--version", version, "Print ws version");
|
||||||
@ -358,7 +357,8 @@ int main(int argc, char** argv)
|
|||||||
cobra2python->add_option("--host", hostname, "Statsd host");
|
cobra2python->add_option("--host", hostname, "Statsd host");
|
||||||
cobra2python->add_option("--port", statsdPort, "Statsd port");
|
cobra2python->add_option("--port", statsdPort, "Statsd port");
|
||||||
cobra2python->add_option("--prefix", prefix, "Statsd prefix");
|
cobra2python->add_option("--prefix", prefix, "Statsd prefix");
|
||||||
cobra2python->add_option("--script", scriptPath, "Python script path")->check(CLI::ExistingPath);
|
cobra2python->add_option("--script", scriptPath, "Python script path")
|
||||||
|
->check(CLI::ExistingPath);
|
||||||
cobra2python->add_option("--pidfile", pidfile, "Pid file");
|
cobra2python->add_option("--pidfile", pidfile, "Pid file");
|
||||||
addTLSOptions(cobra2python);
|
addTLSOptions(cobra2python);
|
||||||
addCobraBotConfig(cobra2python);
|
addCobraBotConfig(cobra2python);
|
||||||
@ -604,8 +604,7 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret = (int) ix::cobra_to_python_bot(
|
ret = (int) ix::cobra_to_python_bot(cobraBotConfig, statsdClient, scriptPath);
|
||||||
cobraBotConfig, statsdClient, scriptPath);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (app.got_subcommand("cobra_to_sentry"))
|
else if (app.got_subcommand("cobra_to_sentry"))
|
||||||
@ -620,14 +619,12 @@ int main(int argc, char** argv)
|
|||||||
ix::RedisClient redisClient;
|
ix::RedisClient redisClient;
|
||||||
if (!redisClient.connect(hostname, redisPort))
|
if (!redisClient.connect(hostname, redisPort))
|
||||||
{
|
{
|
||||||
spdlog::error("Cannot connect to redis host {}:{}",
|
spdlog::error("Cannot connect to redis host {}:{}", redisHosts, redisPort);
|
||||||
redisHosts, redisPort);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret = (int) ix::cobra_metrics_to_redis_bot(
|
ret = (int) ix::cobra_metrics_to_redis_bot(cobraBotConfig, redisClient, verbose);
|
||||||
cobraBotConfig, redisClient, verbose);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (app.got_subcommand("snake"))
|
else if (app.got_subcommand("snake"))
|
||||||
|
4
ws/ws.h
4
ws/ws.h
@ -64,9 +64,7 @@ namespace ix
|
|||||||
bool disablePerMessageDeflate,
|
bool disablePerMessageDeflate,
|
||||||
const ix::SocketTLSOptions& tlsOptions);
|
const ix::SocketTLSOptions& tlsOptions);
|
||||||
|
|
||||||
int ws_redis_cli_main(const std::string& hostname,
|
int ws_redis_cli_main(const std::string& hostname, int port, const std::string& password);
|
||||||
int port,
|
|
||||||
const std::string& password);
|
|
||||||
|
|
||||||
int ws_redis_publish_main(const std::string& hostname,
|
int ws_redis_publish_main(const std::string& hostname,
|
||||||
int port,
|
int port,
|
||||||
|
@ -6,12 +6,12 @@
|
|||||||
|
|
||||||
#include "IXBench.h"
|
#include "IXBench.h"
|
||||||
#include "linenoise.hpp"
|
#include "linenoise.hpp"
|
||||||
|
#include <iostream>
|
||||||
#include <ixwebsocket/IXSocket.h>
|
#include <ixwebsocket/IXSocket.h>
|
||||||
#include <ixwebsocket/IXSocketTLSOptions.h>
|
#include <ixwebsocket/IXSocketTLSOptions.h>
|
||||||
#include <ixwebsocket/IXWebSocket.h>
|
#include <ixwebsocket/IXWebSocket.h>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
|
|
||||||
namespace ix
|
namespace ix
|
||||||
|
@ -4,17 +4,15 @@
|
|||||||
* Copyright (c) 2019 Machine Zone, Inc. All rights reserved.
|
* Copyright (c) 2019 Machine Zone, Inc. All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "linenoise.hpp"
|
||||||
|
#include <iostream>
|
||||||
#include <ixredis/IXRedisClient.h>
|
#include <ixredis/IXRedisClient.h>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iostream>
|
|
||||||
#include "linenoise.hpp"
|
|
||||||
|
|
||||||
namespace ix
|
namespace ix
|
||||||
{
|
{
|
||||||
int ws_redis_cli_main(const std::string& hostname,
|
int ws_redis_cli_main(const std::string& hostname, int port, const std::string& password)
|
||||||
int port,
|
|
||||||
const std::string& password)
|
|
||||||
{
|
{
|
||||||
RedisClient redisClient;
|
RedisClient redisClient;
|
||||||
if (!redisClient.connect(hostname, port))
|
if (!redisClient.connect(hostname, port))
|
||||||
@ -71,9 +69,7 @@ namespace ix
|
|||||||
{
|
{
|
||||||
if (response.first != RespType::String)
|
if (response.first != RespType::String)
|
||||||
{
|
{
|
||||||
std::cout << "("
|
std::cout << "(" << redisClient.getRespTypeDescription(response.first) << ")"
|
||||||
<< redisClient.getRespTypeDescription(response.first)
|
|
||||||
<< ")"
|
|
||||||
<< " ";
|
<< " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user