Compile uSocketsMock as C
This commit is contained in:
+2
-1
@@ -1,6 +1,7 @@
|
||||
default:
|
||||
# Fuzzing is only available with clang++
|
||||
clang++ -DUWS_NO_ZLIB -DLIBUS_NO_SSL -std=c++17 -fsanitize=address,fuzzer -O3 -I../src -I../uSockets/src uSocketsMock.c MockedHelloWorld.cpp -o MockedHelloWorld
|
||||
clang -DLIBUS_NO_SSL -c -O3 uSocketsMock.c
|
||||
clang++ -DUWS_NO_ZLIB -DLIBUS_NO_SSL -std=c++17 -fsanitize=undefined,fuzzer -O3 -I../src -I../uSockets/src uSocketsMock.o MockedHelloWorld.cpp -o MockedHelloWorld
|
||||
# Purely "unit tests"
|
||||
clang++ -std=c++17 -fsanitize=address,fuzzer -O3 WebSocket.cpp -o WebSocket
|
||||
clang++ -std=c++17 -fsanitize=address,fuzzer -O3 Http.cpp -o Http
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "helpers.h"
|
||||
|
||||
/* This function pushes data to the uSockets mock */
|
||||
extern void us_loop_read_mocked_data(struct us_loop *loop, char *data, unsigned int size);
|
||||
extern "C" void us_loop_read_mocked_data(struct us_loop *loop, char *data, unsigned int size);
|
||||
|
||||
uWS::TemplatedApp<false> *app;
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ struct us_loop {
|
||||
};
|
||||
|
||||
struct us_loop *us_create_loop(int default_hint, void (*wakeup_cb)(struct us_loop *loop), void (*pre_cb)(struct us_loop *loop), void (*post_cb)(struct us_loop *loop), unsigned int ext_size) {
|
||||
return (struct us_loop *) malloc(sizeof(us_loop) + ext_size);
|
||||
return (struct us_loop *) malloc(sizeof(struct us_loop) + ext_size);
|
||||
}
|
||||
|
||||
void us_loop_free(struct us_loop *loop) {
|
||||
@@ -38,7 +38,7 @@ struct us_socket_context {
|
||||
};
|
||||
|
||||
struct us_socket_context *us_create_socket_context(struct us_loop *loop, int ext_size) {
|
||||
struct us_socket_context *socket_context = (struct us_socket_context *) malloc(sizeof(us_socket_context) + ext_size);
|
||||
struct us_socket_context *socket_context = (struct us_socket_context *) malloc(sizeof(struct us_socket_context) + ext_size);
|
||||
|
||||
socket_context->loop = loop;
|
||||
|
||||
@@ -169,7 +169,7 @@ void us_loop_read_mocked_data(struct us_loop *loop, char *data, unsigned int siz
|
||||
int socket_ext_size = loop->listen_socket->socket_ext_size;
|
||||
|
||||
/* Create a socket with information from the listen socket */
|
||||
struct us_socket *s = (struct us_socket *) malloc(sizeof(us_socket) + socket_ext_size);
|
||||
struct us_socket *s = (struct us_socket *) malloc(sizeof(struct us_socket) + socket_ext_size);
|
||||
s->context = loop->listen_socket->context;
|
||||
|
||||
/* Emit open event */
|
||||
|
||||
+6
-6
@@ -59,7 +59,7 @@ private:
|
||||
/* Init the HttpContext by registering libusockets event handlers */
|
||||
HttpContext<SSL> *init() {
|
||||
/* Handle socket connections */
|
||||
us_new_socket_context_on_open(SSL, getSocketContext(), [](auto *s, int is_client, char *ip, int ip_length) {
|
||||
us_new_socket_context_on_open(SSL, getSocketContext(), [](us_new_socket_t *s, int is_client, char *ip, int ip_length) {
|
||||
/* Any connected socket should timeout until it has a request */
|
||||
us_new_socket_timeout(SSL, s, HTTP_IDLE_TIMEOUT_S);
|
||||
|
||||
@@ -76,7 +76,7 @@ private:
|
||||
});
|
||||
|
||||
/* Handle socket disconnections */
|
||||
us_new_socket_context_on_close(SSL, getSocketContext(), [](auto *s) {
|
||||
us_new_socket_context_on_close(SSL, getSocketContext(), [](us_new_socket_t *s) {
|
||||
/* Get socket ext */
|
||||
HttpResponseData<SSL> *httpResponseData = (HttpResponseData<SSL> *) us_new_socket_ext(SSL, s);
|
||||
|
||||
@@ -98,7 +98,7 @@ private:
|
||||
});
|
||||
|
||||
/* Handle HTTP data streams */
|
||||
us_new_socket_context_on_data(SSL, getSocketContext(), [](auto *s, char *data, int length) {
|
||||
us_new_socket_context_on_data(SSL, getSocketContext(), [](us_new_socket_t *s, char *data, int length) {
|
||||
|
||||
// total overhead is about 210k down to 180k
|
||||
// ~210k req/sec is the original perf with write in data
|
||||
@@ -242,7 +242,7 @@ private:
|
||||
});
|
||||
|
||||
/* Handle HTTP write out (note: SSL_read may trigger this spuriously, the app need to handle spurious calls) */
|
||||
us_new_socket_context_on_writable(SSL, getSocketContext(), [](auto *s) {
|
||||
us_new_socket_context_on_writable(SSL, getSocketContext(), [](us_new_socket_t *s) {
|
||||
|
||||
AsyncSocket<SSL> *asyncSocket = (AsyncSocket<SSL> *) s;
|
||||
HttpResponseData<SSL> *httpResponseData = (HttpResponseData<SSL> *) asyncSocket->getAsyncSocketData();
|
||||
@@ -277,7 +277,7 @@ private:
|
||||
});
|
||||
|
||||
/* Handle FIN, HTTP does not support half-closed sockets, so simply close */
|
||||
us_new_socket_context_on_end(SSL, getSocketContext(), [](auto *s) {
|
||||
us_new_socket_context_on_end(SSL, getSocketContext(), [](us_new_socket_t *s) {
|
||||
|
||||
/* We do not care for half closed sockets */
|
||||
AsyncSocket<SSL> *asyncSocket = (AsyncSocket<SSL> *) s;
|
||||
@@ -286,7 +286,7 @@ private:
|
||||
});
|
||||
|
||||
/* Handle socket timeouts, simply close them so to not confuse client with FIN */
|
||||
us_new_socket_context_on_timeout(SSL, getSocketContext(), [](auto *s) {
|
||||
us_new_socket_context_on_timeout(SSL, getSocketContext(), [](us_new_socket_t *s) {
|
||||
|
||||
/* Force close rather than gracefully shutdown and risk confusing the client with a complete download */
|
||||
AsyncSocket<SSL> *asyncSocket = (AsyncSocket<SSL> *) s;
|
||||
|
||||
Reference in New Issue
Block a user