Skip to content

Commit ac0c218

Browse files
committed
clang-format
1 parent 299dc04 commit ac0c218

13 files changed

+235
-234
lines changed

ixwebsocket/IXSocketAppleSSL.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ namespace ix
105105
}
106106
}
107107

108-
OSStatus SocketAppleSSL::writeToSocket(SSLConnectionRef connection, const void* data, size_t* len)
108+
OSStatus SocketAppleSSL::writeToSocket(SSLConnectionRef connection,
109+
const void* data,
110+
size_t* len)
109111
{
110112
int fd = (int) (long) connection;
111113
if (fd < 0) return errSSLInternal;
@@ -165,7 +167,8 @@ namespace ix
165167

166168
_sslContext = SSLCreateContext(kCFAllocatorDefault, kSSLClientSide, kSSLStreamType);
167169

168-
SSLSetIOFuncs(_sslContext, SocketAppleSSL::readFromSocket, SocketAppleSSL::writeToSocket);
170+
SSLSetIOFuncs(
171+
_sslContext, SocketAppleSSL::readFromSocket, SocketAppleSSL::writeToSocket);
169172
SSLSetConnection(_sslContext, (SSLConnectionRef)(long) _sockfd);
170173
SSLSetProtocolVersionMin(_sslContext, kTLSProtocol12);
171174
SSLSetPeerDomainName(_sslContext, host.c_str(), host.size());

ixwebsocket/IXSocketServer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include "IXSocketConnect.h"
1212
#include "IXSocketFactory.h"
1313
#include <assert.h>
14-
#include <stdio.h>
1514
#include <sstream>
15+
#include <stdio.h>
1616
#include <string.h>
1717

1818
namespace ix

test/IXCobraChatTest.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ namespace
3737
class CobraChat
3838
{
3939
public:
40-
CobraChat(const std::string& user,
41-
const std::string& session,
42-
const std::string& endpoint);
40+
CobraChat(const std::string& user, const std::string& session, const std::string& endpoint);
4341

4442
void subscribe(const std::string& channel);
4543
void start();

ws/ws.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,9 @@ int main(int argc, char** argv)
269269
cobra2sentry->add_option("--rolesecret", rolesecret, "Role secret")->required();
270270
cobra2sentry->add_option("--dsn", dsn, "Sentry DSN");
271271
cobra2sentry->add_option("--jobs", jobs, "Number of thread sending events to Sentry");
272-
cobra2sentry->add_option("--queue_size", maxQueueSize, "Size of the queue to hold messages before they are sent to Sentry");
272+
cobra2sentry->add_option("--queue_size",
273+
maxQueueSize,
274+
"Size of the queue to hold messages before they are sent to Sentry");
273275
cobra2sentry->add_option("channel", channel, "Channel")->required();
274276
cobra2sentry->add_flag("-v", verbose, "Verbose");
275277
cobra2sentry->add_flag("-s", strict, "Strict mode. Error out when sending to sentry fails");
@@ -474,8 +476,14 @@ int main(int argc, char** argv)
474476
}
475477
else if (app.got_subcommand("snake"))
476478
{
477-
ret = ix::ws_snake_main(
478-
port, hostname, redisHosts, redisPort, redisPassword, verbose, appsConfigPath, tlsOptions);
479+
ret = ix::ws_snake_main(port,
480+
hostname,
481+
redisHosts,
482+
redisPort,
483+
redisPassword,
484+
verbose,
485+
appsConfigPath,
486+
tlsOptions);
479487
}
480488
else if (app.got_subcommand("httpd"))
481489
{

ws/ws_broadcast_server.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
*/
66

77
#include <ixwebsocket/IXWebSocketServer.h>
8-
#include <sstream>
98
#include <spdlog/spdlog.h>
9+
#include <sstream>
1010

1111

1212
namespace ix
@@ -38,7 +38,8 @@ namespace ix
3838
else if (msg->type == ix::WebSocketMessageType::Close)
3939
{
4040
spdlog::info("Closed connection: code {} reason {}",
41-
msg->closeInfo.code, msg->closeInfo.reason);
41+
msg->closeInfo.code,
42+
msg->closeInfo.reason);
4243
}
4344
else if (msg->type == ix::WebSocketMessageType::Error)
4445
{

ws/ws_chat.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#include <ixwebsocket/IXSocket.h>
1515
#include <ixwebsocket/IXWebSocket.h>
1616
#include <queue>
17-
#include <sstream>
1817
#include <spdlog/spdlog.h>
18+
#include <sstream>
1919

2020
// for convenience
2121
using json = nlohmann::json;

ws/ws_cobra_to_sentry.cpp

+79-87
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,24 @@
99
#include <condition_variable>
1010
#include <ixcobra/IXCobraConnection.h>
1111
#include <ixsentry/IXSentryClient.h>
12+
#include <map>
1213
#include <mutex>
1314
#include <queue>
1415
#include <spdlog/spdlog.h>
1516
#include <sstream>
1617
#include <thread>
1718
#include <vector>
18-
#include <map>
1919

2020
namespace ix
2121
{
2222
class QueueManager
2323
{
2424
public:
25-
QueueManager(size_t maxQueueSize,
26-
std::atomic<bool> &stop) :
27-
_maxQueueSize(maxQueueSize),
28-
_stop(stop) {}
25+
QueueManager(size_t maxQueueSize, std::atomic<bool>& stop)
26+
: _maxQueueSize(maxQueueSize)
27+
, _stop(stop)
28+
{
29+
}
2930

3031
Json::Value pop();
3132
void add(Json::Value msg);
@@ -136,95 +137,90 @@ namespace ix
136137

137138
std::thread t1(timer);
138139

139-
auto sentrySender = [&queueManager,
140-
verbose,
141-
&errorSending,
142-
&sentCount,
143-
&stop,
144-
&throttled,
145-
&dsn] {
146-
SentryClient sentryClient(dsn);
147-
148-
while (true)
149-
{
150-
Json::Value msg = queueManager.pop();
151-
152-
if (msg.isNull()) continue;
153-
if (stop) return;
154-
155-
auto ret = sentryClient.send(msg, verbose);
156-
HttpResponsePtr response = ret.first;
140+
auto sentrySender =
141+
[&queueManager, verbose, &errorSending, &sentCount, &stop, &throttled, &dsn] {
142+
SentryClient sentryClient(dsn);
157143

158-
if (!response)
144+
while (true)
159145
{
160-
spdlog::warn("Null HTTP Response");
161-
continue;
162-
}
146+
Json::Value msg = queueManager.pop();
163147

164-
if (verbose)
165-
{
166-
for (auto it : response->headers)
167-
{
168-
spdlog::info("{}: {}", it.first, it.second);
169-
}
148+
if (msg.isNull()) continue;
149+
if (stop) return;
170150

171-
spdlog::info("Upload size: {}", response->uploadSize);
172-
spdlog::info("Download size: {}", response->downloadSize);
151+
auto ret = sentryClient.send(msg, verbose);
152+
HttpResponsePtr response = ret.first;
173153

174-
spdlog::info("Status: {}", response->statusCode);
175-
if (response->errorCode != HttpErrorCode::Ok)
154+
if (!response)
176155
{
177-
spdlog::info("error message: {}", response->errorMsg);
156+
spdlog::warn("Null HTTP Response");
157+
continue;
178158
}
179159

180-
if (response->headers["Content-Type"] != "application/octet-stream")
160+
if (verbose)
181161
{
182-
spdlog::info("payload: {}", response->payload);
183-
}
184-
}
162+
for (auto it : response->headers)
163+
{
164+
spdlog::info("{}: {}", it.first, it.second);
165+
}
185166

186-
if (response->statusCode != 200)
187-
{
188-
spdlog::error("Error sending data to sentry: {}", response->statusCode);
189-
spdlog::error("Body: {}", ret.second);
190-
spdlog::error("Response: {}", response->payload);
191-
errorSending = true;
167+
spdlog::info("Upload size: {}", response->uploadSize);
168+
spdlog::info("Download size: {}", response->downloadSize);
192169

193-
// Error 429 Too Many Requests
194-
if (response->statusCode == 429)
195-
{
196-
auto retryAfter = response->headers["Retry-After"];
197-
std::stringstream ss;
198-
ss << retryAfter;
199-
int seconds;
200-
ss >> seconds;
170+
spdlog::info("Status: {}", response->statusCode);
171+
if (response->errorCode != HttpErrorCode::Ok)
172+
{
173+
spdlog::info("error message: {}", response->errorMsg);
174+
}
201175

202-
if (!ss.eof() || ss.fail())
176+
if (response->headers["Content-Type"] != "application/octet-stream")
203177
{
204-
seconds = 30;
205-
spdlog::warn("Error parsing Retry-After header. "
206-
"Using {} for the sleep duration",
207-
seconds);
178+
spdlog::info("payload: {}", response->payload);
208179
}
180+
}
209181

210-
spdlog::warn("Error 429 - Too Many Requests. ws will sleep "
211-
"and retry after {} seconds",
212-
retryAfter);
182+
if (response->statusCode != 200)
183+
{
184+
spdlog::error("Error sending data to sentry: {}", response->statusCode);
185+
spdlog::error("Body: {}", ret.second);
186+
spdlog::error("Response: {}", response->payload);
187+
errorSending = true;
213188

214-
throttled = true;
215-
auto duration = std::chrono::seconds(seconds);
216-
std::this_thread::sleep_for(duration);
217-
throttled = false;
189+
// Error 429 Too Many Requests
190+
if (response->statusCode == 429)
191+
{
192+
auto retryAfter = response->headers["Retry-After"];
193+
std::stringstream ss;
194+
ss << retryAfter;
195+
int seconds;
196+
ss >> seconds;
197+
198+
if (!ss.eof() || ss.fail())
199+
{
200+
seconds = 30;
201+
spdlog::warn("Error parsing Retry-After header. "
202+
"Using {} for the sleep duration",
203+
seconds);
204+
}
205+
206+
spdlog::warn("Error 429 - Too Many Requests. ws will sleep "
207+
"and retry after {} seconds",
208+
retryAfter);
209+
210+
throttled = true;
211+
auto duration = std::chrono::seconds(seconds);
212+
std::this_thread::sleep_for(duration);
213+
throttled = false;
214+
}
215+
}
216+
else
217+
{
218+
++sentCount;
218219
}
219-
}
220-
else
221-
{
222-
++sentCount;
223-
}
224220

225-
if (stop) return;
226-
}
227-
};
221+
if (stop) return;
222+
}
223+
};
228224

229225
// Create a thread pool
230226
spdlog::info("Starting {} sentry sender jobs", jobs);
@@ -241,12 +237,11 @@ namespace ix
241237
verbose,
242238
&throttled,
243239
&receivedCount,
244-
&queueManager](
245-
ix::CobraConnectionEventType eventType,
246-
const std::string& errMsg,
247-
const ix::WebSocketHttpHeaders& headers,
248-
const std::string& subscriptionId,
249-
CobraConnection::MsgId msgId) {
240+
&queueManager](ix::CobraConnectionEventType eventType,
241+
const std::string& errMsg,
242+
const ix::WebSocketHttpHeaders& headers,
243+
const std::string& subscriptionId,
244+
CobraConnection::MsgId msgId) {
250245
if (eventType == ix::CobraConnection_EventType_Open)
251246
{
252247
spdlog::info("Subscriber connected");
@@ -265,11 +260,8 @@ namespace ix
265260
spdlog::info("Subscriber authenticated");
266261
conn.subscribe(channel,
267262
filter,
268-
[&jsonWriter,
269-
verbose,
270-
&throttled,
271-
&receivedCount,
272-
&queueManager](const Json::Value& msg) {
263+
[&jsonWriter, verbose, &throttled, &receivedCount, &queueManager](
264+
const Json::Value& msg) {
273265
if (verbose)
274266
{
275267
spdlog::info(jsonWriter.write(msg));

0 commit comments

Comments
 (0)