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.
Files changed (315) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +84 -0
  3. package/UwsReactNative.podspec +71 -0
  4. package/android/build.gradle.kts +138 -0
  5. package/android/src/main/AndroidManifest.xml +2 -0
  6. package/android/src/main/java/id/sufeni/oss/uwsreactnative/UwsReactNativePackage.kt +18 -0
  7. package/apple/OnLoad.mm +17 -0
  8. package/cpp/CMakeLists.txt +154 -0
  9. package/cpp/UwsReactNativeModule.cpp +191 -0
  10. package/cpp/UwsReactNativeModule.h +30 -0
  11. package/cpp/app/AppHost.h +37 -0
  12. package/cpp/app/AppRunner.h +88 -0
  13. package/cpp/app/CMakeLists.txt +39 -0
  14. package/cpp/app/HttpRequestObject.h +173 -0
  15. package/cpp/app/HttpResponseObject.h +623 -0
  16. package/cpp/app/RecognizedString.h +71 -0
  17. package/cpp/app/TemplatedAppObject.h +472 -0
  18. package/cpp/bridging/ArrayBuffer.h +150 -0
  19. package/cpp/bridging/CMakeLists.txt +34 -0
  20. package/cpp/jsi/Buffer.h +91 -0
  21. package/cpp/jsi/CMakeLists.txt +34 -0
  22. package/cpp/uSockets/bsd.c +767 -0
  23. package/cpp/uSockets/context.c +524 -0
  24. package/cpp/uSockets/crypto/openssl.c +858 -0
  25. package/cpp/uSockets/crypto/sni_tree.cpp +218 -0
  26. package/cpp/uSockets/eventing/asio.cpp +475 -0
  27. package/cpp/uSockets/eventing/epoll_kqueue.c +458 -0
  28. package/cpp/uSockets/eventing/gcd.c +278 -0
  29. package/cpp/uSockets/eventing/libuv.c +305 -0
  30. package/cpp/uSockets/internal/eventing/asio.h +45 -0
  31. package/cpp/uSockets/internal/eventing/epoll_kqueue.h +67 -0
  32. package/cpp/uSockets/internal/eventing/gcd.h +40 -0
  33. package/cpp/uSockets/internal/eventing/libuv.h +45 -0
  34. package/cpp/uSockets/internal/internal.h +224 -0
  35. package/cpp/uSockets/internal/loop_data.h +38 -0
  36. package/cpp/uSockets/internal/networking/bsd.h +109 -0
  37. package/cpp/uSockets/io_uring/internal.h +98 -0
  38. package/cpp/uSockets/io_uring/io_context.c +302 -0
  39. package/cpp/uSockets/io_uring/io_loop.c +422 -0
  40. package/cpp/uSockets/io_uring/io_socket.c +139 -0
  41. package/cpp/uSockets/libusockets.h +350 -0
  42. package/cpp/uSockets/loop.c +396 -0
  43. package/cpp/uSockets/quic.c +1071 -0
  44. package/cpp/uSockets/quic.h +68 -0
  45. package/cpp/uSockets/socket.c +231 -0
  46. package/cpp/uSockets/udp.c +151 -0
  47. package/cpp/uWebSockets/uWebSockets/App.h +676 -0
  48. package/cpp/uWebSockets/uWebSockets/AsyncSocket.h +376 -0
  49. package/cpp/uWebSockets/uWebSockets/AsyncSocketData.h +94 -0
  50. package/cpp/uWebSockets/uWebSockets/BloomFilter.h +83 -0
  51. package/cpp/uWebSockets/uWebSockets/CachingApp.h +115 -0
  52. package/cpp/uWebSockets/uWebSockets/ChunkedEncoding.h +237 -0
  53. package/cpp/uWebSockets/uWebSockets/ClientApp.h +36 -0
  54. package/cpp/uWebSockets/uWebSockets/Http3App.h +140 -0
  55. package/cpp/uWebSockets/uWebSockets/Http3Context.h +157 -0
  56. package/cpp/uWebSockets/uWebSockets/Http3ContextData.h +21 -0
  57. package/cpp/uWebSockets/uWebSockets/Http3Request.h +22 -0
  58. package/cpp/uWebSockets/uWebSockets/Http3Response.h +120 -0
  59. package/cpp/uWebSockets/uWebSockets/Http3ResponseData.h +25 -0
  60. package/cpp/uWebSockets/uWebSockets/HttpContext.h +521 -0
  61. package/cpp/uWebSockets/uWebSockets/HttpContextData.h +60 -0
  62. package/cpp/uWebSockets/uWebSockets/HttpErrors.h +53 -0
  63. package/cpp/uWebSockets/uWebSockets/HttpParser.h +747 -0
  64. package/cpp/uWebSockets/uWebSockets/HttpResponse.h +605 -0
  65. package/cpp/uWebSockets/uWebSockets/HttpResponseData.h +123 -0
  66. package/cpp/uWebSockets/uWebSockets/HttpRouter.h +384 -0
  67. package/cpp/uWebSockets/uWebSockets/LocalCluster.h +64 -0
  68. package/cpp/uWebSockets/uWebSockets/Loop.h +238 -0
  69. package/cpp/uWebSockets/uWebSockets/LoopData.h +113 -0
  70. package/cpp/uWebSockets/uWebSockets/MessageParser.h +64 -0
  71. package/cpp/uWebSockets/uWebSockets/MoveOnlyFunction.h +389 -0
  72. package/cpp/uWebSockets/uWebSockets/Multipart.h +231 -0
  73. package/cpp/uWebSockets/uWebSockets/PerMessageDeflate.h +303 -0
  74. package/cpp/uWebSockets/uWebSockets/ProxyParser.h +187 -0
  75. package/cpp/uWebSockets/uWebSockets/QueryParser.h +120 -0
  76. package/cpp/uWebSockets/uWebSockets/TopicTree.h +364 -0
  77. package/cpp/uWebSockets/uWebSockets/Utilities.h +66 -0
  78. package/cpp/uWebSockets/uWebSockets/WebSocket.h +407 -0
  79. package/cpp/uWebSockets/uWebSockets/WebSocketContext.h +436 -0
  80. package/cpp/uWebSockets/uWebSockets/WebSocketContextData.h +109 -0
  81. package/cpp/uWebSockets/uWebSockets/WebSocketData.h +86 -0
  82. package/cpp/uWebSockets/uWebSockets/WebSocketExtensions.h +256 -0
  83. package/cpp/uWebSockets/uWebSockets/WebSocketHandshake.h +145 -0
  84. package/cpp/uWebSockets/uWebSockets/WebSocketProtocol.h +525 -0
  85. package/lib/commonjs/_internal/native-modules/NativeReactNativeUws.js +12 -0
  86. package/lib/commonjs/_internal/native-modules/NativeReactNativeUws.js.map +1 -0
  87. package/lib/commonjs/index.js +28 -0
  88. package/lib/commonjs/index.js.map +1 -0
  89. package/lib/commonjs/modules/App.js +17 -0
  90. package/lib/commonjs/modules/App.js.map +1 -0
  91. package/lib/commonjs/modules/CompressOptions.js +103 -0
  92. package/lib/commonjs/modules/CompressOptions.js.map +1 -0
  93. package/lib/commonjs/modules/EnvironmentVariables.js +17 -0
  94. package/lib/commonjs/modules/EnvironmentVariables.js.map +1 -0
  95. package/lib/commonjs/modules/ListenOptions.js +12 -0
  96. package/lib/commonjs/modules/ListenOptions.js.map +1 -0
  97. package/lib/commonjs/modules/SSLApp.js +15 -0
  98. package/lib/commonjs/modules/SSLApp.js.map +1 -0
  99. package/lib/commonjs/modules/getParts.js +28 -0
  100. package/lib/commonjs/modules/getParts.js.map +1 -0
  101. package/lib/commonjs/modules/index.js +61 -0
  102. package/lib/commonjs/modules/index.js.map +1 -0
  103. package/lib/commonjs/modules/us_listen_socket_close.js +21 -0
  104. package/lib/commonjs/modules/us_listen_socket_close.js.map +1 -0
  105. package/lib/commonjs/modules/us_socket_local_port.js +22 -0
  106. package/lib/commonjs/modules/us_socket_local_port.js.map +1 -0
  107. package/lib/commonjs/package.json +1 -0
  108. package/lib/commonjs/types/AppDescriptor.js +2 -0
  109. package/lib/commonjs/types/AppDescriptor.js.map +1 -0
  110. package/lib/commonjs/types/AppOptions.js +2 -0
  111. package/lib/commonjs/types/AppOptions.js.map +1 -0
  112. package/lib/commonjs/types/HttpRequest.js +6 -0
  113. package/lib/commonjs/types/HttpRequest.js.map +1 -0
  114. package/lib/commonjs/types/HttpResponse.js +6 -0
  115. package/lib/commonjs/types/HttpResponse.js.map +1 -0
  116. package/lib/commonjs/types/HttpRouterOptions.js +2 -0
  117. package/lib/commonjs/types/HttpRouterOptions.js.map +1 -0
  118. package/lib/commonjs/types/MultipartField.js +2 -0
  119. package/lib/commonjs/types/MultipartField.js.map +1 -0
  120. package/lib/commonjs/types/RecognizedString.js +2 -0
  121. package/lib/commonjs/types/RecognizedString.js.map +1 -0
  122. package/lib/commonjs/types/TemplatedApp.js +6 -0
  123. package/lib/commonjs/types/TemplatedApp.js.map +1 -0
  124. package/lib/commonjs/types/WebSocket.js +6 -0
  125. package/lib/commonjs/types/WebSocket.js.map +1 -0
  126. package/lib/commonjs/types/WebSocketBehaviour.js +139 -0
  127. package/lib/commonjs/types/WebSocketBehaviour.js.map +1 -0
  128. package/lib/commonjs/types/index.js +2 -0
  129. package/lib/commonjs/types/index.js.map +1 -0
  130. package/lib/commonjs/types/us_listen_socket.js +2 -0
  131. package/lib/commonjs/types/us_listen_socket.js.map +1 -0
  132. package/lib/commonjs/types/us_socket.js +2 -0
  133. package/lib/commonjs/types/us_socket.js.map +1 -0
  134. package/lib/commonjs/types/us_socket_context_t.js +2 -0
  135. package/lib/commonjs/types/us_socket_context_t.js.map +1 -0
  136. package/lib/module/_internal/native-modules/NativeReactNativeUws.js +10 -0
  137. package/lib/module/_internal/native-modules/NativeReactNativeUws.js.map +1 -0
  138. package/lib/module/index.js +5 -0
  139. package/lib/module/index.js.map +1 -0
  140. package/lib/module/modules/App.js +12 -0
  141. package/lib/module/modules/App.js.map +1 -0
  142. package/lib/module/modules/CompressOptions.js +103 -0
  143. package/lib/module/modules/CompressOptions.js.map +1 -0
  144. package/lib/module/modules/EnvironmentVariables.js +13 -0
  145. package/lib/module/modules/EnvironmentVariables.js.map +1 -0
  146. package/lib/module/modules/ListenOptions.js +8 -0
  147. package/lib/module/modules/ListenOptions.js.map +1 -0
  148. package/lib/module/modules/SSLApp.js +15 -0
  149. package/lib/module/modules/SSLApp.js.map +1 -0
  150. package/lib/module/modules/getParts.js +23 -0
  151. package/lib/module/modules/getParts.js.map +1 -0
  152. package/lib/module/modules/index.js +11 -0
  153. package/lib/module/modules/index.js.map +1 -0
  154. package/lib/module/modules/us_listen_socket_close.js +17 -0
  155. package/lib/module/modules/us_listen_socket_close.js.map +1 -0
  156. package/lib/module/modules/us_socket_local_port.js +18 -0
  157. package/lib/module/modules/us_socket_local_port.js.map +1 -0
  158. package/lib/module/package.json +1 -0
  159. package/lib/module/types/AppDescriptor.js +2 -0
  160. package/lib/module/types/AppDescriptor.js.map +1 -0
  161. package/lib/module/types/AppOptions.js +2 -0
  162. package/lib/module/types/AppOptions.js.map +1 -0
  163. package/lib/module/types/HttpRequest.js +4 -0
  164. package/lib/module/types/HttpRequest.js.map +1 -0
  165. package/lib/module/types/HttpResponse.js +4 -0
  166. package/lib/module/types/HttpResponse.js.map +1 -0
  167. package/lib/module/types/HttpRouterOptions.js +2 -0
  168. package/lib/module/types/HttpRouterOptions.js.map +1 -0
  169. package/lib/module/types/MultipartField.js +2 -0
  170. package/lib/module/types/MultipartField.js.map +1 -0
  171. package/lib/module/types/RecognizedString.js +2 -0
  172. package/lib/module/types/RecognizedString.js.map +1 -0
  173. package/lib/module/types/TemplatedApp.js +4 -0
  174. package/lib/module/types/TemplatedApp.js.map +1 -0
  175. package/lib/module/types/WebSocket.js +4 -0
  176. package/lib/module/types/WebSocket.js.map +1 -0
  177. package/lib/module/types/WebSocketBehaviour.js +139 -0
  178. package/lib/module/types/WebSocketBehaviour.js.map +1 -0
  179. package/lib/module/types/index.js +2 -0
  180. package/lib/module/types/index.js.map +1 -0
  181. package/lib/module/types/us_listen_socket.js +2 -0
  182. package/lib/module/types/us_listen_socket.js.map +1 -0
  183. package/lib/module/types/us_socket.js +2 -0
  184. package/lib/module/types/us_socket.js.map +1 -0
  185. package/lib/module/types/us_socket_context_t.js +2 -0
  186. package/lib/module/types/us_socket_context_t.js.map +1 -0
  187. package/lib/typescript/commonjs/_internal/native-modules/NativeReactNativeUws.d.ts +22 -0
  188. package/lib/typescript/commonjs/_internal/native-modules/NativeReactNativeUws.d.ts.map +1 -0
  189. package/lib/typescript/commonjs/index.d.ts +3 -0
  190. package/lib/typescript/commonjs/index.d.ts.map +1 -0
  191. package/lib/typescript/commonjs/modules/App.d.ts +7 -0
  192. package/lib/typescript/commonjs/modules/App.d.ts.map +1 -0
  193. package/lib/typescript/commonjs/modules/CompressOptions.d.ts +1 -0
  194. package/lib/typescript/commonjs/modules/CompressOptions.d.ts.map +1 -0
  195. package/lib/typescript/commonjs/modules/EnvironmentVariables.d.ts +16 -0
  196. package/lib/typescript/commonjs/modules/EnvironmentVariables.d.ts.map +1 -0
  197. package/lib/typescript/commonjs/modules/ListenOptions.d.ts +5 -0
  198. package/lib/typescript/commonjs/modules/ListenOptions.d.ts.map +1 -0
  199. package/lib/typescript/commonjs/modules/SSLApp.d.ts +1 -0
  200. package/lib/typescript/commonjs/modules/SSLApp.d.ts.map +1 -0
  201. package/lib/typescript/commonjs/modules/getParts.d.ts +6 -0
  202. package/lib/typescript/commonjs/modules/getParts.d.ts.map +1 -0
  203. package/lib/typescript/commonjs/modules/index.d.ts +6 -0
  204. package/lib/typescript/commonjs/modules/index.d.ts.map +1 -0
  205. package/lib/typescript/commonjs/modules/us_listen_socket_close.d.ts +5 -0
  206. package/lib/typescript/commonjs/modules/us_listen_socket_close.d.ts.map +1 -0
  207. package/lib/typescript/commonjs/modules/us_socket_local_port.d.ts +5 -0
  208. package/lib/typescript/commonjs/modules/us_socket_local_port.d.ts.map +1 -0
  209. package/lib/typescript/commonjs/package.json +1 -0
  210. package/lib/typescript/commonjs/types/AppDescriptor.d.ts +8 -0
  211. package/lib/typescript/commonjs/types/AppDescriptor.d.ts.map +1 -0
  212. package/lib/typescript/commonjs/types/AppOptions.d.ts +17 -0
  213. package/lib/typescript/commonjs/types/AppOptions.d.ts.map +1 -0
  214. package/lib/typescript/commonjs/types/HttpRequest.d.ts +54 -0
  215. package/lib/typescript/commonjs/types/HttpRequest.d.ts.map +1 -0
  216. package/lib/typescript/commonjs/types/HttpResponse.d.ts +169 -0
  217. package/lib/typescript/commonjs/types/HttpResponse.d.ts.map +1 -0
  218. package/lib/typescript/commonjs/types/HttpRouterOptions.d.ts +24 -0
  219. package/lib/typescript/commonjs/types/HttpRouterOptions.d.ts.map +1 -0
  220. package/lib/typescript/commonjs/types/MultipartField.d.ts +7 -0
  221. package/lib/typescript/commonjs/types/MultipartField.d.ts.map +1 -0
  222. package/lib/typescript/commonjs/types/RecognizedString.d.ts +10 -0
  223. package/lib/typescript/commonjs/types/RecognizedString.d.ts.map +1 -0
  224. package/lib/typescript/commonjs/types/TemplatedApp.d.ts +108 -0
  225. package/lib/typescript/commonjs/types/TemplatedApp.d.ts.map +1 -0
  226. package/lib/typescript/commonjs/types/WebSocket.d.ts +96 -0
  227. package/lib/typescript/commonjs/types/WebSocket.d.ts.map +1 -0
  228. package/lib/typescript/commonjs/types/WebSocketBehaviour.d.ts +1 -0
  229. package/lib/typescript/commonjs/types/WebSocketBehaviour.d.ts.map +1 -0
  230. package/lib/typescript/commonjs/types/index.d.ts +6 -0
  231. package/lib/typescript/commonjs/types/index.d.ts.map +1 -0
  232. package/lib/typescript/commonjs/types/us_listen_socket.d.ts +7 -0
  233. package/lib/typescript/commonjs/types/us_listen_socket.d.ts.map +1 -0
  234. package/lib/typescript/commonjs/types/us_socket.d.ts +7 -0
  235. package/lib/typescript/commonjs/types/us_socket.d.ts.map +1 -0
  236. package/lib/typescript/commonjs/types/us_socket_context_t.d.ts +7 -0
  237. package/lib/typescript/commonjs/types/us_socket_context_t.d.ts.map +1 -0
  238. package/lib/typescript/module/_internal/native-modules/NativeReactNativeUws.d.ts +22 -0
  239. package/lib/typescript/module/_internal/native-modules/NativeReactNativeUws.d.ts.map +1 -0
  240. package/lib/typescript/module/index.d.ts +3 -0
  241. package/lib/typescript/module/index.d.ts.map +1 -0
  242. package/lib/typescript/module/modules/App.d.ts +7 -0
  243. package/lib/typescript/module/modules/App.d.ts.map +1 -0
  244. package/lib/typescript/module/modules/CompressOptions.d.ts +1 -0
  245. package/lib/typescript/module/modules/CompressOptions.d.ts.map +1 -0
  246. package/lib/typescript/module/modules/EnvironmentVariables.d.ts +16 -0
  247. package/lib/typescript/module/modules/EnvironmentVariables.d.ts.map +1 -0
  248. package/lib/typescript/module/modules/ListenOptions.d.ts +5 -0
  249. package/lib/typescript/module/modules/ListenOptions.d.ts.map +1 -0
  250. package/lib/typescript/module/modules/SSLApp.d.ts +1 -0
  251. package/lib/typescript/module/modules/SSLApp.d.ts.map +1 -0
  252. package/lib/typescript/module/modules/getParts.d.ts +6 -0
  253. package/lib/typescript/module/modules/getParts.d.ts.map +1 -0
  254. package/lib/typescript/module/modules/index.d.ts +6 -0
  255. package/lib/typescript/module/modules/index.d.ts.map +1 -0
  256. package/lib/typescript/module/modules/us_listen_socket_close.d.ts +5 -0
  257. package/lib/typescript/module/modules/us_listen_socket_close.d.ts.map +1 -0
  258. package/lib/typescript/module/modules/us_socket_local_port.d.ts +5 -0
  259. package/lib/typescript/module/modules/us_socket_local_port.d.ts.map +1 -0
  260. package/lib/typescript/module/package.json +1 -0
  261. package/lib/typescript/module/types/AppDescriptor.d.ts +8 -0
  262. package/lib/typescript/module/types/AppDescriptor.d.ts.map +1 -0
  263. package/lib/typescript/module/types/AppOptions.d.ts +17 -0
  264. package/lib/typescript/module/types/AppOptions.d.ts.map +1 -0
  265. package/lib/typescript/module/types/HttpRequest.d.ts +54 -0
  266. package/lib/typescript/module/types/HttpRequest.d.ts.map +1 -0
  267. package/lib/typescript/module/types/HttpResponse.d.ts +169 -0
  268. package/lib/typescript/module/types/HttpResponse.d.ts.map +1 -0
  269. package/lib/typescript/module/types/HttpRouterOptions.d.ts +24 -0
  270. package/lib/typescript/module/types/HttpRouterOptions.d.ts.map +1 -0
  271. package/lib/typescript/module/types/MultipartField.d.ts +7 -0
  272. package/lib/typescript/module/types/MultipartField.d.ts.map +1 -0
  273. package/lib/typescript/module/types/RecognizedString.d.ts +10 -0
  274. package/lib/typescript/module/types/RecognizedString.d.ts.map +1 -0
  275. package/lib/typescript/module/types/TemplatedApp.d.ts +108 -0
  276. package/lib/typescript/module/types/TemplatedApp.d.ts.map +1 -0
  277. package/lib/typescript/module/types/WebSocket.d.ts +96 -0
  278. package/lib/typescript/module/types/WebSocket.d.ts.map +1 -0
  279. package/lib/typescript/module/types/WebSocketBehaviour.d.ts +1 -0
  280. package/lib/typescript/module/types/WebSocketBehaviour.d.ts.map +1 -0
  281. package/lib/typescript/module/types/index.d.ts +6 -0
  282. package/lib/typescript/module/types/index.d.ts.map +1 -0
  283. package/lib/typescript/module/types/us_listen_socket.d.ts +7 -0
  284. package/lib/typescript/module/types/us_listen_socket.d.ts.map +1 -0
  285. package/lib/typescript/module/types/us_socket.d.ts +7 -0
  286. package/lib/typescript/module/types/us_socket.d.ts.map +1 -0
  287. package/lib/typescript/module/types/us_socket_context_t.d.ts +7 -0
  288. package/lib/typescript/module/types/us_socket_context_t.d.ts.map +1 -0
  289. package/lib/typescript/tsconfig.tsbuildinfo +1 -0
  290. package/package.json +62 -0
  291. package/src/_internal/native-modules/NativeUwsReactNative.ts +40 -0
  292. package/src/index.ts +2 -0
  293. package/src/modules/App.ts +14 -0
  294. package/src/modules/CompressOptions.ts +101 -0
  295. package/src/modules/EnvironmentVariables.ts +16 -0
  296. package/src/modules/ListenOptions.ts +4 -0
  297. package/src/modules/SSLApp.ts +13 -0
  298. package/src/modules/getParts.ts +29 -0
  299. package/src/modules/index.ts +8 -0
  300. package/src/modules/us_listen_socket_close.ts +15 -0
  301. package/src/modules/us_socket_local_port.ts +16 -0
  302. package/src/types/AppDescriptor.ts +7 -0
  303. package/src/types/AppOptions.ts +22 -0
  304. package/src/types/HttpRequest.ts +74 -0
  305. package/src/types/HttpResponse.ts +309 -0
  306. package/src/types/HttpRouterOptions.ts +24 -0
  307. package/src/types/MultipartField.ts +6 -0
  308. package/src/types/RecognizedString.ts +11 -0
  309. package/src/types/TemplatedApp.ts +285 -0
  310. package/src/types/WebSocket.ts +147 -0
  311. package/src/types/WebSocketBehaviour.ts +137 -0
  312. package/src/types/index.ts +12 -0
  313. package/src/types/us_listen_socket.ts +6 -0
  314. package/src/types/us_socket.ts +6 -0
  315. package/src/types/us_socket_context_t.ts +6 -0
