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,422 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Authored by Alex Hultman, 2018-2021.
|
|
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
|
+
#ifdef LIBUS_USE_IO_URING
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
#include "libusockets.h"
|
|
22
|
+
#include "internal/internal.h"
|
|
23
|
+
#include "internal.h"
|
|
24
|
+
#include <stdlib.h>
|
|
25
|
+
|
|
26
|
+
char bufs[BUFFERS_COUNT][MAX_MESSAGE_LEN] = {0};
|
|
27
|
+
int group_id = 1337;
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
/* This functions should never run recursively */
|
|
31
|
+
void us_internal_timer_sweep(struct us_loop_t *loop) {
|
|
32
|
+
struct us_loop_t *loop_data = loop;
|
|
33
|
+
/* For all socket contexts in this loop */
|
|
34
|
+
for (loop_data->iterator = loop_data->head; loop_data->iterator; loop_data->iterator = loop_data->iterator->next) {
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
struct us_socket_context_t *context = loop_data->iterator;
|
|
38
|
+
|
|
39
|
+
/* Update this context's timestamps (this could be moved to loop and done once) */
|
|
40
|
+
context->global_tick++;
|
|
41
|
+
unsigned char short_ticks = context->timestamp = context->global_tick % 240;
|
|
42
|
+
unsigned char long_ticks = context->long_timestamp = (context->global_tick / 15) % 240;
|
|
43
|
+
|
|
44
|
+
/* Begin at head */
|
|
45
|
+
struct us_socket_t *s = context->head_sockets;
|
|
46
|
+
while (s) {
|
|
47
|
+
/* Seek until end or timeout found (tightest loop) */
|
|
48
|
+
while (1) {
|
|
49
|
+
/* We only read from 1 random cache line here */
|
|
50
|
+
if (short_ticks == s->timeout || long_ticks == s->long_timeout) {
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/* Did we reach the end without a find? */
|
|
55
|
+
if ((s = s->next) == 0) {
|
|
56
|
+
goto next_context;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/* Here we have a timeout to emit (slow path) */
|
|
61
|
+
context->iterator = s;
|
|
62
|
+
|
|
63
|
+
if (short_ticks == s->timeout) {
|
|
64
|
+
s->timeout = 255;
|
|
65
|
+
context->on_socket_timeout(s);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (context->iterator == s && long_ticks == s->long_timeout) {
|
|
69
|
+
s->long_timeout = 255;
|
|
70
|
+
context->on_socket_long_timeout(s);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/* Check for unlink / link (if the event handler did not modify the chain, we step 1) */
|
|
74
|
+
if (s == context->iterator) {
|
|
75
|
+
s = s->next;
|
|
76
|
+
} else {
|
|
77
|
+
/* The iterator was changed by event handler */
|
|
78
|
+
s = context->iterator;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/* We always store a 0 to context->iterator here since we are no longer iterating this context */
|
|
82
|
+
next_context:
|
|
83
|
+
context->iterator = 0;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
/* The loop has 2 fallthrough polls */
|
|
89
|
+
void us_loop_run(struct us_loop_t *loop) {
|
|
90
|
+
|
|
91
|
+
us_timer_set(loop->timer, NULL, LIBUS_TIMEOUT_GRANULARITY * 1000, LIBUS_TIMEOUT_GRANULARITY * 1000);
|
|
92
|
+
|
|
93
|
+
// // register a timeout
|
|
94
|
+
// struct __kernel_timespec ts;
|
|
95
|
+
// ts.tv_sec = 4;
|
|
96
|
+
// ts.tv_nsec = 0;
|
|
97
|
+
|
|
98
|
+
// struct io_uring_sqe *sqe = io_uring_get_sqe(&loop->ring);
|
|
99
|
+
// io_uring_prep_timeout(sqe, &ts, 1, IORING_TIMEOUT_REALTIME | IORING_TIMEOUT_ETIME_SUCCESS);
|
|
100
|
+
// io_uring_sqe_set_data(sqe, (char *)loop + LOOP_TIMER);
|
|
101
|
+
|
|
102
|
+
while (1) {
|
|
103
|
+
io_uring_submit_and_wait(&loop->ring, 1);
|
|
104
|
+
struct io_uring_cqe *cqe;
|
|
105
|
+
unsigned head;
|
|
106
|
+
unsigned count = 0;
|
|
107
|
+
|
|
108
|
+
// go through all CQEs
|
|
109
|
+
io_uring_for_each_cqe(&loop->ring, head, cqe) {
|
|
110
|
+
++count;
|
|
111
|
+
//struct conn_info conn_i;
|
|
112
|
+
//memcpy(&conn_i, &cqe->user_data, sizeof(conn_i));
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
int pointer_tag = (int)((uintptr_t)io_uring_cqe_get_data(cqe) & (uintptr_t)0x7ull);
|
|
116
|
+
void *object = (void *)((uintptr_t)io_uring_cqe_get_data(cqe) & (uintptr_t)0xFFFFFFFFFFFFFFF8ull);
|
|
117
|
+
|
|
118
|
+
if (pointer_tag == 6) {
|
|
119
|
+
printf("uuuuuuuuh: %d\n", cqe->res);
|
|
120
|
+
exit(1);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
//printf("pointer tag is %d\n", pointer_tag);
|
|
124
|
+
|
|
125
|
+
int type = pointer_tag;//conn_i.type;
|
|
126
|
+
if (cqe->res == -ENOBUFS) {
|
|
127
|
+
fprintf(stdout, "bufs in automatic buffer selection empty, this should not happen...\n");
|
|
128
|
+
fflush(stdout);
|
|
129
|
+
exit(1);
|
|
130
|
+
}/* else if (type == PROV_BUF) {
|
|
131
|
+
if (cqe->res < 0) {
|
|
132
|
+
printf("cqe->res = %d\n", cqe->res);
|
|
133
|
+
exit(1);
|
|
134
|
+
}
|
|
135
|
+
} */else if (type == LISTEN_SOCKET_ACCEPT) {
|
|
136
|
+
|
|
137
|
+
struct us_listen_socket_t *listen_s = object;
|
|
138
|
+
|
|
139
|
+
// we need the listen_socket attached to the accept request to know the ext size and context
|
|
140
|
+
struct us_socket_t *s = malloc(sizeof(struct us_socket_t) + listen_s->socket_ext_size);
|
|
141
|
+
s->context = listen_s->context;
|
|
142
|
+
s->dd = cqe->res;
|
|
143
|
+
s->timeout = 255;
|
|
144
|
+
s->long_timeout = 255;
|
|
145
|
+
s->prev = s->next = 0;
|
|
146
|
+
|
|
147
|
+
us_internal_socket_context_link_socket(listen_s->context, s);
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
// register this send buffer as registered buffer (using the DD of the socket as index!)
|
|
151
|
+
struct iovec iovecs = {s->sendBuf, 16 * 1024};
|
|
152
|
+
//printf("register: %d\n", io_uring_register_buffers_update_tag(&loop->ring, s->dd, &iovecs, 0, 1));
|
|
153
|
+
|
|
154
|
+
int sock_conn_fd = cqe->res;
|
|
155
|
+
// only read when there is no error, >= 0
|
|
156
|
+
if (sock_conn_fd >= 0) {
|
|
157
|
+
// this will not succeed since we don't have FD we have DD
|
|
158
|
+
//bsd_socket_nodelay(sock_conn_fd, 1);
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
struct io_uring_sqe *sqe = io_uring_get_sqe(&loop->ring);
|
|
162
|
+
io_uring_prep_recv_multishot(sqe, s->dd, NULL, 0/*message_size*/, 0);
|
|
163
|
+
io_uring_sqe_set_flags(sqe, IOSQE_BUFFER_SELECT | IOSQE_FIXED_FILE);
|
|
164
|
+
sqe->buf_group = group_id;
|
|
165
|
+
|
|
166
|
+
io_uring_sqe_set_data(sqe, (char *)s + SOCKET_READ);
|
|
167
|
+
|
|
168
|
+
//printf("starting to read on new socket: %p\n", s);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
s->context->on_open(s, 1, 0, 0);
|
|
172
|
+
|
|
173
|
+
} else if (type == SOCKET_READ) {
|
|
174
|
+
int bytes_read = cqe->res;
|
|
175
|
+
int bid = cqe->flags >> 16;
|
|
176
|
+
if (cqe->res <= 0) {
|
|
177
|
+
// read failed, re-add the buffer
|
|
178
|
+
|
|
179
|
+
//add_provide_buf(&loop->ring, bid, group_id);
|
|
180
|
+
|
|
181
|
+
io_uring_buf_ring_add(loop->buf_ring, bufs[bid], MAX_MESSAGE_LEN, bid, io_uring_buf_ring_mask(4096), 0);
|
|
182
|
+
loop->buf_ring->tail++;
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
// connection closed or error
|
|
186
|
+
//close(conn_i.fd);
|
|
187
|
+
struct io_uring_sqe *sqe = io_uring_get_sqe(&loop->ring);
|
|
188
|
+
|
|
189
|
+
struct us_socket_t *s = object;
|
|
190
|
+
|
|
191
|
+
//printf("closed socket: %p\n", s);
|
|
192
|
+
|
|
193
|
+
s->context->on_close(s, 0, 0);
|
|
194
|
+
|
|
195
|
+
io_uring_prep_close_direct(sqe, s->dd);
|
|
196
|
+
io_uring_sqe_set_flags(sqe, IOSQE_CQE_SKIP_SUCCESS);
|
|
197
|
+
io_uring_sqe_set_data64(sqe, 5);
|
|
198
|
+
} else {
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
struct us_socket_t *s = object;
|
|
202
|
+
|
|
203
|
+
//printf("emitting read on new socket: %p\n", s);
|
|
204
|
+
|
|
205
|
+
s->context->on_data(s, bufs[bid], bytes_read);
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
io_uring_buf_ring_add(loop->buf_ring, bufs[bid], MAX_MESSAGE_LEN, bid, io_uring_buf_ring_mask(4096), 0);
|
|
209
|
+
loop->buf_ring->tail++;
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
//add_socket_write(&loop->ring, s->dd, bid, bytes_read, IOSQE_FIXED_FILE);
|
|
213
|
+
}
|
|
214
|
+
} else if (type == SOCKET_WRITE) {
|
|
215
|
+
// write has been completed, first re-add the buffer
|
|
216
|
+
//add_provide_buf(&loop->ring, conn_i.bid, group_id);
|
|
217
|
+
// add a new read for the existing connection
|
|
218
|
+
|
|
219
|
+
} else if (type == SOCKET_CONNECT) {
|
|
220
|
+
//printf("we are connectred: %d\n", cqe->res);
|
|
221
|
+
|
|
222
|
+
struct us_socket_t *s = object;
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
struct io_uring_sqe *sqe = io_uring_get_sqe(&loop->ring);
|
|
226
|
+
io_uring_prep_recv_multishot(sqe, s->dd, NULL, 0/*message_size*/, 0);
|
|
227
|
+
io_uring_sqe_set_flags(sqe, IOSQE_BUFFER_SELECT | IOSQE_FIXED_FILE);
|
|
228
|
+
sqe->buf_group = group_id;
|
|
229
|
+
|
|
230
|
+
io_uring_sqe_set_data(sqe, (char *)s + SOCKET_READ);
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
s->context->on_open(s, 1, 0, 0);
|
|
234
|
+
} else if (type == LOOP_TIMER) {
|
|
235
|
+
//if (cqe->res == 0) {
|
|
236
|
+
//printf("timer tick %d\n", cqe->res);
|
|
237
|
+
us_internal_timer_sweep(loop);
|
|
238
|
+
//}
|
|
239
|
+
|
|
240
|
+
struct us_timer_t *t = object;
|
|
241
|
+
|
|
242
|
+
struct io_uring_sqe *sqe = io_uring_get_sqe(&loop->ring);
|
|
243
|
+
io_uring_prep_read(sqe, t->fd, &t->buf, 8, 0);
|
|
244
|
+
io_uring_sqe_set_data(sqe, (char *)t + LOOP_TIMER);
|
|
245
|
+
|
|
246
|
+
// struct __kernel_timespec ts;
|
|
247
|
+
// ts.tv_sec = 4;
|
|
248
|
+
// ts.tv_nsec = 0;
|
|
249
|
+
|
|
250
|
+
// struct io_uring_sqe *sqe = io_uring_get_sqe(&loop->ring);
|
|
251
|
+
// io_uring_prep_timeout(sqe, &ts, 1, IORING_TIMEOUT_REALTIME | IORING_TIMEOUT_ETIME_SUCCESS);
|
|
252
|
+
// io_uring_sqe_set_data(sqe, (char *)loop + LOOP_TIMER);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
io_uring_cq_advance(&loop->ring, count);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
#include <sys/timerfd.h>
|
|
261
|
+
|
|
262
|
+
struct us_timer_t *us_create_timer(struct us_loop_t *loop, int fallthrough, unsigned int ext_size) {
|
|
263
|
+
struct us_timer_t *timer = malloc(ext_size + sizeof(struct us_timer_t));
|
|
264
|
+
|
|
265
|
+
timer->loop = loop;
|
|
266
|
+
|
|
267
|
+
int timerfd = timerfd_create(CLOCK_REALTIME, TFD_NONBLOCK | TFD_CLOEXEC);
|
|
268
|
+
if (timerfd == -1) {
|
|
269
|
+
return NULL;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
timer->fd = timerfd;
|
|
273
|
+
|
|
274
|
+
return timer;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
void us_timer_set(struct us_timer_t *t, void (*cb)(struct us_timer_t *t), int ms, int repeat_ms) {
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
struct itimerspec timer_spec = {
|
|
281
|
+
{repeat_ms / 1000, (long) (repeat_ms % 1000) * (long) 1000000},
|
|
282
|
+
{ms / 1000, (long) (ms % 1000) * (long) 1000000}
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
timerfd_settime(t->fd, 0, &timer_spec, NULL);
|
|
286
|
+
|
|
287
|
+
// prep read into uint64_t of timer
|
|
288
|
+
|
|
289
|
+
struct io_uring_sqe *sqe = io_uring_get_sqe(&t->loop->ring);
|
|
290
|
+
io_uring_prep_read(sqe, t->fd, &t->buf, 8, 0);
|
|
291
|
+
io_uring_sqe_set_data(sqe, (char *)t + LOOP_TIMER);
|
|
292
|
+
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
void *us_timer_ext(struct us_timer_t *timer) {
|
|
296
|
+
return timer + 1;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
void us_timer_close(struct us_timer_t *timer) {
|
|
300
|
+
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
struct us_loop_t *us_timer_loop(struct us_timer_t *t) {
|
|
304
|
+
return t->loop;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
void us_loop_free(struct us_loop_t *loop) {
|
|
308
|
+
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
struct us_loop_t *us_create_loop(void *hint, void (*wakeup_cb)(struct us_loop_t *loop), void (*pre_cb)(struct us_loop_t *loop), void (*post_cb)(struct us_loop_t *loop), unsigned int ext_size) {
|
|
312
|
+
|
|
313
|
+
struct us_loop_t *loop = malloc(ext_size + sizeof(struct us_loop_t));
|
|
314
|
+
|
|
315
|
+
loop->timer = us_create_timer(loop, 1, 0);
|
|
316
|
+
|
|
317
|
+
loop->head = 0;
|
|
318
|
+
loop->iterator = 0;
|
|
319
|
+
//loop->closed_head = 0;
|
|
320
|
+
//loop->low_prio_head = 0;
|
|
321
|
+
//loop->low_prio_budget = 0;
|
|
322
|
+
|
|
323
|
+
//loop->pre_cb = pre_cb;
|
|
324
|
+
//loop->post_cb = post_cb;
|
|
325
|
+
//loop->iteration_nr = 0;
|
|
326
|
+
|
|
327
|
+
struct io_uring_params params;
|
|
328
|
+
memset(¶ms, 0, sizeof(params));
|
|
329
|
+
params.flags = IORING_SETUP_COOP_TASKRUN | IORING_SETUP_SINGLE_ISSUER;
|
|
330
|
+
if (io_uring_queue_init_params(2048, &loop->ring, ¶ms) < 0) {
|
|
331
|
+
perror("io_uring_init_failed...\n");
|
|
332
|
+
exit(1);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (io_uring_register_files_sparse(&loop->ring, 1024)) {
|
|
336
|
+
exit(1);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
io_uring_register_ring_fd(&loop->ring);
|
|
340
|
+
|
|
341
|
+
// create buffer ring here
|
|
342
|
+
struct io_uring_buf_reg reg = {0};
|
|
343
|
+
posix_memalign(®.ring_addr, 1024 * 4, sizeof(struct io_uring_buf) * 4096);
|
|
344
|
+
reg.ring_entries = 4096;
|
|
345
|
+
reg.bgid = 1337;
|
|
346
|
+
loop->buf_ring = reg.ring_addr;
|
|
347
|
+
|
|
348
|
+
// registrera buffer ring bvuffer
|
|
349
|
+
if (io_uring_register_buf_ring(&loop->ring, ®, 0)) {
|
|
350
|
+
printf("Failed to register ring\n");
|
|
351
|
+
exit(1);
|
|
352
|
+
}
|
|
353
|
+
io_uring_buf_ring_init(loop->buf_ring);
|
|
354
|
+
|
|
355
|
+
for (int i = 0; i < 4096; i++) {
|
|
356
|
+
io_uring_buf_ring_add(loop->buf_ring, bufs[i], MAX_MESSAGE_LEN, i, io_uring_buf_ring_mask(4096), i);
|
|
357
|
+
}
|
|
358
|
+
io_uring_buf_ring_advance(loop->buf_ring, 4096);
|
|
359
|
+
|
|
360
|
+
return loop;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
void us_internal_loop_data_free(struct us_loop_t *loop) {
|
|
364
|
+
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
void us_wakeup_loop(struct us_loop_t *loop) {
|
|
368
|
+
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
void us_internal_loop_link(struct us_loop_t *loop, struct us_socket_context_t *context) {
|
|
372
|
+
/* Insert this context as the head of loop */
|
|
373
|
+
context->next = loop->head;
|
|
374
|
+
context->prev = 0;
|
|
375
|
+
if (loop->head) {
|
|
376
|
+
loop->head->prev = context;
|
|
377
|
+
}
|
|
378
|
+
loop->head = context;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/* Unlink is called before free */
|
|
382
|
+
void us_internal_loop_unlink(struct us_loop_t *loop, struct us_socket_context_t *context) {
|
|
383
|
+
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/* We do not want to block the loop with tons and tons of CPU-intensive work for SSL handshakes.
|
|
387
|
+
* Spread it out during many loop iterations, prioritizing already open connections, they are far
|
|
388
|
+
* easier on CPU */
|
|
389
|
+
static const int MAX_LOW_PRIO_SOCKETS_PER_LOOP_ITERATION = 5;
|
|
390
|
+
|
|
391
|
+
void us_internal_handle_low_priority_sockets(struct us_loop_t *loop) {
|
|
392
|
+
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/* Note: Properly takes the linked list and timeout sweep into account */
|
|
396
|
+
void us_internal_free_closed_sockets(struct us_loop_t *loop) {
|
|
397
|
+
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
long long us_loop_iteration_number(struct us_loop_t *loop) {
|
|
401
|
+
return 0;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/* These may have somewhat different meaning depending on the underlying event library */
|
|
405
|
+
void us_internal_loop_pre(struct us_loop_t *loop) {
|
|
406
|
+
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
void us_internal_loop_post(struct us_loop_t *loop) {
|
|
410
|
+
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/* Integration only requires the timer to be set up */
|
|
414
|
+
void us_loop_integrate(struct us_loop_t *loop) {
|
|
415
|
+
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
void *us_loop_ext(struct us_loop_t *loop) {
|
|
419
|
+
return loop + 1;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
#endif
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Authored by Alex Hultman, 2018-2021.
|
|
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
|
+
#ifdef LIBUS_USE_IO_URING
|
|
19
|
+
|
|
20
|
+
#include "libusockets.h"
|
|
21
|
+
#include "internal/internal.h"
|
|
22
|
+
#include "internal.h"
|
|
23
|
+
#include <stdlib.h>
|
|
24
|
+
#include <string.h>
|
|
25
|
+
#include <stdint.h>
|
|
26
|
+
#include <stdio.h>
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
/* Shared with SSL */
|
|
31
|
+
|
|
32
|
+
int us_socket_local_port(int ssl, struct us_socket_t *s) {
|
|
33
|
+
return 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
int us_socket_remote_port(int ssl, struct us_socket_t *s) {
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
void us_socket_shutdown_read(int ssl, struct us_socket_t *s) {
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
void us_socket_remote_address(int ssl, struct us_socket_t *s, char *buf, int *length) {
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
struct us_socket_context_t *us_socket_context(int ssl, struct us_socket_t *s) {
|
|
49
|
+
return s->context;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
void us_socket_timeout(int ssl, struct us_socket_t *s, unsigned int seconds) {
|
|
53
|
+
if (seconds) {
|
|
54
|
+
s->timeout = ((unsigned int)s->context->timestamp + ((seconds + 3) >> 2)) % 240;
|
|
55
|
+
} else {
|
|
56
|
+
s->timeout = 255;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
void us_socket_long_timeout(int ssl, struct us_socket_t *s, unsigned int minutes) {
|
|
61
|
+
if (minutes) {
|
|
62
|
+
s->long_timeout = ((unsigned int)s->context->long_timestamp + minutes) % 240;
|
|
63
|
+
} else {
|
|
64
|
+
s->long_timeout = 255;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
void us_socket_flush(int ssl, struct us_socket_t *s) {
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
int us_socket_is_closed(int ssl, struct us_socket_t *s) {
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
int us_socket_is_established(int ssl, struct us_socket_t *s) {
|
|
77
|
+
return 1;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/* Exactly the same as us_socket_close but does not emit on_close event */
|
|
81
|
+
struct us_socket_t *us_socket_close_connecting(int ssl, struct us_socket_t *s) {
|
|
82
|
+
return s;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
int us_socket_write2(int ssl, struct us_socket_t *s, const char *header, int header_length, const char *payload, int payload_length) {
|
|
86
|
+
exit(1);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
char *us_socket_send_buffer(int ssl, struct us_socket_t *s) {
|
|
90
|
+
return s->sendBuf;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/* Same as above but emits on_close */
|
|
94
|
+
struct us_socket_t *us_socket_close(int ssl, struct us_socket_t *s, int code, void *reason) {
|
|
95
|
+
return s;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/* Not shared with SSL */
|
|
99
|
+
|
|
100
|
+
void *us_socket_get_native_handle(int ssl, struct us_socket_t *s) {
|
|
101
|
+
return 0;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
int us_socket_write(int ssl, struct us_socket_t *s, const char *data, int length, int msg_more) {
|
|
105
|
+
|
|
106
|
+
//printf("writing on socket now\n");
|
|
107
|
+
|
|
108
|
+
if (data != s->sendBuf) {
|
|
109
|
+
//printf("WHAT THE HECK!\n");
|
|
110
|
+
memcpy(s->sendBuf, data, length);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
struct io_uring_sqe *sqe = io_uring_get_sqe(&s->context->loop->ring);
|
|
115
|
+
|
|
116
|
+
io_uring_prep_send(sqe, s->dd, s->sendBuf, length, 0);
|
|
117
|
+
|
|
118
|
+
//io_uring_prep_write_fixed(sqe, s->dd, s->sendBuf, length, 0, s->dd);
|
|
119
|
+
|
|
120
|
+
io_uring_sqe_set_flags(sqe, IOSQE_FIXED_FILE);
|
|
121
|
+
io_uring_sqe_set_data(sqe, (char *)s + SOCKET_WRITE);
|
|
122
|
+
|
|
123
|
+
return length;
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
void *us_socket_ext(int ssl, struct us_socket_t *s) {
|
|
128
|
+
return s + 1;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
int us_socket_is_shut_down(int ssl, struct us_socket_t *s) {
|
|
132
|
+
return 0;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
void us_socket_shutdown(int ssl, struct us_socket_t *s) {
|
|
136
|
+
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
#endif
|