diff --git a/Makefile b/Makefile index 6bad04a..664750d 100644 --- a/Makefile +++ b/Makefile @@ -2,9 +2,9 @@ default: rm *.o clang -flto -O3 -c -IuSockets/src uSockets/src/*.c uSockets/src/eventing/*.c clang++ -flto -O3 -c -std=c++17 -Isrc -IuSockets/src main.cpp - clang++ -flto -O3 -s *.o -o uWS_main -lssl -lcrypto + clang++ -flto -O3 -s *.o -o uWS_main -lssl -lcrypto -lpthread tests: rm *.o clang -flto -O3 -c -IuSockets/src uSockets/src/*.c uSockets/src/eventing/*.c clang++ -flto -O3 -c -std=c++17 -Isrc -IuSockets/src tests.cpp - clang++ -flto -O3 -s *.o -o uWS_tests -lssl -lcrypto + clang++ -flto -O3 -s *.o -o uWS_tests -lssl -lcrypto -lpthread diff --git a/src/AsyncSocket.h b/src/AsyncSocket.h index dcb88a6..334b343 100644 --- a/src/AsyncSocket.h +++ b/src/AsyncSocket.h @@ -15,24 +15,6 @@ protected: using SOCKET_TYPE = typename StaticDispatch::SOCKET_TYPE; using StaticDispatch::static_dispatch; - // this will have to belong here for now - int u32toa(uint32_t value, char *dst) { - char temp[10]; - char *p = temp; - do { - *p++ = (char) (value % 10) + '0'; - value /= 10; - } while (value > 0); - - int ret = p - temp; - - do { - *dst++ = *--p; - } while (p != temp); - - return ret; - } - LoopData *getLoopData() { if constexpr(SSL) { return (LoopData *) us_loop_ext(us_ssl_socket_context_loop(us_ssl_socket_get_context((SOCKET_TYPE *) this))); @@ -138,17 +120,6 @@ public: return length; } - /* Write an unsigned 32-bit integer */ - void writeUnsigned(unsigned int value) { - LoopData *loopData = getLoopData(); - - char buf[10]; - int length = u32toa(value, buf); - - // for now we do this copy - write(buf, length); - } - /* Uncork this socket and flush or buffer any corked and/or passed data. It is essential to remember doing this. */ /* It does NOT count bytes written from cork buffer (they are already accounted for in the write call responsible for its corking)! */ int uncork(const char *src = nullptr, int length = 0, bool optionally = false) { diff --git a/src/AsyncSocketData.h b/src/AsyncSocketData.h index c51a2ce..0307c1b 100644 --- a/src/AsyncSocketData.h +++ b/src/AsyncSocketData.h @@ -1,17 +1,14 @@ #ifndef ASYNCSOCKETDATA_H #define ASYNCSOCKETDATA_H -#include +/* Depending on how we want AsyncSocket to function, this will need to change */ -// todo: think about chains of AsyncSocketData too! -// we want to buffer things up in one buffer, or in many separate ones (like with websockets) +#include template struct AsyncSocketData { - - // we need a buffer + /* This will do for now */ std::string buffer; - }; #endif // ASYNCSOCKETDATA_H diff --git a/src/HttpContextData.h b/src/HttpContextData.h index 92fa650..1dbb6d6 100644 --- a/src/HttpContextData.h +++ b/src/HttpContextData.h @@ -11,18 +11,15 @@ struct HttpRequest; template struct HttpContextData { - private: public: - struct UserData { HttpResponse *httpResponse; HttpRequest *httpRequest; }; HttpRouter router; - }; } diff --git a/src/HttpParser.h b/src/HttpParser.h index bed7f5a..7cb9af6 100644 --- a/src/HttpParser.h +++ b/src/HttpParser.h @@ -1,6 +1,8 @@ #ifndef HTTPPARSER_H #define HTTPPARSER_H +/* The HTTP parser is an independent module subject to unit testing / fuzz testing */ + #include #include #include diff --git a/src/HttpResponse.h b/src/HttpResponse.h index a4e5a58..8fd11c5 100644 --- a/src/HttpResponse.h +++ b/src/HttpResponse.h @@ -18,6 +18,32 @@ private: return (HttpResponseData *) AsyncSocket::getExt(); } + int u32toa(uint32_t value, char *dst) { + char temp[10]; + char *p = temp; + do { + *p++ = (char) (value % 10) + '0'; + value /= 10; + } while (value > 0); + + int ret = p - temp; + + do { + *dst++ = *--p; + } while (p != temp); + + return ret; + } + + /* Write an unsigned 32-bit integer */ + void writeUnsigned(unsigned int value) { + char buf[10]; + int length = u32toa(value, buf); + + /* For now we do this copy */ + AsyncSocket::write(buf, length); + } + public: /* Write the HTTP status */ HttpResponse *writeStatus(std::string_view status) { @@ -40,7 +66,7 @@ public: void write(std::function cb, int length) { std::string_view chunk = cb(0); AsyncSocket::write("Content-Length: ", 16); - AsyncSocket::writeUnsigned(chunk.length()); + writeUnsigned(chunk.length()); AsyncSocket::write("\r\n\r\n", 4); if (int written; (written = AsyncSocket::write(chunk.data(), chunk.length(), true)) < length) { std::cout << "HttpResponse::write failed to write everything" << std::endl; diff --git a/src/HttpResponseData.h b/src/HttpResponseData.h index 6f9d992..a0968be 100644 --- a/src/HttpResponseData.h +++ b/src/HttpResponseData.h @@ -11,16 +11,10 @@ namespace uWS { template struct HttpResponseData : HttpParser, AsyncSocketData { - - // asyncsocketdata will hold the outgoing buffer to hold the header if not sent off in one go - - // inStream, outStream std::function inStream; std::function outStream; - + /* Outgoing offset */ int offset = 0; - // writeHandler - }; } diff --git a/src/HttpRouter.h b/src/HttpRouter.h index a50e547..964e3d5 100644 --- a/src/HttpRouter.h +++ b/src/HttpRouter.h @@ -1,7 +1,8 @@ #ifndef HTTPROUTER_HPP #define HTTPROUTER_HPP -// this header also needs testing and fixing as a separate module +/* HTTP router is an independent module subject to unit testing and fuzz testing */ +/* TODO: this module needs much work and fixes */ #include #include diff --git a/src/Loop.h b/src/Loop.h index 20a689c..3318397 100644 --- a/src/Loop.h +++ b/src/Loop.h @@ -1,6 +1,8 @@ #ifndef LOOP_H #define LOOP_H +/* The loop is lazily created per-thread and run with uWS::run() */ + #include "LoopData.h" #include diff --git a/src/LoopData.h b/src/LoopData.h index 283e7bc..e28804a 100644 --- a/src/LoopData.h +++ b/src/LoopData.h @@ -2,18 +2,16 @@ #define LOOPDATA_H struct LoopData { - private: public: - /* Good 16k for SSL perf. */ static const int CORK_BUFFER_SIZE = 16 * 1024; + /* Cork data */ char *corkBuffer = new char[CORK_BUFFER_SIZE]; int corkOffset = 0; bool corked = false; - }; #endif // LOOPDATA_H diff --git a/src/StaticDispatch.h b/src/StaticDispatch.h index 75077ca..b7b26b7 100644 --- a/src/StaticDispatch.h +++ b/src/StaticDispatch.h @@ -1,7 +1,7 @@ #ifndef STATICDISPATCH_H #define STATICDISPATCH_H -// this headers is basically a statically dispatched libusockets wrapper base +/* This headers is basically a statically dispatched libusockets wrapper base */ #include #include