uws-react-native 0.0.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +84 -0
- package/UwsReactNative.podspec +71 -0
- package/android/build.gradle.kts +138 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/id/sufeni/oss/uwsreactnative/UwsReactNativePackage.kt +18 -0
- package/apple/OnLoad.mm +17 -0
- package/cpp/CMakeLists.txt +154 -0
- package/cpp/UwsReactNativeModule.cpp +191 -0
- package/cpp/UwsReactNativeModule.h +30 -0
- package/cpp/app/AppHost.h +37 -0
- package/cpp/app/AppRunner.h +88 -0
- package/cpp/app/CMakeLists.txt +39 -0
- package/cpp/app/HttpRequestObject.h +173 -0
- package/cpp/app/HttpResponseObject.h +623 -0
- package/cpp/app/RecognizedString.h +71 -0
- package/cpp/app/TemplatedAppObject.h +472 -0
- package/cpp/bridging/ArrayBuffer.h +150 -0
- package/cpp/bridging/CMakeLists.txt +34 -0
- package/cpp/jsi/Buffer.h +91 -0
- package/cpp/jsi/CMakeLists.txt +34 -0
- package/cpp/uSockets/bsd.c +767 -0
- package/cpp/uSockets/context.c +524 -0
- package/cpp/uSockets/crypto/openssl.c +858 -0
- package/cpp/uSockets/crypto/sni_tree.cpp +218 -0
- package/cpp/uSockets/eventing/asio.cpp +475 -0
- package/cpp/uSockets/eventing/epoll_kqueue.c +458 -0
- package/cpp/uSockets/eventing/gcd.c +278 -0
- package/cpp/uSockets/eventing/libuv.c +305 -0
- package/cpp/uSockets/internal/eventing/asio.h +45 -0
- package/cpp/uSockets/internal/eventing/epoll_kqueue.h +67 -0
- package/cpp/uSockets/internal/eventing/gcd.h +40 -0
- package/cpp/uSockets/internal/eventing/libuv.h +45 -0
- package/cpp/uSockets/internal/internal.h +224 -0
- package/cpp/uSockets/internal/loop_data.h +38 -0
- package/cpp/uSockets/internal/networking/bsd.h +109 -0
- package/cpp/uSockets/io_uring/internal.h +98 -0
- package/cpp/uSockets/io_uring/io_context.c +302 -0
- package/cpp/uSockets/io_uring/io_loop.c +422 -0
- package/cpp/uSockets/io_uring/io_socket.c +139 -0
- package/cpp/uSockets/libusockets.h +350 -0
- package/cpp/uSockets/loop.c +396 -0
- package/cpp/uSockets/quic.c +1071 -0
- package/cpp/uSockets/quic.h +68 -0
- package/cpp/uSockets/socket.c +231 -0
- package/cpp/uSockets/udp.c +151 -0
- package/cpp/uWebSockets/uWebSockets/App.h +676 -0
- package/cpp/uWebSockets/uWebSockets/AsyncSocket.h +376 -0
- package/cpp/uWebSockets/uWebSockets/AsyncSocketData.h +94 -0
- package/cpp/uWebSockets/uWebSockets/BloomFilter.h +83 -0
- package/cpp/uWebSockets/uWebSockets/CachingApp.h +115 -0
- package/cpp/uWebSockets/uWebSockets/ChunkedEncoding.h +237 -0
- package/cpp/uWebSockets/uWebSockets/ClientApp.h +36 -0
- package/cpp/uWebSockets/uWebSockets/Http3App.h +140 -0
- package/cpp/uWebSockets/uWebSockets/Http3Context.h +157 -0
- package/cpp/uWebSockets/uWebSockets/Http3ContextData.h +21 -0
- package/cpp/uWebSockets/uWebSockets/Http3Request.h +22 -0
- package/cpp/uWebSockets/uWebSockets/Http3Response.h +120 -0
- package/cpp/uWebSockets/uWebSockets/Http3ResponseData.h +25 -0
- package/cpp/uWebSockets/uWebSockets/HttpContext.h +521 -0
- package/cpp/uWebSockets/uWebSockets/HttpContextData.h +60 -0
- package/cpp/uWebSockets/uWebSockets/HttpErrors.h +53 -0
- package/cpp/uWebSockets/uWebSockets/HttpParser.h +747 -0
- package/cpp/uWebSockets/uWebSockets/HttpResponse.h +605 -0
- package/cpp/uWebSockets/uWebSockets/HttpResponseData.h +123 -0
- package/cpp/uWebSockets/uWebSockets/HttpRouter.h +384 -0
- package/cpp/uWebSockets/uWebSockets/LocalCluster.h +64 -0
- package/cpp/uWebSockets/uWebSockets/Loop.h +238 -0
- package/cpp/uWebSockets/uWebSockets/LoopData.h +113 -0
- package/cpp/uWebSockets/uWebSockets/MessageParser.h +64 -0
- package/cpp/uWebSockets/uWebSockets/MoveOnlyFunction.h +389 -0
- package/cpp/uWebSockets/uWebSockets/Multipart.h +231 -0
- package/cpp/uWebSockets/uWebSockets/PerMessageDeflate.h +303 -0
- package/cpp/uWebSockets/uWebSockets/ProxyParser.h +187 -0
- package/cpp/uWebSockets/uWebSockets/QueryParser.h +120 -0
- package/cpp/uWebSockets/uWebSockets/TopicTree.h +364 -0
- package/cpp/uWebSockets/uWebSockets/Utilities.h +66 -0
- package/cpp/uWebSockets/uWebSockets/WebSocket.h +407 -0
- package/cpp/uWebSockets/uWebSockets/WebSocketContext.h +436 -0
- package/cpp/uWebSockets/uWebSockets/WebSocketContextData.h +109 -0
- package/cpp/uWebSockets/uWebSockets/WebSocketData.h +86 -0
- package/cpp/uWebSockets/uWebSockets/WebSocketExtensions.h +256 -0
- package/cpp/uWebSockets/uWebSockets/WebSocketHandshake.h +145 -0
- package/cpp/uWebSockets/uWebSockets/WebSocketProtocol.h +525 -0
- package/lib/commonjs/_internal/native-modules/NativeReactNativeUws.js +12 -0
- package/lib/commonjs/_internal/native-modules/NativeReactNativeUws.js.map +1 -0
- package/lib/commonjs/index.js +28 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/modules/App.js +17 -0
- package/lib/commonjs/modules/App.js.map +1 -0
- package/lib/commonjs/modules/CompressOptions.js +103 -0
- package/lib/commonjs/modules/CompressOptions.js.map +1 -0
- package/lib/commonjs/modules/EnvironmentVariables.js +17 -0
- package/lib/commonjs/modules/EnvironmentVariables.js.map +1 -0
- package/lib/commonjs/modules/ListenOptions.js +12 -0
- package/lib/commonjs/modules/ListenOptions.js.map +1 -0
- package/lib/commonjs/modules/SSLApp.js +15 -0
- package/lib/commonjs/modules/SSLApp.js.map +1 -0
- package/lib/commonjs/modules/getParts.js +28 -0
- package/lib/commonjs/modules/getParts.js.map +1 -0
- package/lib/commonjs/modules/index.js +61 -0
- package/lib/commonjs/modules/index.js.map +1 -0
- package/lib/commonjs/modules/us_listen_socket_close.js +21 -0
- package/lib/commonjs/modules/us_listen_socket_close.js.map +1 -0
- package/lib/commonjs/modules/us_socket_local_port.js +22 -0
- package/lib/commonjs/modules/us_socket_local_port.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/types/AppDescriptor.js +2 -0
- package/lib/commonjs/types/AppDescriptor.js.map +1 -0
- package/lib/commonjs/types/AppOptions.js +2 -0
- package/lib/commonjs/types/AppOptions.js.map +1 -0
- package/lib/commonjs/types/HttpRequest.js +6 -0
- package/lib/commonjs/types/HttpRequest.js.map +1 -0
- package/lib/commonjs/types/HttpResponse.js +6 -0
- package/lib/commonjs/types/HttpResponse.js.map +1 -0
- package/lib/commonjs/types/HttpRouterOptions.js +2 -0
- package/lib/commonjs/types/HttpRouterOptions.js.map +1 -0
- package/lib/commonjs/types/MultipartField.js +2 -0
- package/lib/commonjs/types/MultipartField.js.map +1 -0
- package/lib/commonjs/types/RecognizedString.js +2 -0
- package/lib/commonjs/types/RecognizedString.js.map +1 -0
- package/lib/commonjs/types/TemplatedApp.js +6 -0
- package/lib/commonjs/types/TemplatedApp.js.map +1 -0
- package/lib/commonjs/types/WebSocket.js +6 -0
- package/lib/commonjs/types/WebSocket.js.map +1 -0
- package/lib/commonjs/types/WebSocketBehaviour.js +139 -0
- package/lib/commonjs/types/WebSocketBehaviour.js.map +1 -0
- package/lib/commonjs/types/index.js +2 -0
- package/lib/commonjs/types/index.js.map +1 -0
- package/lib/commonjs/types/us_listen_socket.js +2 -0
- package/lib/commonjs/types/us_listen_socket.js.map +1 -0
- package/lib/commonjs/types/us_socket.js +2 -0
- package/lib/commonjs/types/us_socket.js.map +1 -0
- package/lib/commonjs/types/us_socket_context_t.js +2 -0
- package/lib/commonjs/types/us_socket_context_t.js.map +1 -0
- package/lib/module/_internal/native-modules/NativeReactNativeUws.js +10 -0
- package/lib/module/_internal/native-modules/NativeReactNativeUws.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/modules/App.js +12 -0
- package/lib/module/modules/App.js.map +1 -0
- package/lib/module/modules/CompressOptions.js +103 -0
- package/lib/module/modules/CompressOptions.js.map +1 -0
- package/lib/module/modules/EnvironmentVariables.js +13 -0
- package/lib/module/modules/EnvironmentVariables.js.map +1 -0
- package/lib/module/modules/ListenOptions.js +8 -0
- package/lib/module/modules/ListenOptions.js.map +1 -0
- package/lib/module/modules/SSLApp.js +15 -0
- package/lib/module/modules/SSLApp.js.map +1 -0
- package/lib/module/modules/getParts.js +23 -0
- package/lib/module/modules/getParts.js.map +1 -0
- package/lib/module/modules/index.js +11 -0
- package/lib/module/modules/index.js.map +1 -0
- package/lib/module/modules/us_listen_socket_close.js +17 -0
- package/lib/module/modules/us_listen_socket_close.js.map +1 -0
- package/lib/module/modules/us_socket_local_port.js +18 -0
- package/lib/module/modules/us_socket_local_port.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types/AppDescriptor.js +2 -0
- package/lib/module/types/AppDescriptor.js.map +1 -0
- package/lib/module/types/AppOptions.js +2 -0
- package/lib/module/types/AppOptions.js.map +1 -0
- package/lib/module/types/HttpRequest.js +4 -0
- package/lib/module/types/HttpRequest.js.map +1 -0
- package/lib/module/types/HttpResponse.js +4 -0
- package/lib/module/types/HttpResponse.js.map +1 -0
- package/lib/module/types/HttpRouterOptions.js +2 -0
- package/lib/module/types/HttpRouterOptions.js.map +1 -0
- package/lib/module/types/MultipartField.js +2 -0
- package/lib/module/types/MultipartField.js.map +1 -0
- package/lib/module/types/RecognizedString.js +2 -0
- package/lib/module/types/RecognizedString.js.map +1 -0
- package/lib/module/types/TemplatedApp.js +4 -0
- package/lib/module/types/TemplatedApp.js.map +1 -0
- package/lib/module/types/WebSocket.js +4 -0
- package/lib/module/types/WebSocket.js.map +1 -0
- package/lib/module/types/WebSocketBehaviour.js +139 -0
- package/lib/module/types/WebSocketBehaviour.js.map +1 -0
- package/lib/module/types/index.js +2 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/module/types/us_listen_socket.js +2 -0
- package/lib/module/types/us_listen_socket.js.map +1 -0
- package/lib/module/types/us_socket.js +2 -0
- package/lib/module/types/us_socket.js.map +1 -0
- package/lib/module/types/us_socket_context_t.js +2 -0
- package/lib/module/types/us_socket_context_t.js.map +1 -0
- package/lib/typescript/commonjs/_internal/native-modules/NativeReactNativeUws.d.ts +22 -0
- package/lib/typescript/commonjs/_internal/native-modules/NativeReactNativeUws.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +3 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/App.d.ts +7 -0
- package/lib/typescript/commonjs/modules/App.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/CompressOptions.d.ts +1 -0
- package/lib/typescript/commonjs/modules/CompressOptions.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/EnvironmentVariables.d.ts +16 -0
- package/lib/typescript/commonjs/modules/EnvironmentVariables.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/ListenOptions.d.ts +5 -0
- package/lib/typescript/commonjs/modules/ListenOptions.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/SSLApp.d.ts +1 -0
- package/lib/typescript/commonjs/modules/SSLApp.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/getParts.d.ts +6 -0
- package/lib/typescript/commonjs/modules/getParts.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/index.d.ts +6 -0
- package/lib/typescript/commonjs/modules/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/us_listen_socket_close.d.ts +5 -0
- package/lib/typescript/commonjs/modules/us_listen_socket_close.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/us_socket_local_port.d.ts +5 -0
- package/lib/typescript/commonjs/modules/us_socket_local_port.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/types/AppDescriptor.d.ts +8 -0
- package/lib/typescript/commonjs/types/AppDescriptor.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/AppOptions.d.ts +17 -0
- package/lib/typescript/commonjs/types/AppOptions.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/HttpRequest.d.ts +54 -0
- package/lib/typescript/commonjs/types/HttpRequest.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/HttpResponse.d.ts +169 -0
- package/lib/typescript/commonjs/types/HttpResponse.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/HttpRouterOptions.d.ts +24 -0
- package/lib/typescript/commonjs/types/HttpRouterOptions.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/MultipartField.d.ts +7 -0
- package/lib/typescript/commonjs/types/MultipartField.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/RecognizedString.d.ts +10 -0
- package/lib/typescript/commonjs/types/RecognizedString.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/TemplatedApp.d.ts +108 -0
- package/lib/typescript/commonjs/types/TemplatedApp.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/WebSocket.d.ts +96 -0
- package/lib/typescript/commonjs/types/WebSocket.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/WebSocketBehaviour.d.ts +1 -0
- package/lib/typescript/commonjs/types/WebSocketBehaviour.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/index.d.ts +6 -0
- package/lib/typescript/commonjs/types/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/us_listen_socket.d.ts +7 -0
- package/lib/typescript/commonjs/types/us_listen_socket.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/us_socket.d.ts +7 -0
- package/lib/typescript/commonjs/types/us_socket.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/us_socket_context_t.d.ts +7 -0
- package/lib/typescript/commonjs/types/us_socket_context_t.d.ts.map +1 -0
- package/lib/typescript/module/_internal/native-modules/NativeReactNativeUws.d.ts +22 -0
- package/lib/typescript/module/_internal/native-modules/NativeReactNativeUws.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +3 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/modules/App.d.ts +7 -0
- package/lib/typescript/module/modules/App.d.ts.map +1 -0
- package/lib/typescript/module/modules/CompressOptions.d.ts +1 -0
- package/lib/typescript/module/modules/CompressOptions.d.ts.map +1 -0
- package/lib/typescript/module/modules/EnvironmentVariables.d.ts +16 -0
- package/lib/typescript/module/modules/EnvironmentVariables.d.ts.map +1 -0
- package/lib/typescript/module/modules/ListenOptions.d.ts +5 -0
- package/lib/typescript/module/modules/ListenOptions.d.ts.map +1 -0
- package/lib/typescript/module/modules/SSLApp.d.ts +1 -0
- package/lib/typescript/module/modules/SSLApp.d.ts.map +1 -0
- package/lib/typescript/module/modules/getParts.d.ts +6 -0
- package/lib/typescript/module/modules/getParts.d.ts.map +1 -0
- package/lib/typescript/module/modules/index.d.ts +6 -0
- package/lib/typescript/module/modules/index.d.ts.map +1 -0
- package/lib/typescript/module/modules/us_listen_socket_close.d.ts +5 -0
- package/lib/typescript/module/modules/us_listen_socket_close.d.ts.map +1 -0
- package/lib/typescript/module/modules/us_socket_local_port.d.ts +5 -0
- package/lib/typescript/module/modules/us_socket_local_port.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/types/AppDescriptor.d.ts +8 -0
- package/lib/typescript/module/types/AppDescriptor.d.ts.map +1 -0
- package/lib/typescript/module/types/AppOptions.d.ts +17 -0
- package/lib/typescript/module/types/AppOptions.d.ts.map +1 -0
- package/lib/typescript/module/types/HttpRequest.d.ts +54 -0
- package/lib/typescript/module/types/HttpRequest.d.ts.map +1 -0
- package/lib/typescript/module/types/HttpResponse.d.ts +169 -0
- package/lib/typescript/module/types/HttpResponse.d.ts.map +1 -0
- package/lib/typescript/module/types/HttpRouterOptions.d.ts +24 -0
- package/lib/typescript/module/types/HttpRouterOptions.d.ts.map +1 -0
- package/lib/typescript/module/types/MultipartField.d.ts +7 -0
- package/lib/typescript/module/types/MultipartField.d.ts.map +1 -0
- package/lib/typescript/module/types/RecognizedString.d.ts +10 -0
- package/lib/typescript/module/types/RecognizedString.d.ts.map +1 -0
- package/lib/typescript/module/types/TemplatedApp.d.ts +108 -0
- package/lib/typescript/module/types/TemplatedApp.d.ts.map +1 -0
- package/lib/typescript/module/types/WebSocket.d.ts +96 -0
- package/lib/typescript/module/types/WebSocket.d.ts.map +1 -0
- package/lib/typescript/module/types/WebSocketBehaviour.d.ts +1 -0
- package/lib/typescript/module/types/WebSocketBehaviour.d.ts.map +1 -0
- package/lib/typescript/module/types/index.d.ts +6 -0
- package/lib/typescript/module/types/index.d.ts.map +1 -0
- package/lib/typescript/module/types/us_listen_socket.d.ts +7 -0
- package/lib/typescript/module/types/us_listen_socket.d.ts.map +1 -0
- package/lib/typescript/module/types/us_socket.d.ts +7 -0
- package/lib/typescript/module/types/us_socket.d.ts.map +1 -0
- package/lib/typescript/module/types/us_socket_context_t.d.ts +7 -0
- package/lib/typescript/module/types/us_socket_context_t.d.ts.map +1 -0
- package/lib/typescript/tsconfig.tsbuildinfo +1 -0
- package/package.json +62 -0
- package/src/_internal/native-modules/NativeUwsReactNative.ts +40 -0
- package/src/index.ts +2 -0
- package/src/modules/App.ts +14 -0
- package/src/modules/CompressOptions.ts +101 -0
- package/src/modules/EnvironmentVariables.ts +16 -0
- package/src/modules/ListenOptions.ts +4 -0
- package/src/modules/SSLApp.ts +13 -0
- package/src/modules/getParts.ts +29 -0
- package/src/modules/index.ts +8 -0
- package/src/modules/us_listen_socket_close.ts +15 -0
- package/src/modules/us_socket_local_port.ts +16 -0
- package/src/types/AppDescriptor.ts +7 -0
- package/src/types/AppOptions.ts +22 -0
- package/src/types/HttpRequest.ts +74 -0
- package/src/types/HttpResponse.ts +309 -0
- package/src/types/HttpRouterOptions.ts +24 -0
- package/src/types/MultipartField.ts +6 -0
- package/src/types/RecognizedString.ts +11 -0
- package/src/types/TemplatedApp.ts +285 -0
- package/src/types/WebSocket.ts +147 -0
- package/src/types/WebSocketBehaviour.ts +137 -0
- package/src/types/index.ts +12 -0
- package/src/types/us_listen_socket.ts +6 -0
- package/src/types/us_socket.ts +6 -0
- package/src/types/us_socket_context_t.ts +6 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Authored by Alex Hultman, 2018-2020.
|
|
3
|
+
* Intellectual property of third-party.
|
|
4
|
+
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#ifndef UWS_LOOP_H
|
|
19
|
+
#define UWS_LOOP_H
|
|
20
|
+
|
|
21
|
+
/* The loop is lazily created per-thread and run with run() */
|
|
22
|
+
|
|
23
|
+
#include "LoopData.h"
|
|
24
|
+
#include <libusockets.h>
|
|
25
|
+
#include <iostream>
|
|
26
|
+
|
|
27
|
+
namespace uWS {
|
|
28
|
+
|
|
29
|
+
/* A prepared message is dependent on the Loop, so it belongs here */
|
|
30
|
+
struct PreparedMessage {
|
|
31
|
+
/* These should be a single alloation along with the PreparedMessage itself (they are static) */
|
|
32
|
+
std::string originalMessage, compressedMessage;
|
|
33
|
+
bool compressed;
|
|
34
|
+
int opCode;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
struct Loop {
|
|
38
|
+
private:
|
|
39
|
+
static void wakeupCb(us_loop_t *loop) {
|
|
40
|
+
LoopData *loopData = (LoopData *) us_loop_ext(loop);
|
|
41
|
+
|
|
42
|
+
/* Swap current deferQueue */
|
|
43
|
+
loopData->deferMutex.lock();
|
|
44
|
+
int oldDeferQueue = loopData->currentDeferQueue;
|
|
45
|
+
loopData->currentDeferQueue = (loopData->currentDeferQueue + 1) % 2;
|
|
46
|
+
loopData->deferMutex.unlock();
|
|
47
|
+
|
|
48
|
+
/* Drain the queue */
|
|
49
|
+
for (auto &x : loopData->deferQueues[oldDeferQueue]) {
|
|
50
|
+
x();
|
|
51
|
+
}
|
|
52
|
+
loopData->deferQueues[oldDeferQueue].clear();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static void preCb(us_loop_t *loop) {
|
|
56
|
+
LoopData *loopData = (LoopData *) us_loop_ext(loop);
|
|
57
|
+
|
|
58
|
+
for (auto &p : loopData->preHandlers) {
|
|
59
|
+
p.second((Loop *) loop);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static void postCb(us_loop_t *loop) {
|
|
64
|
+
LoopData *loopData = (LoopData *) us_loop_ext(loop);
|
|
65
|
+
|
|
66
|
+
for (auto &p : loopData->postHandlers) {
|
|
67
|
+
p.second((Loop *) loop);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* After every event loop iteration, we must not hold the cork buffer */
|
|
71
|
+
if (loopData->corkedSocket) {
|
|
72
|
+
std::cerr << "Error: Cork buffer must not be held across event loop iterations!" << std::endl;
|
|
73
|
+
std::terminate();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
Loop() = delete;
|
|
78
|
+
~Loop() = default;
|
|
79
|
+
|
|
80
|
+
Loop *init() {
|
|
81
|
+
new (us_loop_ext((us_loop_t *) this)) LoopData;
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static Loop *create(void *hint) {
|
|
86
|
+
Loop *loop = ((Loop *) us_create_loop(hint, wakeupCb, preCb, postCb, sizeof(LoopData)))->init();
|
|
87
|
+
|
|
88
|
+
/* We also need some timers (should live off the one 4 second timer rather) */
|
|
89
|
+
LoopData *loopData = (LoopData *) us_loop_ext((struct us_loop_t *) loop);
|
|
90
|
+
loopData->dateTimer = us_create_timer((struct us_loop_t *) loop, 1, sizeof(LoopData *));
|
|
91
|
+
memcpy(us_timer_ext(loopData->dateTimer), &loopData, sizeof(LoopData *));
|
|
92
|
+
us_timer_set(loopData->dateTimer, [](struct us_timer_t *t) {
|
|
93
|
+
LoopData *loopData;
|
|
94
|
+
memcpy(&loopData, us_timer_ext(t), sizeof(LoopData *));
|
|
95
|
+
loopData->updateDate();
|
|
96
|
+
}, 1000, 1000);
|
|
97
|
+
|
|
98
|
+
return loop;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/* What to do with loops created with existingNativeLoop? */
|
|
102
|
+
struct LoopCleaner {
|
|
103
|
+
~LoopCleaner() {
|
|
104
|
+
if(loop && cleanMe) {
|
|
105
|
+
loop->free();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
Loop *loop = nullptr;
|
|
109
|
+
bool cleanMe = false;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
static LoopCleaner &getLazyLoop() {
|
|
113
|
+
static thread_local LoopCleaner lazyLoop;
|
|
114
|
+
return lazyLoop;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public:
|
|
118
|
+
|
|
119
|
+
/* Preformatted messages need the Loop */
|
|
120
|
+
PreparedMessage prepareMessage(std::string_view message, int opCode, bool compress = true) {
|
|
121
|
+
/* The message could be formatted right here, but this optimization is not done yet */
|
|
122
|
+
PreparedMessage preparedMessage;
|
|
123
|
+
preparedMessage.compressed = compress;
|
|
124
|
+
preparedMessage.opCode = opCode;
|
|
125
|
+
preparedMessage.originalMessage = message;
|
|
126
|
+
|
|
127
|
+
LoopData *loopData = (LoopData *) us_loop_ext((us_loop_t *) this);
|
|
128
|
+
|
|
129
|
+
if (compress) {
|
|
130
|
+
/* Initialize loop's deflate inflate streams */
|
|
131
|
+
if (!loopData->zlibContext) {
|
|
132
|
+
loopData->zlibContext = new ZlibContext;
|
|
133
|
+
loopData->inflationStream = new InflationStream(CompressOptions::DEDICATED_DECOMPRESSOR);
|
|
134
|
+
loopData->deflationStream = new DeflationStream(CompressOptions::DEDICATED_COMPRESSOR);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
preparedMessage.compressedMessage = loopData->deflationStream->deflate(loopData->zlibContext, {preparedMessage.originalMessage.data(), preparedMessage.originalMessage.length()}, true);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return preparedMessage;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/* Lazily initializes a per-thread loop and returns it.
|
|
144
|
+
* Will automatically free all initialized loops at exit. */
|
|
145
|
+
static Loop *get(void *existingNativeLoop = nullptr) {
|
|
146
|
+
if (!getLazyLoop().loop) {
|
|
147
|
+
/* If we are given a native loop pointer we pass that to uSockets and let it deal with it */
|
|
148
|
+
if (existingNativeLoop) {
|
|
149
|
+
/* Todo: here we want to pass the pointer, not a boolean */
|
|
150
|
+
getLazyLoop().loop = create(existingNativeLoop);
|
|
151
|
+
/* We cannot register automatic free here, must be manually done */
|
|
152
|
+
} else {
|
|
153
|
+
getLazyLoop().loop = create(nullptr);
|
|
154
|
+
getLazyLoop().cleanMe = true;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return getLazyLoop().loop;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/* Freeing the default loop should be done once */
|
|
162
|
+
void free() {
|
|
163
|
+
LoopData *loopData = (LoopData *) us_loop_ext((us_loop_t *) this);
|
|
164
|
+
|
|
165
|
+
/* Stop and free dateTimer first */
|
|
166
|
+
us_timer_close(loopData->dateTimer);
|
|
167
|
+
|
|
168
|
+
loopData->~LoopData();
|
|
169
|
+
/* uSockets will track whether this loop is owned by us or a borrowed alien loop */
|
|
170
|
+
us_loop_free((us_loop_t *) this);
|
|
171
|
+
|
|
172
|
+
/* Reset lazyLoop */
|
|
173
|
+
getLazyLoop().loop = nullptr;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
void addPostHandler(void *key, MoveOnlyFunction<void(Loop *)> &&handler) {
|
|
177
|
+
LoopData *loopData = (LoopData *) us_loop_ext((us_loop_t *) this);
|
|
178
|
+
|
|
179
|
+
loopData->postHandlers.emplace(key, std::move(handler));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/* Bug: what if you remove a handler while iterating them? */
|
|
183
|
+
void removePostHandler(void *key) {
|
|
184
|
+
LoopData *loopData = (LoopData *) us_loop_ext((us_loop_t *) this);
|
|
185
|
+
|
|
186
|
+
loopData->postHandlers.erase(key);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
void addPreHandler(void *key, MoveOnlyFunction<void(Loop *)> &&handler) {
|
|
190
|
+
LoopData *loopData = (LoopData *) us_loop_ext((us_loop_t *) this);
|
|
191
|
+
|
|
192
|
+
loopData->preHandlers.emplace(key, std::move(handler));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/* Bug: what if you remove a handler while iterating them? */
|
|
196
|
+
void removePreHandler(void *key) {
|
|
197
|
+
LoopData *loopData = (LoopData *) us_loop_ext((us_loop_t *) this);
|
|
198
|
+
|
|
199
|
+
loopData->preHandlers.erase(key);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/* Defer this callback on Loop's thread of execution */
|
|
203
|
+
void defer(MoveOnlyFunction<void()> &&cb) {
|
|
204
|
+
LoopData *loopData = (LoopData *) us_loop_ext((us_loop_t *) this);
|
|
205
|
+
|
|
206
|
+
//if (std::thread::get_id() == ) // todo: add fast path for same thread id
|
|
207
|
+
loopData->deferMutex.lock();
|
|
208
|
+
loopData->deferQueues[loopData->currentDeferQueue].emplace_back(std::move(cb));
|
|
209
|
+
loopData->deferMutex.unlock();
|
|
210
|
+
|
|
211
|
+
us_wakeup_loop((us_loop_t *) this);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/* Actively block and run this loop */
|
|
215
|
+
void run() {
|
|
216
|
+
us_loop_run((us_loop_t *) this);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/* Passively integrate with the underlying default loop */
|
|
220
|
+
/* Used to seamlessly integrate with third parties such as Node.js */
|
|
221
|
+
void integrate() {
|
|
222
|
+
us_loop_integrate((us_loop_t *) this);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/* Dynamically change this */
|
|
226
|
+
void setSilent(bool silent) {
|
|
227
|
+
((LoopData *) us_loop_ext((us_loop_t *) this))->noMark = silent;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
/* Can be called from any thread to run the thread local loop */
|
|
232
|
+
inline void run() {
|
|
233
|
+
Loop::get()->run();
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
#endif // UWS_LOOP_H
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Authored by Alex Hultman, 2018-2020.
|
|
3
|
+
* Intellectual property of third-party.
|
|
4
|
+
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#ifndef UWS_LOOPDATA_H
|
|
19
|
+
#define UWS_LOOPDATA_H
|
|
20
|
+
|
|
21
|
+
#include <thread>
|
|
22
|
+
#include <functional>
|
|
23
|
+
#include <vector>
|
|
24
|
+
#include <mutex>
|
|
25
|
+
#include <map>
|
|
26
|
+
#include <ctime>
|
|
27
|
+
#include <cstdint>
|
|
28
|
+
|
|
29
|
+
#include "PerMessageDeflate.h"
|
|
30
|
+
#include "MoveOnlyFunction.h"
|
|
31
|
+
|
|
32
|
+
struct us_timer_t;
|
|
33
|
+
|
|
34
|
+
namespace uWS {
|
|
35
|
+
|
|
36
|
+
struct Loop;
|
|
37
|
+
|
|
38
|
+
struct alignas(16) LoopData {
|
|
39
|
+
friend struct Loop;
|
|
40
|
+
private:
|
|
41
|
+
std::mutex deferMutex;
|
|
42
|
+
int currentDeferQueue = 0;
|
|
43
|
+
std::vector<MoveOnlyFunction<void()>> deferQueues[2];
|
|
44
|
+
|
|
45
|
+
/* Map from void ptr to handler */
|
|
46
|
+
std::map<void *, MoveOnlyFunction<void(Loop *)>> postHandlers, preHandlers;
|
|
47
|
+
|
|
48
|
+
public:
|
|
49
|
+
LoopData() {
|
|
50
|
+
updateDate();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
~LoopData() {
|
|
54
|
+
/* If we have had App.ws called with compression we need to clear this */
|
|
55
|
+
if (zlibContext) {
|
|
56
|
+
delete zlibContext;
|
|
57
|
+
delete inflationStream;
|
|
58
|
+
delete deflationStream;
|
|
59
|
+
}
|
|
60
|
+
delete [] corkBuffer;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
void updateDate() {
|
|
64
|
+
cacheTimepoint = time(0);
|
|
65
|
+
struct tm tstruct = {};
|
|
66
|
+
#ifdef _WIN32
|
|
67
|
+
/* Micro, fucking soft never follows spec. */
|
|
68
|
+
gmtime_s(&tstruct, &cacheTimepoint);
|
|
69
|
+
#else
|
|
70
|
+
gmtime_r(&cacheTimepoint, &tstruct);
|
|
71
|
+
#endif
|
|
72
|
+
static const char wday_name[][4] = {
|
|
73
|
+
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
|
|
74
|
+
};
|
|
75
|
+
static const char mon_name[][4] = {
|
|
76
|
+
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
|
77
|
+
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
|
78
|
+
};
|
|
79
|
+
snprintf(date, 32, "%.3s, %.2u %.3s %.4u %.2u:%.2u:%.2u GMT",
|
|
80
|
+
wday_name[tstruct.tm_wday],
|
|
81
|
+
tstruct.tm_mday % 99,
|
|
82
|
+
mon_name[tstruct.tm_mon],
|
|
83
|
+
(1900 + tstruct.tm_year) % 9999,
|
|
84
|
+
tstruct.tm_hour % 99,
|
|
85
|
+
tstruct.tm_min % 99,
|
|
86
|
+
tstruct.tm_sec % 99);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
char date[32];
|
|
90
|
+
time_t cacheTimepoint = 0;
|
|
91
|
+
|
|
92
|
+
/* Be silent */
|
|
93
|
+
bool noMark = false;
|
|
94
|
+
|
|
95
|
+
/* Good 16k for SSL perf. */
|
|
96
|
+
static const unsigned int CORK_BUFFER_SIZE = 16 * 1024;
|
|
97
|
+
|
|
98
|
+
/* Cork data */
|
|
99
|
+
char *corkBuffer = new char[CORK_BUFFER_SIZE];
|
|
100
|
+
unsigned int corkOffset = 0;
|
|
101
|
+
void *corkedSocket = nullptr;
|
|
102
|
+
|
|
103
|
+
/* Per message deflate data */
|
|
104
|
+
ZlibContext *zlibContext = nullptr;
|
|
105
|
+
InflationStream *inflationStream = nullptr;
|
|
106
|
+
DeflationStream *deflationStream = nullptr;
|
|
107
|
+
|
|
108
|
+
us_timer_t *dateTimer;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
#endif // UWS_LOOPDATA_H
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Authored by Alex Hultman, 2018-2020.
|
|
3
|
+
* Intellectual property of third-party.
|
|
4
|
+
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/* Implements the common parser (RFC 822) used in both HTTP and Multipart parsing */
|
|
19
|
+
|
|
20
|
+
#ifndef UWS_MESSAGE_PARSER_H
|
|
21
|
+
#define UWS_MESSAGE_PARSER_H
|
|
22
|
+
|
|
23
|
+
#include <string_view>
|
|
24
|
+
#include <utility>
|
|
25
|
+
#include <cstring>
|
|
26
|
+
|
|
27
|
+
/* For now we have this one here */
|
|
28
|
+
#define MAX_HEADERS 10
|
|
29
|
+
|
|
30
|
+
namespace uWS {
|
|
31
|
+
|
|
32
|
+
// should be templated on whether it needs at lest one header (http), or not (multipart)
|
|
33
|
+
static inline unsigned int getHeaders(char *postPaddedBuffer, char *end, std::pair<std::string_view, std::string_view> *headers) {
|
|
34
|
+
char *preliminaryKey, *preliminaryValue, *start = postPaddedBuffer;
|
|
35
|
+
|
|
36
|
+
for (unsigned int i = 0; i < MAX_HEADERS; i++) {
|
|
37
|
+
for (preliminaryKey = postPaddedBuffer; (*postPaddedBuffer != ':') & (*(unsigned char *)postPaddedBuffer > 32); *(postPaddedBuffer++) |= 32);
|
|
38
|
+
if (*postPaddedBuffer == '\r') {
|
|
39
|
+
if ((postPaddedBuffer != end) & (postPaddedBuffer[1] == '\n') /* & (i > 0) */) { // multipart does not require any headers like http does
|
|
40
|
+
headers->first = std::string_view(nullptr, 0);
|
|
41
|
+
return (unsigned int) ((postPaddedBuffer + 2) - start);
|
|
42
|
+
} else {
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
headers->first = std::string_view(preliminaryKey, (size_t) (postPaddedBuffer - preliminaryKey));
|
|
47
|
+
for (postPaddedBuffer++; (*postPaddedBuffer == ':' || *(unsigned char *)postPaddedBuffer < 33) && *postPaddedBuffer != '\r'; postPaddedBuffer++);
|
|
48
|
+
preliminaryValue = postPaddedBuffer;
|
|
49
|
+
postPaddedBuffer = (char *) memchr(postPaddedBuffer, '\r', end - postPaddedBuffer);
|
|
50
|
+
if (postPaddedBuffer && postPaddedBuffer[1] == '\n') {
|
|
51
|
+
headers->second = std::string_view(preliminaryValue, (size_t) (postPaddedBuffer - preliminaryValue));
|
|
52
|
+
postPaddedBuffer += 2;
|
|
53
|
+
headers++;
|
|
54
|
+
} else {
|
|
55
|
+
return 0;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
#endif
|