Better examples with SSL, build benchmarks
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
EXAMPLE_FILES := HelloWorld EchoServer BroadcastingEchoServer HelloWorldSSL
|
EXAMPLE_FILES := HelloWorld EchoServer BroadcastingEchoServer
|
||||||
THREADED_EXAMPLE_FILES := HelloWorldThreaded EchoServerThreaded
|
THREADED_EXAMPLE_FILES := HelloWorldThreaded EchoServerThreaded
|
||||||
override CXXFLAGS += -lpthread -std=c++17 -Isrc -IuSockets/src
|
override CXXFLAGS += -lpthread -std=c++17 -Isrc -IuSockets/src
|
||||||
override LDFLAGS += uSockets/*.o -lz
|
override LDFLAGS += uSockets/*.o -lz
|
||||||
|
|||||||
+3
-3
@@ -1,4 +1,4 @@
|
|||||||
default:
|
default:
|
||||||
clang -flto -O3 -I../uSockets/src ../uSockets/src/*.c ../uSockets/src/eventing/*.c broadcast_test.c -o broadcast_test -lssl -lcrypto
|
clang -flto -O3 -DLIBUS_USE_OPENSSL -I../uSockets/src ../uSockets/src/*.c ../uSockets/src/eventing/*.c ../uSockets/src/crypto/*.c broadcast_test.c -o broadcast_test -lssl -lcrypto
|
||||||
clang -flto -O3 -I../uSockets/src ../uSockets/src/*.c ../uSockets/src/eventing/*.c load_test.c -o load_test -lssl -lcrypto
|
clang -flto -O3 -DLIBUS_USE_OPENSSL -I../uSockets/src ../uSockets/src/*.c ../uSockets/src/eventing/*.c ../uSockets/src/crypto/*.c load_test.c -o load_test -lssl -lcrypto
|
||||||
clang -flto -O3 -I../uSockets/src ../uSockets/src/*.c ../uSockets/src/eventing/*.c scale_test.c -o scale_test -lssl -lcrypto
|
clang -flto -O3 -DLIBUS_USE_OPENSSL -I../uSockets/src ../uSockets/src/*.c ../uSockets/src/eventing/*.c ../uSockets/src/crypto/*.c scale_test.c -o scale_test -lssl -lcrypto
|
||||||
|
|||||||
+18
-8
@@ -1,13 +1,23 @@
|
|||||||
|
/* We simply call the root header file "App.h", giving you uWS::App and uWS::SSLApp */
|
||||||
#include "App.h"
|
#include "App.h"
|
||||||
|
|
||||||
|
/* This is a simple WebSocket echo server example.
|
||||||
|
* You may compile it with "WITH_OPENSSL=1 make" or with "make" */
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
/* ws->getUserData returns one of these */
|
/* ws->getUserData returns one of these */
|
||||||
struct PerSocketData {
|
struct PerSocketData {
|
||||||
|
/* Fill with user data */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Very simple WebSocket echo server */
|
/* Keep in mind that uWS::SSLApp({options}) is the same as uWS::App() when compiled without SSL support.
|
||||||
uWS::App().ws<PerSocketData>("/*", {
|
* You may swap to using uWS:App() if you don't need SSL */
|
||||||
|
uWS::SSLApp({
|
||||||
|
/* There are example certificates in uWebSockets.js repo */
|
||||||
|
.key_file_name = "../misc/key.pem",
|
||||||
|
.cert_file_name = "../misc/cert.pem",
|
||||||
|
.passphrase = "1234"
|
||||||
|
}).ws<PerSocketData>("/*", {
|
||||||
/* Settings */
|
/* Settings */
|
||||||
.compression = uWS::SHARED_COMPRESSOR,
|
.compression = uWS::SHARED_COMPRESSOR,
|
||||||
.maxPayloadLength = 16 * 1024,
|
.maxPayloadLength = 16 * 1024,
|
||||||
@@ -15,22 +25,22 @@ int main() {
|
|||||||
.maxBackpressure = 1 * 1024 * 1204,
|
.maxBackpressure = 1 * 1024 * 1204,
|
||||||
/* Handlers */
|
/* Handlers */
|
||||||
.open = [](auto *ws, auto *req) {
|
.open = [](auto *ws, auto *req) {
|
||||||
|
/* Open event here, you may access ws->getUserData() which points to a PerSocketData struct */
|
||||||
},
|
},
|
||||||
.message = [](auto *ws, std::string_view message, uWS::OpCode opCode) {
|
.message = [](auto *ws, std::string_view message, uWS::OpCode opCode) {
|
||||||
ws->send(message, opCode);
|
ws->send(message, opCode);
|
||||||
},
|
},
|
||||||
.drain = [](auto *ws) {
|
.drain = [](auto *ws) {
|
||||||
/* Check getBufferedAmount here */
|
/* Check ws->getBufferedAmount() here */
|
||||||
},
|
},
|
||||||
.ping = [](auto *ws) {
|
.ping = [](auto *ws) {
|
||||||
|
/* Not implemented yet */
|
||||||
},
|
},
|
||||||
.pong = [](auto *ws) {
|
.pong = [](auto *ws) {
|
||||||
|
/* Not implemented yet */
|
||||||
},
|
},
|
||||||
.close = [](auto *ws, int code, std::string_view message) {
|
.close = [](auto *ws, int code, std::string_view message) {
|
||||||
|
/* You may access ws->getUserData() here */
|
||||||
}
|
}
|
||||||
}).listen(9001, [](auto *token) {
|
}).listen(9001, [](auto *token) {
|
||||||
if (token) {
|
if (token) {
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
#include "App.h"
|
#include "App.h"
|
||||||
|
|
||||||
|
/* Note that uWS::SSLApp({options}) is the same as uWS::App() when compiled without SSL support */
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
/* Overly simple hello world app */
|
/* Overly simple hello world app */
|
||||||
uWS::App().get("/*", [](auto *res, auto *req) {
|
uWS::SSLApp({
|
||||||
|
.key_file_name = "../misc/key.pem",
|
||||||
|
.cert_file_name = "../misc/cert.pem",
|
||||||
|
.passphrase = "1234"
|
||||||
|
}).get("/*", [](auto *res, auto *req) {
|
||||||
res->end("Hello world!");
|
res->end("Hello world!");
|
||||||
}).listen(3000, [](auto *token) {
|
}).listen(3000, [](auto *token) {
|
||||||
if (token) {
|
if (token) {
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
#include "App.h"
|
|
||||||
|
|
||||||
/* Note that uWS::SSLApp({options}) is the same as uWS::App() when compiles without SSL support */
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
/* Overly simple hello world app */
|
|
||||||
uWS::SSLApp({
|
|
||||||
.key_file_name = "../misc/key.pem",
|
|
||||||
.cert_file_name = "../misc/cert.pem",
|
|
||||||
.passphrase = "1234"
|
|
||||||
}).get("/*", [](auto *res, auto *req) {
|
|
||||||
res->end("Hello world!");
|
|
||||||
}).listen(3000, [](auto *token) {
|
|
||||||
if (token) {
|
|
||||||
std::cout << "Listening on port " << 3000 << std::endl;
|
|
||||||
}
|
|
||||||
}).run();
|
|
||||||
|
|
||||||
std::cout << "Failed to listen on port 3000" << std::endl;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user