@@ -0,0 +1,40 @@
1
+ /*
2
+ * Authored by Alex Hultman, 2018-2019.
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 GCD_H
19
+ #define GCD_H
20
+
21
+ #include "internal/loop_data.h"
22
+
23
+ #include <dispatch/dispatch.h>
24
+ #define LIBUS_SOCKET_READABLE 1
25
+ #define LIBUS_SOCKET_WRITABLE 2
26
+
27
+ struct us_loop_t {
28
+ alignas(LIBUS_EXT_ALIGNMENT) struct us_internal_loop_data_t data;
29
+
30
+ dispatch_queue_t gcd_queue;
31
+ };
32
+
33
+ struct us_poll_t {
34
+ int events;
35
+ dispatch_source_t gcd_read, gcd_write;
36
+ LIBUS_SOCKET_DESCRIPTOR fd;
37
+ unsigned char poll_type;
38
+ };
39
+
40
+ #endif // GCD_H
@@ -0,0 +1,45 @@
1
+ /*
2
+ * Authored by Alex Hultman, 2018-2019.
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 LIBUV_H
19
+ #define LIBUV_H
20
+
21
+ #include "internal/loop_data.h"
22
+
23
+ #include <uv.h>
24
+ #define LIBUS_SOCKET_READABLE UV_READABLE
25
+ #define LIBUS_SOCKET_WRITABLE UV_WRITABLE
26
+
27
+ struct us_loop_t {
28
+ alignas(LIBUS_EXT_ALIGNMENT) struct us_internal_loop_data_t data;
29
+
30
+ uv_loop_t *uv_loop;
31
+ int is_default;
32
+
33
+ uv_prepare_t *uv_pre;
34
+ uv_check_t *uv_check;
35
+ };
36
+
37
+ // it is no longer valid to cast a pointer to us_poll_t to a pointer of uv_poll_t
38
+ struct us_poll_t {
39
+ /* We need to hold a pointer to this uv_poll_t since we need to be able to resize our block */
40
+ uv_poll_t *uv_p;
41
+ LIBUS_SOCKET_DESCRIPTOR fd;
42
+ unsigned char poll_type;
43
+ };
44
+
45
+ #endif // LIBUV_H
@@ -0,0 +1,224 @@
1
+ /*
2
+ * Authored by Alex Hultman, 2018-2019.
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 INTERNAL_H
19
+ #define INTERNAL_H
20
+
21
+ #if defined(_MSC_VER)
22
+ #define alignas(x) __declspec(align(x))
23
+ #else
24
+ #include <stdalign.h>
25
+ #endif
26
+
27
+ /* We only have one networking implementation so far */
28
+ #include "internal/networking/bsd.h"
29
+
30
+ // WARNING: This MUST be included after bsd.h, otherwise sys/socket includes
31
+ // fail surprisingly.
32
+ #include <stdint.h>
33
+
34
+ #ifndef LIBUS_USE_IO_URING
35
+
36
+ /* We have many different eventing implementations */
37
+ #if defined(LIBUS_USE_EPOLL) || defined(LIBUS_USE_KQUEUE)
38
+ #include "internal/eventing/epoll_kqueue.h"
39
+ #endif
40
+ #ifdef LIBUS_USE_LIBUV
41
+ #include "internal/eventing/libuv.h"
42
+ #endif
43
+ #ifdef LIBUS_USE_GCD
44
+ #include "internal/eventing/gcd.h"
45
+ #endif
46
+ #ifdef LIBUS_USE_ASIO
47
+ #include "internal/eventing/asio.h"
48
+ #endif
49
+
50
+ /* Poll type and what it polls for */
51
+ enum {
52
+ /* Two first bits */
53
+ POLL_TYPE_SOCKET = 0,
54
+ POLL_TYPE_SOCKET_SHUT_DOWN = 1,
55
+ POLL_TYPE_SEMI_SOCKET = 2,
56
+ POLL_TYPE_CALLBACK = 3,
57
+
58
+ /* Two last bits */
59
+ POLL_TYPE_POLLING_OUT = 4,
60
+ POLL_TYPE_POLLING_IN = 8
61
+ };
62
+
63
+ /* Loop related */
64
+ void us_internal_dispatch_ready_poll(struct us_poll_t *p, int error, int events);
65
+ void us_internal_timer_sweep(struct us_loop_t *loop);
66
+ void us_internal_free_closed_sockets(struct us_loop_t *loop);
67
+ void us_internal_loop_link(struct us_loop_t *loop, struct us_socket_context_t *context);
68
+ void us_internal_loop_unlink(struct us_loop_t *loop, struct us_socket_context_t *context);
69
+ void us_internal_loop_data_init(struct us_loop_t *loop, void (*wakeup_cb)(struct us_loop_t *loop),
70
+ void (*pre_cb)(struct us_loop_t *loop), void (*post_cb)(struct us_loop_t *loop));
71
+ void us_internal_loop_data_free(struct us_loop_t *loop);
72
+ void us_internal_loop_pre(struct us_loop_t *loop);
73
+ void us_internal_loop_post(struct us_loop_t *loop);
74
+
75
+ /* Asyncs (old) */
76
+ struct us_internal_async *us_internal_create_async(struct us_loop_t *loop, int fallthrough, unsigned int ext_size);
77
+ void us_internal_async_close(struct us_internal_async *a);
78
+ void us_internal_async_set(struct us_internal_async *a, void (*cb)(struct us_internal_async *));
79
+ void us_internal_async_wakeup(struct us_internal_async *a);
80
+
81
+ /* Eventing related */
82
+ unsigned int us_internal_accept_poll_event(struct us_poll_t *p);
83
+ int us_internal_poll_type(struct us_poll_t *p);
84
+ void us_internal_poll_set_type(struct us_poll_t *p, int poll_type);
85
+
86
+ /* SSL loop data */
87
+ void us_internal_init_loop_ssl_data(struct us_loop_t *loop);
88
+ void us_internal_free_loop_ssl_data(struct us_loop_t *loop);
89
+
90
+ /* Socket context related */
91
+ void us_internal_socket_context_link_socket(struct us_socket_context_t *context, struct us_socket_t *s);
92
+ void us_internal_socket_context_unlink_socket(struct us_socket_context_t *context, struct us_socket_t *s);
93
+
94
+ /* Sockets are polls */
95
+ struct us_socket_t {
96
+ alignas(LIBUS_EXT_ALIGNMENT) struct us_poll_t p; // 4 bytes
97
+ unsigned char timeout; // 1 byte
98
+ unsigned char long_timeout; // 1 byte
99
+ unsigned short low_prio_state; /* 0 = not in low-prio queue, 1 = is in low-prio queue, 2 = was in low-prio queue in this iteration */
100
+ struct us_socket_context_t *context;
101
+ struct us_socket_t *prev, *next;
102
+ };
103
+
104
+ /* Internal callback types are polls just like sockets */
105
+ struct us_internal_callback_t {
106
+ alignas(LIBUS_EXT_ALIGNMENT) struct us_poll_t p;
107
+ struct us_loop_t *loop;
108
+ int cb_expects_the_loop;
109
+ int leave_poll_ready;
110
+ void (*cb)(struct us_internal_callback_t *cb);
111
+ };
112
+
113
+ /* Listen sockets are sockets */
114
+ struct us_listen_socket_t {
115
+ alignas(LIBUS_EXT_ALIGNMENT) struct us_socket_t s;
116
+ unsigned int socket_ext_size;
117
+ };
118
+
119
+ /* Listen sockets are keps in their own list */
120
+ void us_internal_socket_context_link_listen_socket(struct us_socket_context_t *context, struct us_listen_socket_t *s);
121
+ void us_internal_socket_context_unlink_listen_socket(struct us_socket_context_t *context, struct us_listen_socket_t *s);
122
+
123
+ struct us_socket_context_t {
124
+ alignas(LIBUS_EXT_ALIGNMENT) struct us_loop_t *loop;
125
+ uint32_t global_tick;
126
+ unsigned char timestamp;
127
+ unsigned char long_timestamp;
128
+ struct us_socket_t *head_sockets;
129
+ struct us_listen_socket_t *head_listen_sockets;
130
+ struct us_socket_t *iterator;
131
+ struct us_socket_context_t *prev, *next;
132
+
133
+ LIBUS_SOCKET_DESCRIPTOR (*on_pre_open)(LIBUS_SOCKET_DESCRIPTOR fd);
134
+ struct us_socket_t *(*on_open)(struct us_socket_t *, int is_client, char *ip, int ip_length);
135
+ struct us_socket_t *(*on_data)(struct us_socket_t *, char *data, int length);
136
+ struct us_socket_t *(*on_writable)(struct us_socket_t *);
137
+ struct us_socket_t *(*on_close)(struct us_socket_t *, int code, void *reason);
138
+ //void (*on_timeout)(struct us_socket_context *);
139
+ struct us_socket_t *(*on_socket_timeout)(struct us_socket_t *);
140
+ struct us_socket_t *(*on_socket_long_timeout)(struct us_socket_t *);
141
+ struct us_socket_t *(*on_end)(struct us_socket_t *);
142
+ struct us_socket_t *(*on_connect_error)(struct us_socket_t *, int code);
143
+ int (*is_low_prio)(struct us_socket_t *);
144
+ };
145
+
146
+ #endif
147
+
148
+ /* Internal SSL interface */
149
+ #ifndef LIBUS_NO_SSL
150
+
151
+ struct us_internal_ssl_socket_context_t;
152
+ struct us_internal_ssl_socket_t;
153
+
154
+ /* SNI functions */
155
+ void us_internal_ssl_socket_context_add_server_name(struct us_internal_ssl_socket_context_t *context, const char *hostname_pattern, struct us_socket_context_options_t options, void *user);
156
+ void us_internal_ssl_socket_context_remove_server_name(struct us_internal_ssl_socket_context_t *context, const char *hostname_pattern);
157
+ void us_internal_ssl_socket_context_on_server_name(struct us_internal_ssl_socket_context_t *context, void (*cb)(struct us_internal_ssl_socket_context_t *, const char *));
158
+ void *us_internal_ssl_socket_get_sni_userdata(struct us_internal_ssl_socket_t *s);
159
+ void *us_internal_ssl_socket_context_find_server_name_userdata(struct us_internal_ssl_socket_context_t *context, const char *hostname_pattern);
160
+
161
+ void *us_internal_ssl_socket_get_native_handle(struct us_internal_ssl_socket_t *s);
162
+ void *us_internal_ssl_socket_context_get_native_handle(struct us_internal_ssl_socket_context_t *context);
163
+
164
+ struct us_internal_ssl_socket_context_t *us_internal_create_ssl_socket_context(struct us_loop_t *loop,
165
+ int context_ext_size, struct us_socket_context_options_t options);
166
+
167
+ void us_internal_ssl_socket_context_free(struct us_internal_ssl_socket_context_t *context);
168
+ void us_internal_ssl_socket_context_on_open(struct us_internal_ssl_socket_context_t *context,
169
+ struct us_internal_ssl_socket_t *(*on_open)(struct us_internal_ssl_socket_t *s, int is_client, char *ip, int ip_length));
170
+
171
+ void us_internal_ssl_socket_context_on_close(struct us_internal_ssl_socket_context_t *context,
172
+ struct us_internal_ssl_socket_t *(*on_close)(struct us_internal_ssl_socket_t *s, int code, void *reason));
173
+
174
+ void us_internal_ssl_socket_context_on_data(struct us_internal_ssl_socket_context_t *context,
175
+ struct us_internal_ssl_socket_t *(*on_data)(struct us_internal_ssl_socket_t *s, char *data, int length));
176
+
177
+ void us_internal_ssl_socket_context_on_writable(struct us_internal_ssl_socket_context_t *context,
178
+ struct us_internal_ssl_socket_t *(*on_writable)(struct us_internal_ssl_socket_t *s));
179
+
180
+ void us_internal_ssl_socket_context_on_timeout(struct us_internal_ssl_socket_context_t *context,
181
+ struct us_internal_ssl_socket_t *(*on_timeout)(struct us_internal_ssl_socket_t *s));
182
+
183
+ void us_internal_ssl_socket_context_on_long_timeout(struct us_internal_ssl_socket_context_t *context,
184
+ struct us_internal_ssl_socket_t *(*on_timeout)(struct us_internal_ssl_socket_t *s));
185
+
186
+ void us_internal_ssl_socket_context_on_end(struct us_internal_ssl_socket_context_t *context,
187
+ struct us_internal_ssl_socket_t *(*on_end)(struct us_internal_ssl_socket_t *s));
188
+
189
+ void us_internal_ssl_socket_context_on_connect_error(struct us_internal_ssl_socket_context_t *context,
190
+ struct us_internal_ssl_socket_t *(*on_connect_error)(struct us_internal_ssl_socket_t *s, int code));
191
+
192
+ struct us_listen_socket_t *us_internal_ssl_socket_context_listen(struct us_internal_ssl_socket_context_t *context,
193
+ const char *host, int port, int options, int socket_ext_size);
194
+
195
+ struct us_listen_socket_t *us_internal_ssl_socket_context_listen_unix(struct us_internal_ssl_socket_context_t *context,
196
+ const char *path, int options, int socket_ext_size);
197
+
198
+ struct us_internal_ssl_socket_t *us_internal_ssl_adopt_accepted_socket(struct us_internal_ssl_socket_context_t *context, LIBUS_SOCKET_DESCRIPTOR accepted_fd,
199
+ unsigned int socket_ext_size, char *addr_ip, int addr_ip_length);
200
+
201
+ struct us_internal_ssl_socket_t *us_internal_ssl_socket_context_connect(struct us_internal_ssl_socket_context_t *context,
202
+ const char *host, int port, const char *source_host, int options, int socket_ext_size);
203
+
204
+
205
+ struct us_internal_ssl_socket_t *us_internal_ssl_socket_context_connect_unix(struct us_internal_ssl_socket_context_t *context,
206
+ const char *server_path, int options, int socket_ext_size);
207
+
208
+ int us_internal_ssl_socket_write(struct us_internal_ssl_socket_t *s, const char *data, int length, int msg_more);
209
+ void us_internal_ssl_socket_timeout(struct us_internal_ssl_socket_t *s, unsigned int seconds);
210
+ void *us_internal_ssl_socket_context_ext(struct us_internal_ssl_socket_context_t *s);
211
+ struct us_internal_ssl_socket_context_t *us_internal_ssl_socket_get_context(struct us_internal_ssl_socket_t *s);
212
+ void *us_internal_ssl_socket_ext(struct us_internal_ssl_socket_t *s);
213
+ int us_internal_ssl_socket_is_shut_down(struct us_internal_ssl_socket_t *s);
214
+ void us_internal_ssl_socket_shutdown(struct us_internal_ssl_socket_t *s);
215
+
216
+ struct us_internal_ssl_socket_t *us_internal_ssl_socket_context_adopt_socket(struct us_internal_ssl_socket_context_t *context,
217
+ struct us_internal_ssl_socket_t *s, int ext_size);
218
+
219
+ struct us_internal_ssl_socket_context_t *us_internal_create_child_ssl_socket_context(struct us_internal_ssl_socket_context_t *context, int context_ext_size);
220
+ struct us_loop_t *us_internal_ssl_socket_context_loop(struct us_internal_ssl_socket_context_t *context);
221
+
222
+ #endif
223
+
224
+ #endif // INTERNAL_H
@@ -0,0 +1,38 @@
1
+ /*
2
+ * Authored by Alex Hultman, 2018-2019.
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 LOOP_DATA_H
19
+ #define LOOP_DATA_H
20
+
21
+ struct us_internal_loop_data_t {
22
+ struct us_timer_t *sweep_timer;
23
+ struct us_internal_async *wakeup_async;
24
+ int last_write_failed;
25
+ struct us_socket_context_t *head;
26
+ struct us_socket_context_t *iterator;
27
+ char *recv_buf;
28
+ void *ssl_data;
29
+ void (*pre_cb)(struct us_loop_t *);
30
+ void (*post_cb)(struct us_loop_t *);
31
+ struct us_socket_t *closed_head;
32
+ struct us_socket_t *low_prio_head;
33
+ int low_prio_budget;
34
+ /* We do not care if this flips or not, it doesn't matter */
35
+ long long iteration_nr;
36
+ };
37
+
38
+ #endif // LOOP_DATA_H
@@ -0,0 +1,109 @@
1
+ /*
2
+ * Authored by Alex Hultman, 2018-2019.
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 BSD_H
19
+ #define BSD_H
20
+
21
+ // top-most wrapper of bsd-like syscalls
22
+
23
+ // holds everything you need from the bsd/winsock interfaces, only included by internal libusockets.h
24
+ // here everything about the syscalls are inline-wrapped and included
25
+
26
+ #include "libusockets.h"
27
+
28
+ #ifdef _WIN32
29
+ #ifndef NOMINMAX
30
+ #define NOMINMAX
31
+ #endif
32
+ #include <winsock2.h>
33
+ #include <ws2tcpip.h>
34
+ #pragma comment(lib, "ws2_32.lib")
35
+ #define SETSOCKOPT_PTR_TYPE const char *
36
+ #define LIBUS_SOCKET_ERROR INVALID_SOCKET
37
+ #else
38
+ #ifndef _GNU_SOURCE
39
+ #define _GNU_SOURCE
40
+ #endif
41
+ /* For socklen_t */
42
+ #include <sys/socket.h>
43
+ #define SETSOCKOPT_PTR_TYPE int *
44
+ #define LIBUS_SOCKET_ERROR -1
45
+ #endif
46
+
47
+ #define LIBUS_UDP_MAX_SIZE (64 * 1024)
48
+ #define LIBUS_UDP_MAX_NUM 1024
49
+
50
+ struct bsd_addr_t {
51
+ struct sockaddr_storage mem;
52
+ socklen_t len;
53
+ char *ip;
54
+ int ip_length;
55
+ int port;
56
+ };
57
+
58
+ int bsd_sendmmsg(LIBUS_SOCKET_DESCRIPTOR fd, void *msgvec, unsigned int vlen, int flags);
59
+ int bsd_recvmmsg(LIBUS_SOCKET_DESCRIPTOR fd, void *msgvec, unsigned int vlen, int flags, void *timeout);
60
+ int bsd_udp_packet_buffer_payload_length(void *msgvec, int index);
61
+ char *bsd_udp_packet_buffer_payload(void *msgvec, int index);
62
+ char *bsd_udp_packet_buffer_peer(void *msgvec, int index);
63
+ int bsd_udp_packet_buffer_local_ip(void *msgvec, int index, char *ip);
64
+ int bsd_udp_packet_buffer_ecn(void *msgvec, int index);
65
+ void *bsd_create_udp_packet_buffer();
66
+ void bsd_udp_buffer_set_packet_payload(struct us_udp_packet_buffer_t *send_buf, int index, int offset, void *payload, int length, void *peer_addr);
67
+
68
+ LIBUS_SOCKET_DESCRIPTOR apple_no_sigpipe(LIBUS_SOCKET_DESCRIPTOR fd);
69
+ LIBUS_SOCKET_DESCRIPTOR bsd_set_nonblocking(LIBUS_SOCKET_DESCRIPTOR fd);
70
+ void bsd_socket_nodelay(LIBUS_SOCKET_DESCRIPTOR fd, int enabled);
71
+ void bsd_socket_flush(LIBUS_SOCKET_DESCRIPTOR fd);
72
+ LIBUS_SOCKET_DESCRIPTOR bsd_create_socket(int domain, int type, int protocol);
73
+
74
+ void bsd_close_socket(LIBUS_SOCKET_DESCRIPTOR fd);
75
+ void bsd_shutdown_socket(LIBUS_SOCKET_DESCRIPTOR fd);
76
+ void bsd_shutdown_socket_read(LIBUS_SOCKET_DESCRIPTOR fd);
77
+
78
+ void internal_finalize_bsd_addr(struct bsd_addr_t *addr);
79
+
80
+ int bsd_local_addr(LIBUS_SOCKET_DESCRIPTOR fd, struct bsd_addr_t *addr);
81
+ int bsd_remote_addr(LIBUS_SOCKET_DESCRIPTOR fd, struct bsd_addr_t *addr);
82
+
83
+ char *bsd_addr_get_ip(struct bsd_addr_t *addr);
84
+ int bsd_addr_get_ip_length(struct bsd_addr_t *addr);
85
+
86
+ int bsd_addr_get_port(struct bsd_addr_t *addr);
87
+
88
+ // called by dispatch_ready_poll
89
+ LIBUS_SOCKET_DESCRIPTOR bsd_accept_socket(LIBUS_SOCKET_DESCRIPTOR fd, struct bsd_addr_t *addr);
90
+
91
+ int bsd_recv(LIBUS_SOCKET_DESCRIPTOR fd, void *buf, int length, int flags);
92
+ int bsd_send(LIBUS_SOCKET_DESCRIPTOR fd, const char *buf, int length, int msg_more);
93
+ int bsd_write2(LIBUS_SOCKET_DESCRIPTOR fd, const char *header, int header_length, const char *payload, int payload_length);
94
+ int bsd_would_block();
95
+
96
+ // return LIBUS_SOCKET_ERROR or the fd that represents listen socket
97
+ // listen both on ipv6 and ipv4
98
+ LIBUS_SOCKET_DESCRIPTOR bsd_create_listen_socket(const char *host, int port, int options);
99
+
100
+ LIBUS_SOCKET_DESCRIPTOR bsd_create_listen_socket_unix(const char *path, int options);
101
+
102
+ /* Creates an UDP socket bound to the hostname and port */
103
+ LIBUS_SOCKET_DESCRIPTOR bsd_create_udp_socket(const char *host, int port);
104
+
105
+ LIBUS_SOCKET_DESCRIPTOR bsd_create_connect_socket(const char *host, int port, const char *source_host, int options);
106
+
107
+ LIBUS_SOCKET_DESCRIPTOR bsd_create_connect_socket_unix(const char *server_path, int options);
108
+
109
+ #endif // BSD_H
@@ -0,0 +1,98 @@
1
+ #include <errno.h>
2
+ #include <fcntl.h>
3
+ #include <netinet/in.h>
4
+ #include <stdio.h>
5
+ #include <stdlib.h>
6
+ #include <string.h>
7
+ #include <strings.h>
8
+ #include <sys/poll.h>
9
+ #include <sys/socket.h>
10
+ #include <unistd.h>
11
+
12
+ #include "liburing.h"
13
+
14
+ #define MAX_CONNECTIONS 4096
15
+ #define BACKLOG 512
16
+ #define MAX_MESSAGE_LEN 2048
17
+ #define BUFFERS_COUNT MAX_CONNECTIONS
18
+
19
+ void add_accept(struct io_uring *ring, int fd, struct sockaddr *client_addr, socklen_t *client_len, unsigned flags);
20
+ void add_socket_read(struct io_uring *ring, int fd, unsigned gid, size_t size, unsigned flags);
21
+ void add_socket_write(struct io_uring *ring, int fd, __u16 bid, size_t size, unsigned flags);
22
+ void add_provide_buf(struct io_uring *ring, __u16 bid, unsigned gid);
23
+
24
+ // 8 byte aligned pointer offset
25
+ enum pointer_tags {
26
+ SOCKET_READ,
27
+ SOCKET_WRITE,
28
+ LISTEN_SOCKET_ACCEPT,
29
+ SOCKET_CONNECT,
30
+ LOOP_TIMER = 7,
31
+ };
32
+
33
+ #include <netinet/tcp.h>
34
+
35
+ /*void bsd_socket_nodelay(int fd, int enabled) {
36
+ setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (void *) &enabled, sizeof(enabled));
37
+ }*/
38
+
39
+ void us_internal_loop_link(struct us_loop_t *loop, struct us_socket_context_t *context);
40
+ void us_internal_socket_context_link_socket(struct us_socket_context_t *context, struct us_socket_t *s);
41
+
42
+ struct us_timer_t {
43
+ struct us_loop_t *loop;
44
+ int fd;
45
+ uint64_t buf;
46
+ };
47
+
48
+ struct us_loop_t {
49
+ struct io_uring ring;
50
+ struct io_uring_buf_ring *buf_ring;
51
+
52
+ struct us_timer_t *timer;
53
+
54
+
55
+ struct us_socket_context_t *head;
56
+ struct us_socket_context_t *iterator;
57
+
58
+ uint64_t next_timeout;
59
+
60
+ // let's say there is only one context for now
61
+ //struct us_socket_context_t *context_head;
62
+ };
63
+
64
+ struct us_socket_context_t {
65
+ struct us_loop_t *loop;
66
+ uint32_t global_tick;
67
+ unsigned char timestamp;
68
+ unsigned char long_timestamp;
69
+ struct us_socket_t *head_sockets;
70
+ struct us_listen_socket_t *head_listen_sockets;
71
+ struct us_socket_t *iterator;
72
+ struct us_socket_context_t *prev, *next;
73
+
74
+ struct us_socket_t *(*on_open)(struct us_socket_t *, int is_client, char *ip, int ip_length);
75
+ struct us_socket_t *(*on_data)(struct us_socket_t *, char *data, int length);
76
+ struct us_socket_t *(*on_writable)(struct us_socket_t *);
77
+ struct us_socket_t *(*on_close)(struct us_socket_t *, int code, void *reason);
78
+ //void (*on_timeout)(struct us_socket_context *);
79
+ struct us_socket_t *(*on_socket_timeout)(struct us_socket_t *);
80
+ struct us_socket_t *(*on_socket_long_timeout)(struct us_socket_t *);
81
+ struct us_socket_t *(*on_end)(struct us_socket_t *);
82
+ struct us_socket_t *(*on_connect_error)(struct us_socket_t *, int code);
83
+ };
84
+
85
+ struct us_listen_socket_t {
86
+ struct us_socket_context_t *context;
87
+ int socket_ext_size;
88
+ };
89
+
90
+ struct us_socket_t {
91
+ struct us_socket_context_t *context;
92
+ struct us_socket_t *prev, *next;
93
+ unsigned char timeout; // 1 byte
94
+ unsigned char long_timeout; // 1 byte
95
+ int dd;
96
+
97
+ char sendBuf[16 * 1024];
98
+ };