Skip to content

Commit ba00df5

Browse files
committed
Fix indentation
1 parent f1cc38e commit ba00df5

14 files changed

+248
-244
lines changed

examples/Broadcast.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ int main() {
1818
* You may swap to using uWS:App() if you don't need SSL */
1919
uWS::SSLApp app = uWS::SSLApp({
2020
/* There are example certificates in uWebSockets.js repo */
21-
.key_file_name = "misc/key.pem",
22-
.cert_file_name = "misc/cert.pem",
23-
.passphrase = "1234"
24-
}).ws<PerSocketData>("/*", {
21+
.key_file_name = "misc/key.pem",
22+
.cert_file_name = "misc/cert.pem",
23+
.passphrase = "1234"
24+
}).ws<PerSocketData>("/*", {
2525
/* Settings */
2626
.compression = uWS::SHARED_COMPRESSOR,
2727
.maxPayloadLength = 16 * 1024 * 1024,

examples/BroadcastingEchoServer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ int main() {
1515
* You may swap to using uWS:App() if you don't need SSL */
1616
uWS::SSLApp *app = new uWS::SSLApp({
1717
/* There are example certificates in uWebSockets.js repo */
18-
.key_file_name = "misc/key.pem",
19-
.cert_file_name = "misc/cert.pem",
20-
.passphrase = "1234"
21-
});
18+
.key_file_name = "misc/key.pem",
19+
.cert_file_name = "misc/cert.pem",
20+
.passphrase = "1234"
21+
});
2222

2323
app->ws<PerSocketData>("/*", {
2424
/* Settings */

examples/Crc32.cpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -32,40 +32,40 @@ uint32_t crc32(const char *s, size_t n, uint32_t crc = 0xFFFFFFFF) {
3232

3333
int main() {
3434

35-
uWS::SSLApp({
36-
.key_file_name = "misc/key.pem",
37-
.cert_file_name = "misc/cert.pem",
38-
.passphrase = "1234"
39-
}).post("/*", [](auto *res, auto *req) {
35+
uWS::SSLApp({
36+
.key_file_name = "misc/key.pem",
37+
.cert_file_name = "misc/cert.pem",
38+
.passphrase = "1234"
39+
}).post("/*", [](auto *res, auto *req) {
4040

41-
/* Display the headers */
42-
std::cout << " --- " << req->getUrl() << " --- " << std::endl;
43-
for (auto [key, value] : *req) {
44-
std::cout << key << ": " << value << std::endl;
45-
}
41+
/* Display the headers */
42+
std::cout << " --- " << req->getUrl() << " --- " << std::endl;
43+
for (auto [key, value] : *req) {
44+
std::cout << key << ": " << value << std::endl;
45+
}
4646

47-
auto isAborted = std::make_shared<bool>(false);
48-
uint32_t crc = 0xFFFFFFFF;
49-
res->onData([res, isAborted, crc](std::string_view chunk, bool isFin) mutable {
50-
if (chunk.length()) {
51-
crc = crc32(chunk.data(), chunk.length(), crc);
52-
}
47+
auto isAborted = std::make_shared<bool>(false);
48+
uint32_t crc = 0xFFFFFFFF;
49+
res->onData([res, isAborted, crc](std::string_view chunk, bool isFin) mutable {
50+
if (chunk.length()) {
51+
crc = crc32(chunk.data(), chunk.length(), crc);
52+
}
5353

54-
if (isFin && !*isAborted) {
55-
std::stringstream s;
56-
s << std::hex << (~crc) << std::endl;
57-
res->end(s.str());
58-
}
59-
});
54+
if (isFin && !*isAborted) {
55+
std::stringstream s;
56+
s << std::hex << (~crc) << std::endl;
57+
res->end(s.str());
58+
}
59+
});
6060

61-
res->onAborted([isAborted]() {
62-
*isAborted = true;
63-
});
64-
}).listen(3000, [](auto *listen_socket) {
65-
if (listen_socket) {
66-
std::cerr << "Listening on port " << 3000 << std::endl;
67-
}
68-
}).run();
61+
res->onAborted([isAborted]() {
62+
*isAborted = true;
63+
});
64+
}).listen(3000, [](auto *listen_socket) {
65+
if (listen_socket) {
66+
std::cerr << "Listening on port " << 3000 << std::endl;
67+
}
68+
}).run();
6969

70-
std::cout << "Failed to listen on port 3000" << std::endl;
70+
std::cout << "Failed to listen on port 3000" << std::endl;
7171
}

examples/EchoBody.cpp

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,35 @@
55

66
int main() {
77

8-
uWS::App().get("/*", [](auto *res, auto */*req*/) {
9-
/* Technically the any route could be used likewise, but GET is optimized like this */
10-
res->end();
11-
}).any("/*", [](auto *res, auto */*req*/) {
12-
std::unique_ptr<std::string> buffer;
13-
res->onData([res, buffer = std::move(buffer)](std::string_view chunk, bool isFin) mutable {
14-
if (isFin) [[likely]] {
15-
if (buffer.get()) [[unlikely]] {
16-
buffer->append(chunk);
17-
res->end(*buffer);
18-
} else {
19-
res->end(chunk);
20-
}
21-
} else {
22-
if (!buffer.get()) {
23-
buffer = std::make_unique<std::string>(chunk);
24-
} else {
25-
buffer->append(chunk);
26-
}
27-
}
28-
});
8+
uWS::App().get("/*", [](auto *res, auto */*req*/) {
9+
/* Technically the any route could be used likewise, but GET is optimized like this */
10+
res->end();
11+
}).any("/*", [](auto *res, auto */*req*/) {
12+
std::unique_ptr<std::string> buffer;
13+
res->onData([res, buffer = std::move(buffer)](std::string_view chunk, bool isFin) mutable {
14+
if (isFin) [[likely]] {
15+
if (buffer.get()) [[unlikely]] {
16+
buffer->append(chunk);
17+
res->end(*buffer);
18+
} else {
19+
res->end(chunk);
20+
}
21+
} else {
22+
if (!buffer.get()) {
23+
buffer = std::make_unique<std::string>(chunk);
24+
} else {
25+
buffer->append(chunk);
26+
}
27+
}
28+
});
2929

30-
/* In this particular case we actually don't need to know this, as we only rely on RAII above. */
31-
res->onAborted([]() {});
32-
}).listen(3000, [](auto *listen_socket) {
33-
if (listen_socket) {
34-
std::cerr << "Listening on port " << 3000 << std::endl;
35-
}
36-
}).run();
30+
/* In this particular case we actually don't need to know this, as we only rely on RAII above. */
31+
res->onAborted([]() {});
32+
}).listen(3000, [](auto *listen_socket) {
33+
if (listen_socket) {
34+
std::cerr << "Listening on port " << 3000 << std::endl;
35+
}
36+
}).run();
3737

38-
std::cout << "Failed to listen on port 3000" << std::endl;
38+
std::cout << "Failed to listen on port 3000" << std::endl;
3939
}

examples/EchoServer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ int main() {
1414
* You may swap to using uWS:App() if you don't need SSL */
1515
uWS::App({
1616
/* There are example certificates in uWebSockets.js repo */
17-
.key_file_name = "misc/key.pem",
18-
.cert_file_name = "misc/cert.pem",
19-
.passphrase = "1234"
20-
}).ws<PerSocketData>("/*", {
17+
.key_file_name = "misc/key.pem",
18+
.cert_file_name = "misc/cert.pem",
19+
.passphrase = "1234"
20+
}).ws<PerSocketData>("/*", {
2121
/* Settings */
2222
.compression = uWS::CompressOptions(uWS::DEDICATED_COMPRESSOR_4KB | uWS::DEDICATED_DECOMPRESSOR),
2323
.maxPayloadLength = 100 * 1024 * 1024,

examples/HelloWorld.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
/* Note that uWS::SSLApp({options}) is the same as uWS::App() when compiled without SSL support */
44

55
int main() {
6-
/* Overly simple hello world app */
7-
uWS::SSLApp({
8-
.key_file_name = "misc/key.pem",
9-
.cert_file_name = "misc/cert.pem",
10-
.passphrase = "1234"
11-
}).get("/*", [](auto *res, auto */*req*/) {
12-
res->end("Hello world!");
13-
}).listen(3000, [](auto *listen_socket) {
14-
if (listen_socket) {
15-
std::cout << "Listening on port " << 3000 << std::endl;
16-
}
17-
}).run();
6+
/* Overly simple hello world app */
7+
uWS::SSLApp({
8+
.key_file_name = "misc/key.pem",
9+
.cert_file_name = "misc/cert.pem",
10+
.passphrase = "1234"
11+
}).get("/*", [](auto *res, auto */*req*/) {
12+
res->end("Hello world!");
13+
}).listen(3000, [](auto *listen_socket) {
14+
if (listen_socket) {
15+
std::cout << "Listening on port " << 3000 << std::endl;
16+
}
17+
}).run();
1818

19-
std::cout << "Failed to listen on port 3000" << std::endl;
19+
std::cout << "Failed to listen on port 3000" << std::endl;
2020
}

examples/Http3Server.cpp

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -9,84 +9,84 @@
99
/* Todo: use onWritable and tryEnd instead of end */
1010
int main() {
1111

12-
/* Read video file to memory */
13-
std::ifstream file("video.mp4", std::ios::binary | std::ios::ate);
14-
std::streamsize size = file.tellg();
15-
file.seekg(0, std::ios::beg);
12+
/* Read video file to memory */
13+
std::ifstream file("video.mp4", std::ios::binary | std::ios::ate);
14+
std::streamsize size = file.tellg();
15+
file.seekg(0, std::ios::beg);
1616

17-
std::vector<char> buffer(size);
18-
if (!file.read(buffer.data(), size)) {
19-
std::cout << "Failed to load video.mp4" << std::endl;
20-
return 0;
21-
}
17+
std::vector<char> buffer(size);
18+
if (!file.read(buffer.data(), size)) {
19+
std::cout << "Failed to load video.mp4" << std::endl;
20+
return 0;
21+
}
2222

23-
/* We need a bootstrapping server that instructs
24-
* the web browser to use HTTP3 */
25-
(*new uWS::SSLApp({
26-
.key_file_name = "misc/key.pem",
27-
.cert_file_name = "misc/cert.pem",
28-
.passphrase = "1234"
29-
})).get("/*", [&buffer](auto *res, auto *req) {
30-
res->writeHeader("Alt-Svc", "h3=\":9004\"");
31-
res->writeHeader("Alternative-Protocol", "quic:9004");
32-
res->end("<html><h1>This is not HTTP3! Try refreshing (works in Firefox!)</h1></html>");
33-
}).listen(9004, [](auto *listen_socket) {
34-
if (listen_socket) {
35-
std::cout << "Bootstrapping server Listening on port " << 9004 << std::endl;
36-
}
37-
});
23+
/* We need a bootstrapping server that instructs
24+
* the web browser to use HTTP3 */
25+
(*new uWS::SSLApp({
26+
.key_file_name = "misc/key.pem",
27+
.cert_file_name = "misc/cert.pem",
28+
.passphrase = "1234"
29+
})).get("/*", [&buffer](auto *res, auto *req) {
30+
res->writeHeader("Alt-Svc", "h3=\":9004\"");
31+
res->writeHeader("Alternative-Protocol", "quic:9004");
32+
res->end("<html><h1>This is not HTTP3! Try refreshing (works in Firefox!)</h1></html>");
33+
}).listen(9004, [](auto *listen_socket) {
34+
if (listen_socket) {
35+
std::cout << "Bootstrapping server Listening on port " << 9004 << std::endl;
36+
}
37+
});
3838

39-
/* And we serve the video over HTTP3 */
40-
uWS::H3App({
41-
.key_file_name = "misc/key.pem",
42-
.cert_file_name = "misc/cert.pem",
43-
.passphrase = "1234"
44-
}).get("/*", [&buffer](auto *res, auto *req) {
45-
res->end("<html><h1>Welcome to HTTP3! <a href=\"video.mp4\">Go see a movie</a></html></h1>");
46-
}).get("/video.mp4", [&buffer](auto *res, auto *req) {
47-
/* Send back a video */
48-
res->end({&buffer[0], buffer.size()});
49-
}).post("/*", [](auto *res, auto *req) {
39+
/* And we serve the video over HTTP3 */
40+
uWS::H3App({
41+
.key_file_name = "misc/key.pem",
42+
.cert_file_name = "misc/cert.pem",
43+
.passphrase = "1234"
44+
}).get("/*", [&buffer](auto *res, auto *req) {
45+
res->end("<html><h1>Welcome to HTTP3! <a href=\"video.mp4\">Go see a movie</a></html></h1>");
46+
}).get("/video.mp4", [&buffer](auto *res, auto *req) {
47+
/* Send back a video */
48+
res->end({&buffer[0], buffer.size()});
49+
}).post("/*", [](auto *res, auto *req) {
5050

51-
std::cout << "Got POST request at " << req->getHeader(":path") << std::endl;
51+
std::cout << "Got POST request at " << req->getHeader(":path") << std::endl;
5252

53-
/* You also need to set onAborted if receiving data */
54-
res->onData([res, bodyBuffer = (std::string *)nullptr](std::string_view chunk, bool isLast) mutable {
55-
if (isLast) {
56-
std::cout << "Sending back posted body now" << std::endl;
57-
if (bodyBuffer) {
58-
/* Send back the (chunked) body we got, as response */
59-
bodyBuffer->append(chunk);
60-
res->end(*bodyBuffer);
61-
delete bodyBuffer;
62-
} else {
63-
/* Send back the body we got, as response (fast path) */
64-
res->end(chunk);
65-
}
66-
} else {
67-
/* Slow path */
68-
if (!bodyBuffer) {
69-
bodyBuffer = new std::string;
70-
}
71-
/* If we got the body in a chunk, buffer it up until whole */
72-
bodyBuffer->append(chunk);
73-
}
53+
/* You also need to set onAborted if receiving data */
54+
res->onData([res, bodyBuffer = (std::string *)nullptr](std::string_view chunk, bool isLast) mutable {
55+
if (isLast) {
56+
std::cout << "Sending back posted body now" << std::endl;
57+
if (bodyBuffer) {
58+
/* Send back the (chunked) body we got, as response */
59+
bodyBuffer->append(chunk);
60+
res->end(*bodyBuffer);
61+
delete bodyBuffer;
62+
} else {
63+
/* Send back the body we got, as response (fast path) */
64+
res->end(chunk);
65+
}
66+
} else {
67+
/* Slow path */
68+
if (!bodyBuffer) {
69+
bodyBuffer = new std::string;
70+
}
71+
/* If we got the body in a chunk, buffer it up until whole */
72+
bodyBuffer->append(chunk);
73+
}
7474

75-
});
75+
});
7676

77-
/* If you have pending, asynch work, you should abort such work in this callback */
78-
res->onAborted([]() {
79-
/* Again, just printing is not enough, you need to abort any pending work here
80-
* so that nothing will call res->end, since the request was aborted and deleted */
81-
printf("Stream was aborted!\n");
82-
});
83-
}).listen(9004, [](auto *listen_socket) {
84-
if (listen_socket) {
85-
std::cout << "HTTP/3 server Listening on port " << 9004 << std::endl;
86-
}
87-
}).run();
77+
/* If you have pending, asynch work, you should abort such work in this callback */
78+
res->onAborted([]() {
79+
/* Again, just printing is not enough, you need to abort any pending work here
80+
* so that nothing will call res->end, since the request was aborted and deleted */
81+
printf("Stream was aborted!\n");
82+
});
83+
}).listen(9004, [](auto *listen_socket) {
84+
if (listen_socket) {
85+
std::cout << "HTTP/3 server Listening on port " << 9004 << std::endl;
86+
}
87+
}).run();
8888

89-
std::cout << "Failed to listen on port 9004" << std::endl;
89+
std::cout << "Failed to listen on port 9004" << std::endl;
9090
}
9191

9292
#else

0 commit comments

Comments
 (0)