clang-format

This commit is contained in:
Benjamin Sergeant 2019-12-30 08:46:18 -08:00
parent 8b5e42fe84
commit d60777b9cc
13 changed files with 239 additions and 238 deletions

View File

@ -105,7 +105,9 @@ namespace ix
} }
} }
OSStatus SocketAppleSSL::writeToSocket(SSLConnectionRef connection, const void* data, size_t* len) OSStatus SocketAppleSSL::writeToSocket(SSLConnectionRef connection,
const void* data,
size_t* len)
{ {
int fd = (int) (long) connection; int fd = (int) (long) connection;
if (fd < 0) return errSSLInternal; if (fd < 0) return errSSLInternal;
@ -165,7 +167,8 @@ namespace ix
_sslContext = SSLCreateContext(kCFAllocatorDefault, kSSLClientSide, kSSLStreamType); _sslContext = SSLCreateContext(kCFAllocatorDefault, kSSLClientSide, kSSLStreamType);
SSLSetIOFuncs(_sslContext, SocketAppleSSL::readFromSocket, SocketAppleSSL::writeToSocket); SSLSetIOFuncs(
_sslContext, SocketAppleSSL::readFromSocket, SocketAppleSSL::writeToSocket);
SSLSetConnection(_sslContext, (SSLConnectionRef)(long) _sockfd); SSLSetConnection(_sslContext, (SSLConnectionRef)(long) _sockfd);
SSLSetProtocolVersionMin(_sslContext, kTLSProtocol12); SSLSetProtocolVersionMin(_sslContext, kTLSProtocol12);
SSLSetPeerDomainName(_sslContext, host.c_str(), host.size()); SSLSetPeerDomainName(_sslContext, host.c_str(), host.size());

View File

@ -11,8 +11,8 @@
#include "IXSocketConnect.h" #include "IXSocketConnect.h"
#include "IXSocketFactory.h" #include "IXSocketFactory.h"
#include <assert.h> #include <assert.h>
#include <stdio.h>
#include <sstream> #include <sstream>
#include <stdio.h>
#include <string.h> #include <string.h>
namespace ix namespace ix

View File

@ -37,9 +37,7 @@ namespace
class CobraChat class CobraChat
{ {
public: public:
CobraChat(const std::string& user, CobraChat(const std::string& user, const std::string& session, const std::string& endpoint);
const std::string& session,
const std::string& endpoint);
void subscribe(const std::string& channel); void subscribe(const std::string& channel);
void start(); void start();

View File

@ -269,7 +269,9 @@ int main(int argc, char** argv)
cobra2sentry->add_option("--rolesecret", rolesecret, "Role secret")->required(); cobra2sentry->add_option("--rolesecret", rolesecret, "Role secret")->required();
cobra2sentry->add_option("--dsn", dsn, "Sentry DSN"); cobra2sentry->add_option("--dsn", dsn, "Sentry DSN");
cobra2sentry->add_option("--jobs", jobs, "Number of thread sending events to Sentry"); cobra2sentry->add_option("--jobs", jobs, "Number of thread sending events to Sentry");
cobra2sentry->add_option("--queue_size", maxQueueSize, "Size of the queue to hold messages before they are sent to Sentry"); cobra2sentry->add_option("--queue_size",
maxQueueSize,
"Size of the queue to hold messages before they are sent to Sentry");
cobra2sentry->add_option("channel", channel, "Channel")->required(); cobra2sentry->add_option("channel", channel, "Channel")->required();
cobra2sentry->add_flag("-v", verbose, "Verbose"); cobra2sentry->add_flag("-v", verbose, "Verbose");
cobra2sentry->add_flag("-s", strict, "Strict mode. Error out when sending to sentry fails"); cobra2sentry->add_flag("-s", strict, "Strict mode. Error out when sending to sentry fails");
@ -474,8 +476,14 @@ int main(int argc, char** argv)
} }
else if (app.got_subcommand("snake")) else if (app.got_subcommand("snake"))
{ {
ret = ix::ws_snake_main( ret = ix::ws_snake_main(port,
port, hostname, redisHosts, redisPort, redisPassword, verbose, appsConfigPath, tlsOptions); hostname,
redisHosts,
redisPort,
redisPassword,
verbose,
appsConfigPath,
tlsOptions);
} }
else if (app.got_subcommand("httpd")) else if (app.got_subcommand("httpd"))
{ {

View File

@ -5,8 +5,8 @@
*/ */
#include <ixwebsocket/IXWebSocketServer.h> #include <ixwebsocket/IXWebSocketServer.h>
#include <sstream>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <sstream>
namespace ix namespace ix
@ -38,7 +38,8 @@ namespace ix
else if (msg->type == ix::WebSocketMessageType::Close) else if (msg->type == ix::WebSocketMessageType::Close)
{ {
spdlog::info("Closed connection: code {} reason {}", spdlog::info("Closed connection: code {} reason {}",
msg->closeInfo.code, msg->closeInfo.reason); msg->closeInfo.code,
msg->closeInfo.reason);
} }
else if (msg->type == ix::WebSocketMessageType::Error) else if (msg->type == ix::WebSocketMessageType::Error)
{ {

View File

@ -14,8 +14,8 @@
#include <ixwebsocket/IXSocket.h> #include <ixwebsocket/IXSocket.h>
#include <ixwebsocket/IXWebSocket.h> #include <ixwebsocket/IXWebSocket.h>
#include <queue> #include <queue>
#include <sstream>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <sstream>
// for convenience // for convenience
using json = nlohmann::json; using json = nlohmann::json;

View File

@ -9,23 +9,24 @@
#include <condition_variable> #include <condition_variable>
#include <ixcobra/IXCobraConnection.h> #include <ixcobra/IXCobraConnection.h>
#include <ixsentry/IXSentryClient.h> #include <ixsentry/IXSentryClient.h>
#include <map>
#include <mutex> #include <mutex>
#include <queue> #include <queue>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <sstream> #include <sstream>
#include <thread> #include <thread>
#include <vector> #include <vector>
#include <map>
namespace ix namespace ix
{ {
class QueueManager class QueueManager
{ {
public: public:
QueueManager(size_t maxQueueSize, QueueManager(size_t maxQueueSize, std::atomic<bool>& stop)
std::atomic<bool> &stop) : : _maxQueueSize(maxQueueSize)
_maxQueueSize(maxQueueSize), , _stop(stop)
_stop(stop) {} {
}
Json::Value pop(); Json::Value pop();
void add(Json::Value msg); void add(Json::Value msg);
@ -136,13 +137,8 @@ namespace ix
std::thread t1(timer); std::thread t1(timer);
auto sentrySender = [&queueManager, auto sentrySender =
verbose, [&queueManager, verbose, &errorSending, &sentCount, &stop, &throttled, &dsn] {
&errorSending,
&sentCount,
&stop,
&throttled,
&dsn] {
SentryClient sentryClient(dsn); SentryClient sentryClient(dsn);
while (true) while (true)
@ -241,8 +237,7 @@ namespace ix
verbose, verbose,
&throttled, &throttled,
&receivedCount, &receivedCount,
&queueManager]( &queueManager](ix::CobraConnectionEventType eventType,
ix::CobraConnectionEventType eventType,
const std::string& errMsg, const std::string& errMsg,
const ix::WebSocketHttpHeaders& headers, const ix::WebSocketHttpHeaders& headers,
const std::string& subscriptionId, const std::string& subscriptionId,
@ -265,11 +260,8 @@ namespace ix
spdlog::info("Subscriber authenticated"); spdlog::info("Subscriber authenticated");
conn.subscribe(channel, conn.subscribe(channel,
filter, filter,
[&jsonWriter, [&jsonWriter, verbose, &throttled, &receivedCount, &queueManager](
verbose, const Json::Value& msg) {
&throttled,
&receivedCount,
&queueManager](const Json::Value& msg) {
if (verbose) if (verbose)
{ {
spdlog::info(jsonWriter.write(msg)); spdlog::info(jsonWriter.write(msg));

View File

@ -22,10 +22,11 @@ namespace
class QueueManager class QueueManager
{ {
public: public:
QueueManager(size_t maxQueueSize, QueueManager(size_t maxQueueSize, std::atomic<bool>& stop)
std::atomic<bool> &stop) : : _maxQueueSize(maxQueueSize)
_maxQueueSize(maxQueueSize), , _stop(stop)
_stop(stop) {} {
}
Json::Value pop(); Json::Value pop();
void add(Json::Value msg); void add(Json::Value msg);
@ -67,7 +68,7 @@ namespace
_condition.notify_one(); _condition.notify_one();
} }
} }
} } // namespace
namespace ix namespace ix
{ {
@ -152,13 +153,7 @@ namespace ix
std::thread t1(timer); std::thread t1(timer);
auto statsdSender = [&queueManager, auto statsdSender = [&queueManager, &host, &port, &sentCount, &tokens, &prefix, &stop] {
&host,
&port,
&sentCount,
&tokens,
&prefix,
&stop] {
// statsd client // statsd client
// test with netcat as a server: `nc -ul 8125` // test with netcat as a server: `nc -ul 8125`
bool statsdBatch = true; bool statsdBatch = true;
@ -191,13 +186,9 @@ namespace ix
std::thread t2(statsdSender); std::thread t2(statsdSender);
conn.setEventCallback([&conn, conn.setEventCallback(
&channel, [&conn, &channel, &filter, &jsonWriter, verbose, &queueManager, &receivedCount](
&filter, ix::CobraConnectionEventType eventType,
&jsonWriter,
verbose,
&queueManager,
&receivedCount](ix::CobraConnectionEventType eventType,
const std::string& errMsg, const std::string& errMsg,
const ix::WebSocketHttpHeaders& headers, const ix::WebSocketHttpHeaders& headers,
const std::string& subscriptionId, const std::string& subscriptionId,

View File

@ -4,12 +4,12 @@
* Copyright (c) 2018-2019 Machine Zone, Inc. All rights reserved. * Copyright (c) 2018-2019 Machine Zone, Inc. All rights reserved.
*/ */
#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
{ {

View File

@ -101,8 +101,8 @@ namespace ix
}); });
// Client connection // Client connection
webSocket->setOnMessageCallback([state, remoteUrl, verbose]( webSocket->setOnMessageCallback(
const WebSocketMessagePtr& msg) { [state, remoteUrl, verbose](const WebSocketMessagePtr& msg) {
if (msg->type == ix::WebSocketMessageType::Open) if (msg->type == ix::WebSocketMessageType::Open)
{ {
spdlog::info("New connection from client"); spdlog::info("New connection from client");

View File

@ -14,8 +14,8 @@
#include <ixwebsocket/IXSocketTLSOptions.h> #include <ixwebsocket/IXSocketTLSOptions.h>
#include <ixwebsocket/IXWebSocket.h> #include <ixwebsocket/IXWebSocket.h>
#include <msgpack11/msgpack11.hpp> #include <msgpack11/msgpack11.hpp>
#include <spdlog/spdlog.h>
#include <mutex> #include <mutex>
#include <spdlog/spdlog.h>
#include <sstream> #include <sstream>
#include <vector> #include <vector>

View File

@ -14,8 +14,8 @@
#include <ixwebsocket/IXSocketTLSOptions.h> #include <ixwebsocket/IXSocketTLSOptions.h>
#include <ixwebsocket/IXWebSocket.h> #include <ixwebsocket/IXWebSocket.h>
#include <msgpack11/msgpack11.hpp> #include <msgpack11/msgpack11.hpp>
#include <spdlog/spdlog.h>
#include <mutex> #include <mutex>
#include <spdlog/spdlog.h>
#include <sstream> #include <sstream>
#include <vector> #include <vector>

View File

@ -70,11 +70,13 @@ namespace ix
if (readyState == ReadyState::Open) if (readyState == ReadyState::Open)
{ {
++receivers; ++receivers;
client->send(msg->str, client->send(
msg->binary, msg->str, msg->binary, [&id](int current, int total) -> bool {
[&id](int current, int total) -> bool {
spdlog::info("{}: [client {}]: Step {} out of {}", spdlog::info("{}: [client {}]: Step {} out of {}",
"ws_transfer", id, current, total); "ws_transfer",
id,
current,
total);
return true; return true;
}); });
do do
@ -82,7 +84,9 @@ namespace ix
size_t bufferedAmount = client->bufferedAmount(); size_t bufferedAmount = client->bufferedAmount();
spdlog::info("{}: [client {}]: {} bytes left to send", spdlog::info("{}: [client {}]: {} bytes left to send",
"ws_transfer", id, bufferedAmount); "ws_transfer",
id,
bufferedAmount);
std::this_thread::sleep_for(std::chrono::milliseconds(500)); std::this_thread::sleep_for(std::chrono::milliseconds(500));
@ -97,8 +101,12 @@ namespace ix
: readyState == ReadyState::Closing ? "Closing" : "Closed"; : readyState == ReadyState::Closing ? "Closing" : "Closed";
size_t bufferedAmount = client->bufferedAmount(); size_t bufferedAmount = client->bufferedAmount();
spdlog::info("{}: [client {}]: has readystate {} bytes left to be sent", spdlog::info(
"ws_transfer", id, readyStateString, bufferedAmount); "{}: [client {}]: has readystate {} bytes left to be sent",
"ws_transfer",
id,
readyStateString,
bufferedAmount);
} }
} }
} }