From 5098ec279f4969eb20aa6389715fd2d2588095d0 Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Mon, 10 Jun 2019 01:19:18 +0200 Subject: [PATCH] Compile uSocketsMock as C --- fuzzing/Makefile | 3 ++- fuzzing/MockedHelloWorld.cpp | 2 +- fuzzing/uSocketsMock.c | 6 +++--- src/HttpContext.h | 12 ++++++------ 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/fuzzing/Makefile b/fuzzing/Makefile index 9779c4a..37f7620 100644 --- a/fuzzing/Makefile +++ b/fuzzing/Makefile @@ -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 diff --git a/fuzzing/MockedHelloWorld.cpp b/fuzzing/MockedHelloWorld.cpp index b2f0863..97d5195 100644 --- a/fuzzing/MockedHelloWorld.cpp +++ b/fuzzing/MockedHelloWorld.cpp @@ -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 *app; diff --git a/fuzzing/uSocketsMock.c b/fuzzing/uSocketsMock.c index 42ef932..aee5171 100644 --- a/fuzzing/uSocketsMock.c +++ b/fuzzing/uSocketsMock.c @@ -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 */ diff --git a/src/HttpContext.h b/src/HttpContext.h index cf7d89c..d6ef0be 100644 --- a/src/HttpContext.h +++ b/src/HttpContext.h @@ -59,7 +59,7 @@ private: /* Init the HttpContext by registering libusockets event handlers */ HttpContext *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 *httpResponseData = (HttpResponseData *) 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 *asyncSocket = (AsyncSocket *) s; HttpResponseData *httpResponseData = (HttpResponseData *) 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 *asyncSocket = (AsyncSocket *) 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 *asyncSocket = (AsyncSocket *) s;