forked from uNetworking/uWebSockets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmokeTest.cpp
More file actions
62 lines (49 loc) · 1.29 KB
/
SmokeTest.cpp
File metadata and controls
62 lines (49 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "App.h"
/* This is not an example; it is a smoke test used in CI testing */
struct Stream {
int offset;
bool aborted;
};
std::string constantChunk;
void streamData(auto *res, auto stream, int chunk) {
if (stream->aborted) {
return;
}
if (chunk < 1600) {
res->cork([res, stream, chunk]() {
auto ok = res->write(constantChunk);
if (ok) {
streamData(res, stream, chunk + 1);
return;
}
uWS::Loop::get()->defer([res, stream, chunk]() {
streamData(res, stream, chunk + 1);
});
});
} else {
res->cork([res]() {
res->end();
});
}
}
int main() {
for (int i = 0; i < 65536; i++) {
constantChunk.append("a", 1);
}
uWS::SSLApp({
.key_file_name = "misc/key.pem",
.cert_file_name = "misc/cert.pem",
.passphrase = "1234"
}).get("/*", [](auto *res, auto */*req*/) {
auto stream = std::make_shared<Stream>(0, false);
streamData(res, stream, 0);
res->onAborted([stream]() {
stream->aborted = true;
});
}).listen(3000, [](auto *listen_socket) {
if (listen_socket) {
std::cout << "Listening on port " << 3000 << std::endl;
}
}).run();
std::cout << "Failed to listen on port 3000" << std::endl;
}