Some clean-ups
This commit is contained in:
@@ -2,9 +2,9 @@ default:
|
|||||||
rm *.o
|
rm *.o
|
||||||
clang -flto -O3 -c -IuSockets/src uSockets/src/*.c uSockets/src/eventing/*.c
|
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 -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:
|
tests:
|
||||||
rm *.o
|
rm *.o
|
||||||
clang -flto -O3 -c -IuSockets/src uSockets/src/*.c uSockets/src/eventing/*.c
|
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 -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
|
||||||
|
|||||||
@@ -15,24 +15,6 @@ protected:
|
|||||||
using SOCKET_TYPE = typename StaticDispatch<SSL>::SOCKET_TYPE;
|
using SOCKET_TYPE = typename StaticDispatch<SSL>::SOCKET_TYPE;
|
||||||
using StaticDispatch<SSL>::static_dispatch;
|
using StaticDispatch<SSL>::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() {
|
LoopData *getLoopData() {
|
||||||
if constexpr(SSL) {
|
if constexpr(SSL) {
|
||||||
return (LoopData *) us_loop_ext(us_ssl_socket_context_loop(us_ssl_socket_get_context((SOCKET_TYPE *) this)));
|
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;
|
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. */
|
/* 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)! */
|
/* 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) {
|
int uncork(const char *src = nullptr, int length = 0, bool optionally = false) {
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
#ifndef ASYNCSOCKETDATA_H
|
#ifndef ASYNCSOCKETDATA_H
|
||||||
#define ASYNCSOCKETDATA_H
|
#define ASYNCSOCKETDATA_H
|
||||||
|
|
||||||
#include <string>
|
/* Depending on how we want AsyncSocket to function, this will need to change */
|
||||||
|
|
||||||
// todo: think about chains of AsyncSocketData too!
|
#include <string>
|
||||||
// we want to buffer things up in one buffer, or in many separate ones (like with websockets)
|
|
||||||
|
|
||||||
template <bool SSL>
|
template <bool SSL>
|
||||||
struct AsyncSocketData {
|
struct AsyncSocketData {
|
||||||
|
/* This will do for now */
|
||||||
// we need a buffer
|
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ASYNCSOCKETDATA_H
|
#endif // ASYNCSOCKETDATA_H
|
||||||
|
|||||||
@@ -11,18 +11,15 @@ struct HttpRequest;
|
|||||||
|
|
||||||
template <bool SSL>
|
template <bool SSL>
|
||||||
struct HttpContextData {
|
struct HttpContextData {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
struct UserData {
|
struct UserData {
|
||||||
HttpResponse<SSL> *httpResponse;
|
HttpResponse<SSL> *httpResponse;
|
||||||
HttpRequest *httpRequest;
|
HttpRequest *httpRequest;
|
||||||
};
|
};
|
||||||
|
|
||||||
HttpRouter<UserData *> router;
|
HttpRouter<UserData *> router;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef HTTPPARSER_H
|
#ifndef HTTPPARSER_H
|
||||||
#define HTTPPARSER_H
|
#define HTTPPARSER_H
|
||||||
|
|
||||||
|
/* The HTTP parser is an independent module subject to unit testing / fuzz testing */
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|||||||
+27
-1
@@ -18,6 +18,32 @@ private:
|
|||||||
return (HttpResponseData<SSL> *) AsyncSocket<SSL>::getExt();
|
return (HttpResponseData<SSL> *) AsyncSocket<SSL>::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<SSL>::write(buf, length);
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/* Write the HTTP status */
|
/* Write the HTTP status */
|
||||||
HttpResponse *writeStatus(std::string_view status) {
|
HttpResponse *writeStatus(std::string_view status) {
|
||||||
@@ -40,7 +66,7 @@ public:
|
|||||||
void write(std::function<std::string_view(int)> cb, int length) {
|
void write(std::function<std::string_view(int)> cb, int length) {
|
||||||
std::string_view chunk = cb(0);
|
std::string_view chunk = cb(0);
|
||||||
AsyncSocket<SSL>::write("Content-Length: ", 16);
|
AsyncSocket<SSL>::write("Content-Length: ", 16);
|
||||||
AsyncSocket<SSL>::writeUnsigned(chunk.length());
|
writeUnsigned(chunk.length());
|
||||||
AsyncSocket<SSL>::write("\r\n\r\n", 4);
|
AsyncSocket<SSL>::write("\r\n\r\n", 4);
|
||||||
if (int written; (written = AsyncSocket<SSL>::write(chunk.data(), chunk.length(), true)) < length) {
|
if (int written; (written = AsyncSocket<SSL>::write(chunk.data(), chunk.length(), true)) < length) {
|
||||||
std::cout << "HttpResponse::write failed to write everything" << std::endl;
|
std::cout << "HttpResponse::write failed to write everything" << std::endl;
|
||||||
|
|||||||
@@ -11,16 +11,10 @@ namespace uWS {
|
|||||||
|
|
||||||
template <bool SSL>
|
template <bool SSL>
|
||||||
struct HttpResponseData : HttpParser, AsyncSocketData<SSL> {
|
struct HttpResponseData : HttpParser, AsyncSocketData<SSL> {
|
||||||
|
|
||||||
// asyncsocketdata will hold the outgoing buffer to hold the header if not sent off in one go
|
|
||||||
|
|
||||||
// inStream, outStream
|
|
||||||
std::function<void(std::string_view)> inStream;
|
std::function<void(std::string_view)> inStream;
|
||||||
std::function<std::string_view(int)> outStream;
|
std::function<std::string_view(int)> outStream;
|
||||||
|
/* Outgoing offset */
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
// writeHandler
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -1,7 +1,8 @@
|
|||||||
#ifndef HTTPROUTER_HPP
|
#ifndef HTTPROUTER_HPP
|
||||||
#define 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 <map>
|
#include <map>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef LOOP_H
|
#ifndef LOOP_H
|
||||||
#define LOOP_H
|
#define LOOP_H
|
||||||
|
|
||||||
|
/* The loop is lazily created per-thread and run with uWS::run() */
|
||||||
|
|
||||||
#include "LoopData.h"
|
#include "LoopData.h"
|
||||||
|
|
||||||
#include <libusockets.h>
|
#include <libusockets.h>
|
||||||
|
|||||||
+1
-3
@@ -2,18 +2,16 @@
|
|||||||
#define LOOPDATA_H
|
#define LOOPDATA_H
|
||||||
|
|
||||||
struct LoopData {
|
struct LoopData {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/* Good 16k for SSL perf. */
|
/* Good 16k for SSL perf. */
|
||||||
static const int CORK_BUFFER_SIZE = 16 * 1024;
|
static const int CORK_BUFFER_SIZE = 16 * 1024;
|
||||||
|
|
||||||
|
/* Cork data */
|
||||||
char *corkBuffer = new char[CORK_BUFFER_SIZE];
|
char *corkBuffer = new char[CORK_BUFFER_SIZE];
|
||||||
int corkOffset = 0;
|
int corkOffset = 0;
|
||||||
bool corked = false;
|
bool corked = false;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LOOPDATA_H
|
#endif // LOOPDATA_H
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef STATICDISPATCH_H
|
#ifndef STATICDISPATCH_H
|
||||||
#define 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 <type_traits>
|
#include <type_traits>
|
||||||
#include <libusockets.h>
|
#include <libusockets.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user