@encharm/cws 4.3.0 → 4.4.0

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 (234) hide show
  1. package/README.md +5 -7
  2. package/dist/bindings/cws_darwin_arm64_node108.node +0 -0
  3. package/dist/bindings/cws_darwin_arm64_node115.node +0 -0
  4. package/dist/bindings/cws_darwin_arm64_node83.node +0 -0
  5. package/dist/bindings/cws_darwin_arm64_node93.node +0 -0
  6. package/dist/bindings/cws_darwin_x64_node108.node +0 -0
  7. package/dist/bindings/cws_darwin_x64_node115.node +0 -0
  8. package/dist/bindings/cws_darwin_x64_node83.node +0 -0
  9. package/dist/bindings/cws_darwin_x64_node93.node +0 -0
  10. package/dist/bindings/cws_linux_arm64_node108.node +0 -0
  11. package/dist/bindings/cws_linux_arm64_node115.node +0 -0
  12. package/dist/bindings/cws_linux_arm64_node83.node +0 -0
  13. package/dist/bindings/cws_linux_arm64_node93.node +0 -0
  14. package/dist/bindings/cws_linux_x64_node108.node +0 -0
  15. package/dist/bindings/cws_linux_x64_node115.node +0 -0
  16. package/dist/bindings/cws_linux_x64_node83.node +0 -0
  17. package/dist/bindings/cws_linux_x64_node93.node +0 -0
  18. package/dist/bindings/cws_win32_x64_node108.node +0 -0
  19. package/dist/bindings/cws_win32_x64_node115.node +0 -0
  20. package/dist/bindings/cws_win32_x64_node83.node +0 -0
  21. package/dist/bindings/cws_win32_x64_node93.node +0 -0
  22. package/dist/shared.js +1 -1
  23. package/package.json +5 -5
  24. package/src/Addon.cpp +4 -12
  25. package/src/Addon.h +55 -90
  26. package/src/Socket.h +1 -0
  27. package/src/cSNode.cpp +3 -8
  28. package/src/headers/20/acorn_version.h +6 -0
  29. package/src/headers/20/aliased_buffer-inl.h +243 -0
  30. package/src/headers/20/aliased_buffer.h +206 -0
  31. package/src/headers/20/aliased_struct-inl.h +54 -0
  32. package/src/headers/20/aliased_struct.h +63 -0
  33. package/src/headers/20/async_wrap-inl.h +93 -0
  34. package/src/headers/20/async_wrap.h +252 -0
  35. package/src/headers/20/base64-inl.h +193 -0
  36. package/src/headers/20/base64.h +53 -0
  37. package/src/headers/20/base64_version.h +6 -0
  38. package/src/headers/20/base_object-inl.h +316 -0
  39. package/src/headers/20/base_object.h +320 -0
  40. package/src/headers/20/base_object_types.h +73 -0
  41. package/src/headers/20/blob_serializer_deserializer-inl.h +361 -0
  42. package/src/headers/20/blob_serializer_deserializer.h +132 -0
  43. package/src/headers/20/callback_queue-inl.h +97 -0
  44. package/src/headers/20/callback_queue.h +79 -0
  45. package/src/headers/20/cares_wrap.h +524 -0
  46. package/src/headers/20/cjs_module_lexer_version.h +6 -0
  47. package/src/headers/20/cleanup_queue-inl.h +62 -0
  48. package/src/headers/20/cleanup_queue.h +85 -0
  49. package/src/headers/20/connect_wrap.h +26 -0
  50. package/src/headers/20/connection_wrap.h +29 -0
  51. package/src/headers/20/cppgc/DEPS +8 -0
  52. package/src/headers/20/cppgc/OWNERS +2 -0
  53. package/src/headers/20/cppgc/README.md +135 -0
  54. package/src/headers/20/cppgc/allocation.h +310 -0
  55. package/src/headers/20/cppgc/common.h +28 -0
  56. package/src/headers/20/cppgc/cross-thread-persistent.h +466 -0
  57. package/src/headers/20/cppgc/custom-space.h +97 -0
  58. package/src/headers/20/cppgc/default-platform.h +67 -0
  59. package/src/headers/20/cppgc/ephemeron-pair.h +30 -0
  60. package/src/headers/20/cppgc/explicit-management.h +100 -0
  61. package/src/headers/20/cppgc/garbage-collected.h +106 -0
  62. package/src/headers/20/cppgc/heap-consistency.h +309 -0
  63. package/src/headers/20/cppgc/heap-handle.h +48 -0
  64. package/src/headers/20/cppgc/heap-state.h +82 -0
  65. package/src/headers/20/cppgc/heap-statistics.h +120 -0
  66. package/src/headers/20/cppgc/heap.h +202 -0
  67. package/src/headers/20/cppgc/internal/api-constants.h +68 -0
  68. package/src/headers/20/cppgc/internal/atomic-entry-flag.h +48 -0
  69. package/src/headers/20/cppgc/internal/base-page-handle.h +45 -0
  70. package/src/headers/20/cppgc/internal/caged-heap-local-data.h +111 -0
  71. package/src/headers/20/cppgc/internal/caged-heap.h +61 -0
  72. package/src/headers/20/cppgc/internal/compiler-specific.h +38 -0
  73. package/src/headers/20/cppgc/internal/finalizer-trait.h +93 -0
  74. package/src/headers/20/cppgc/internal/gc-info.h +157 -0
  75. package/src/headers/20/cppgc/internal/logging.h +50 -0
  76. package/src/headers/20/cppgc/internal/member-storage.h +248 -0
  77. package/src/headers/20/cppgc/internal/name-trait.h +137 -0
  78. package/src/headers/20/cppgc/internal/persistent-node.h +214 -0
  79. package/src/headers/20/cppgc/internal/pointer-policies.h +243 -0
  80. package/src/headers/20/cppgc/internal/write-barrier.h +487 -0
  81. package/src/headers/20/cppgc/liveness-broker.h +78 -0
  82. package/src/headers/20/cppgc/macros.h +35 -0
  83. package/src/headers/20/cppgc/member.h +604 -0
  84. package/src/headers/20/cppgc/name-provider.h +65 -0
  85. package/src/headers/20/cppgc/object-size-trait.h +58 -0
  86. package/src/headers/20/cppgc/persistent.h +373 -0
  87. package/src/headers/20/cppgc/platform.h +158 -0
  88. package/src/headers/20/cppgc/prefinalizer.h +75 -0
  89. package/src/headers/20/cppgc/process-heap-statistics.h +36 -0
  90. package/src/headers/20/cppgc/sentinel-pointer.h +32 -0
  91. package/src/headers/20/cppgc/source-location.h +92 -0
  92. package/src/headers/20/cppgc/testing.h +106 -0
  93. package/src/headers/20/cppgc/trace-trait.h +120 -0
  94. package/src/headers/20/cppgc/type-traits.h +250 -0
  95. package/src/headers/20/cppgc/visitor.h +426 -0
  96. package/src/headers/20/crypto/crypto_clienthello.h +131 -0
  97. package/src/headers/20/crypto/crypto_context.h +160 -0
  98. package/src/headers/20/crypto/crypto_keys.h +416 -0
  99. package/src/headers/20/crypto/crypto_tls.h +295 -0
  100. package/src/headers/20/crypto/crypto_util.h +805 -0
  101. package/src/headers/20/crypto_clienthello.h +131 -0
  102. package/src/headers/20/debug_utils-inl.h +226 -0
  103. package/src/headers/20/debug_utils.h +188 -0
  104. package/src/headers/20/diagnosticfilename-inl.h +33 -0
  105. package/src/headers/20/encoding_binding.h +59 -0
  106. package/src/headers/20/env-inl.h +923 -0
  107. package/src/headers/20/env.h +1193 -0
  108. package/src/headers/20/env_properties.h +444 -0
  109. package/src/headers/20/handle_wrap.h +123 -0
  110. package/src/headers/20/histogram-inl.h +107 -0
  111. package/src/headers/20/histogram.h +240 -0
  112. package/src/headers/20/inspector_agent.h +144 -0
  113. package/src/headers/20/inspector_io.h +78 -0
  114. package/src/headers/20/inspector_profiler.h +149 -0
  115. package/src/headers/20/inspector_socket.h +60 -0
  116. package/src/headers/20/inspector_socket_server.h +110 -0
  117. package/src/headers/20/js_native_api.h +591 -0
  118. package/src/headers/20/js_native_api_types.h +168 -0
  119. package/src/headers/20/js_native_api_v8.h +426 -0
  120. package/src/headers/20/js_native_api_v8_internals.h +39 -0
  121. package/src/headers/20/js_stream.h +52 -0
  122. package/src/headers/20/json_parser.h +38 -0
  123. package/src/headers/20/json_utils.h +172 -0
  124. package/src/headers/20/memory_tracker-inl.h +356 -0
  125. package/src/headers/20/memory_tracker.h +289 -0
  126. package/src/headers/20/module_wrap.h +117 -0
  127. package/src/headers/20/node.h +1514 -0
  128. package/src/headers/20/node_api.h +260 -0
  129. package/src/headers/20/node_api_internals.h +42 -0
  130. package/src/headers/20/node_api_types.h +52 -0
  131. package/src/headers/20/node_binding.h +142 -0
  132. package/src/headers/20/node_blob.h +159 -0
  133. package/src/headers/20/node_bob-inl.h +36 -0
  134. package/src/headers/20/node_bob.h +107 -0
  135. package/src/headers/20/node_buffer.h +92 -0
  136. package/src/headers/20/node_builtins.h +197 -0
  137. package/src/headers/20/node_constants.h +79 -0
  138. package/src/headers/20/node_context_data.h +98 -0
  139. package/src/headers/20/node_contextify.h +182 -0
  140. package/src/headers/20/node_crypto.h +56 -0
  141. package/src/headers/20/node_dir.h +52 -0
  142. package/src/headers/20/node_dotenv.h +37 -0
  143. package/src/headers/20/node_errors.h +313 -0
  144. package/src/headers/20/node_exit_code.h +54 -0
  145. package/src/headers/20/node_external_reference.h +172 -0
  146. package/src/headers/20/node_file-inl.h +357 -0
  147. package/src/headers/20/node_file.h +524 -0
  148. package/src/headers/20/node_http2.h +1146 -0
  149. package/src/headers/20/node_http2_state.h +147 -0
  150. package/src/headers/20/node_http_common-inl.h +201 -0
  151. package/src/headers/20/node_http_common.h +532 -0
  152. package/src/headers/20/node_i18n.h +145 -0
  153. package/src/headers/20/node_internals.h +443 -0
  154. package/src/headers/20/node_main_instance.h +67 -0
  155. package/src/headers/20/node_mem-inl.h +112 -0
  156. package/src/headers/20/node_mem.h +45 -0
  157. package/src/headers/20/node_messaging.h +377 -0
  158. package/src/headers/20/node_metadata.h +138 -0
  159. package/src/headers/20/node_mutex.h +323 -0
  160. package/src/headers/20/node_object_wrap.h +132 -0
  161. package/src/headers/20/node_options-inl.h +478 -0
  162. package/src/headers/20/node_options.h +538 -0
  163. package/src/headers/20/node_perf.h +166 -0
  164. package/src/headers/20/node_perf_common.h +98 -0
  165. package/src/headers/20/node_platform.h +195 -0
  166. package/src/headers/20/node_process-inl.h +26 -0
  167. package/src/headers/20/node_process.h +99 -0
  168. package/src/headers/20/node_realm-inl.h +139 -0
  169. package/src/headers/20/node_realm.h +184 -0
  170. package/src/headers/20/node_report.h +42 -0
  171. package/src/headers/20/node_revert.h +82 -0
  172. package/src/headers/20/node_root_certs.h +3443 -0
  173. package/src/headers/20/node_sea.h +56 -0
  174. package/src/headers/20/node_shadow_realm.h +46 -0
  175. package/src/headers/20/node_snapshot_builder.h +54 -0
  176. package/src/headers/20/node_snapshotable.h +164 -0
  177. package/src/headers/20/node_sockaddr-inl.h +266 -0
  178. package/src/headers/20/node_sockaddr.h +405 -0
  179. package/src/headers/20/node_stat_watcher.h +73 -0
  180. package/src/headers/20/node_threadsafe_cow-inl.h +54 -0
  181. package/src/headers/20/node_threadsafe_cow.h +105 -0
  182. package/src/headers/20/node_union_bytes.h +81 -0
  183. package/src/headers/20/node_url.h +92 -0
  184. package/src/headers/20/node_v8.h +77 -0
  185. package/src/headers/20/node_v8_platform-inl.h +205 -0
  186. package/src/headers/20/node_version.h +109 -0
  187. package/src/headers/20/node_wasi.h +184 -0
  188. package/src/headers/20/node_wasm_web_api.h +55 -0
  189. package/src/headers/20/node_watchdog.h +154 -0
  190. package/src/headers/20/node_worker.h +151 -0
  191. package/src/headers/20/permission/child_process_permission.h +28 -0
  192. package/src/headers/20/permission/fs_permission.h +152 -0
  193. package/src/headers/20/permission/permission.h +71 -0
  194. package/src/headers/20/permission/permission_base.h +49 -0
  195. package/src/headers/20/permission/worker_permission.h +28 -0
  196. package/src/headers/20/pipe_wrap.h +80 -0
  197. package/src/headers/20/req_wrap-inl.h +171 -0
  198. package/src/headers/20/req_wrap.h +77 -0
  199. package/src/headers/20/spawn_sync.h +242 -0
  200. package/src/headers/20/stream_base-inl.h +173 -0
  201. package/src/headers/20/stream_base.h +469 -0
  202. package/src/headers/20/stream_pipe.h +76 -0
  203. package/src/headers/20/stream_wrap.h +131 -0
  204. package/src/headers/20/string_bytes.h +120 -0
  205. package/src/headers/20/string_decoder-inl.h +37 -0
  206. package/src/headers/20/string_decoder.h +50 -0
  207. package/src/headers/20/string_search.h +638 -0
  208. package/src/headers/20/tcp_wrap.h +105 -0
  209. package/src/headers/20/threadpoolwork-inl.h +70 -0
  210. package/src/headers/20/timer_wrap-inl.h +32 -0
  211. package/src/headers/20/timer_wrap.h +85 -0
  212. package/src/headers/20/timers.h +70 -0
  213. package/src/headers/20/tracing/agent.h +195 -0
  214. package/src/headers/20/tracing/trace_event.h +720 -0
  215. package/src/headers/20/tracing/trace_event_common.h +1109 -0
  216. package/src/headers/20/tty_wrap.h +65 -0
  217. package/src/headers/20/udp_wrap.h +227 -0
  218. package/src/headers/20/undici_version.h +6 -0
  219. package/src/headers/20/util-inl.h +623 -0
  220. package/src/headers/20/util.h +988 -0
  221. package/src/headers/20/v8-cppgc.h +245 -0
  222. package/src/headers/20/v8-fast-api-calls.h +957 -0
  223. package/dist/bindings/cws_darwin_arm64_node64.node +0 -0
  224. package/dist/bindings/cws_darwin_arm64_node72.node +0 -0
  225. package/dist/bindings/cws_darwin_arm64_node79.node +0 -0
  226. package/dist/bindings/cws_darwin_x64_node64.node +0 -0
  227. package/dist/bindings/cws_darwin_x64_node72.node +0 -0
  228. package/dist/bindings/cws_darwin_x64_node79.node +0 -0
  229. package/dist/bindings/cws_linux_x64_node64.node +0 -0
  230. package/dist/bindings/cws_linux_x64_node72.node +0 -0
  231. package/dist/bindings/cws_linux_x64_node79.node +0 -0
  232. package/dist/bindings/cws_win32_x64_node64.node +0 -0
  233. package/dist/bindings/cws_win32_x64_node72.node +0 -0
  234. package/dist/bindings/cws_win32_x64_node79.node +0 -0
@@ -0,0 +1,105 @@
1
+ // Copyright Joyent, Inc. and other Node contributors.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a
4
+ // copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ // persons to whom the Software is furnished to do so, subject to the
9
+ // following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included
12
+ // in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ #ifndef SRC_TCP_WRAP_H_
23
+ #define SRC_TCP_WRAP_H_
24
+
25
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
26
+
27
+ #include "async_wrap.h"
28
+ #include "connection_wrap.h"
29
+
30
+ namespace node {
31
+
32
+ class ExternalReferenceRegistry;
33
+ class Environment;
34
+
35
+ class TCPWrap : public ConnectionWrap<TCPWrap, uv_tcp_t> {
36
+ public:
37
+ enum SocketType {
38
+ SOCKET,
39
+ SERVER
40
+ };
41
+
42
+ static v8::MaybeLocal<v8::Object> Instantiate(Environment* env,
43
+ AsyncWrap* parent,
44
+ SocketType type);
45
+ static void Initialize(v8::Local<v8::Object> target,
46
+ v8::Local<v8::Value> unused,
47
+ v8::Local<v8::Context> context,
48
+ void* priv);
49
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
50
+
51
+ SET_NO_MEMORY_INFO()
52
+ SET_SELF_SIZE(TCPWrap)
53
+ const char* MemoryInfoName() const override {
54
+ switch (provider_type()) {
55
+ case ProviderType::PROVIDER_TCPWRAP:
56
+ return "TCPSocketWrap";
57
+ case ProviderType::PROVIDER_TCPSERVERWRAP:
58
+ return "TCPServerWrap";
59
+ default:
60
+ UNREACHABLE();
61
+ }
62
+ }
63
+
64
+ private:
65
+ typedef uv_tcp_t HandleType;
66
+
67
+ template <typename T,
68
+ int (*F)(const typename T::HandleType*, sockaddr*, int*)>
69
+ friend void GetSockOrPeerName(const v8::FunctionCallbackInfo<v8::Value>&);
70
+
71
+ TCPWrap(Environment* env, v8::Local<v8::Object> object,
72
+ ProviderType provider);
73
+
74
+ static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
75
+ static void SetNoDelay(const v8::FunctionCallbackInfo<v8::Value>& args);
76
+ static void SetKeepAlive(const v8::FunctionCallbackInfo<v8::Value>& args);
77
+ static void Bind(const v8::FunctionCallbackInfo<v8::Value>& args);
78
+ static void Bind6(const v8::FunctionCallbackInfo<v8::Value>& args);
79
+ static void Listen(const v8::FunctionCallbackInfo<v8::Value>& args);
80
+ static void Connect(const v8::FunctionCallbackInfo<v8::Value>& args);
81
+ static void Connect6(const v8::FunctionCallbackInfo<v8::Value>& args);
82
+ template <typename T>
83
+ static void Connect(const v8::FunctionCallbackInfo<v8::Value>& args,
84
+ std::function<int(const char* ip_address, T* addr)> uv_ip_addr);
85
+ static void Open(const v8::FunctionCallbackInfo<v8::Value>& args);
86
+ template <typename T>
87
+ static void Bind(
88
+ const v8::FunctionCallbackInfo<v8::Value>& args,
89
+ int family,
90
+ std::function<int(const char* ip_address, int port, T* addr)> uv_ip_addr);
91
+ static void Reset(const v8::FunctionCallbackInfo<v8::Value>& args);
92
+ int Reset(v8::Local<v8::Value> close_callback = v8::Local<v8::Value>());
93
+
94
+ #ifdef _WIN32
95
+ static void SetSimultaneousAccepts(
96
+ const v8::FunctionCallbackInfo<v8::Value>& args);
97
+ #endif
98
+ };
99
+
100
+
101
+ } // namespace node
102
+
103
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
104
+
105
+ #endif // SRC_TCP_WRAP_H_
@@ -0,0 +1,70 @@
1
+ // Copyright Joyent, Inc. and other Node contributors.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a
4
+ // copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ // persons to whom the Software is furnished to do so, subject to the
9
+ // following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included
12
+ // in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ #ifndef SRC_THREADPOOLWORK_INL_H_
23
+ #define SRC_THREADPOOLWORK_INL_H_
24
+
25
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
26
+
27
+ #include "node_internals.h"
28
+ #include "tracing/trace_event.h"
29
+ #include "util-inl.h"
30
+
31
+ namespace node {
32
+
33
+ void ThreadPoolWork::ScheduleWork() {
34
+ env_->IncreaseWaitingRequestCounter();
35
+ TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
36
+ TRACING_CATEGORY_NODE2(threadpoolwork, async), type_, this);
37
+ int status = uv_queue_work(
38
+ env_->event_loop(),
39
+ &work_req_,
40
+ [](uv_work_t* req) {
41
+ ThreadPoolWork* self = ContainerOf(&ThreadPoolWork::work_req_, req);
42
+ TRACE_EVENT_BEGIN0(TRACING_CATEGORY_NODE2(threadpoolwork, sync),
43
+ self->type_);
44
+ self->DoThreadPoolWork();
45
+ TRACE_EVENT_END0(TRACING_CATEGORY_NODE2(threadpoolwork, sync),
46
+ self->type_);
47
+ },
48
+ [](uv_work_t* req, int status) {
49
+ ThreadPoolWork* self = ContainerOf(&ThreadPoolWork::work_req_, req);
50
+ self->env_->DecreaseWaitingRequestCounter();
51
+ TRACE_EVENT_NESTABLE_ASYNC_END1(
52
+ TRACING_CATEGORY_NODE2(threadpoolwork, async),
53
+ self->type_,
54
+ self,
55
+ "result",
56
+ status);
57
+ self->AfterThreadPoolWork(status);
58
+ });
59
+ CHECK_EQ(status, 0);
60
+ }
61
+
62
+ int ThreadPoolWork::CancelWork() {
63
+ return uv_cancel(reinterpret_cast<uv_req_t*>(&work_req_));
64
+ }
65
+
66
+ } // namespace node
67
+
68
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
69
+
70
+ #endif // SRC_THREADPOOLWORK_INL_H_
@@ -0,0 +1,32 @@
1
+ #ifndef SRC_TIMER_WRAP_INL_H_
2
+ #define SRC_TIMER_WRAP_INL_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "timer_wrap.h"
7
+
8
+ #include <utility>
9
+
10
+ #include "env.h"
11
+ #include "uv.h"
12
+
13
+ namespace node {
14
+
15
+ template <typename... Args>
16
+ inline TimerWrap::TimerWrap(Environment* env, Args&&... args)
17
+ : env_(env), fn_(std::forward<Args>(args)...) {
18
+ uv_timer_init(env->event_loop(), &timer_);
19
+ timer_.data = this;
20
+ }
21
+
22
+ template <typename... Args>
23
+ inline TimerWrapHandle::TimerWrapHandle(Environment* env, Args&&... args) {
24
+ timer_ = new TimerWrap(env, std::forward<Args>(args)...);
25
+ env->AddCleanupHook(CleanupHook, this);
26
+ }
27
+
28
+ } // namespace node
29
+
30
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
31
+
32
+ #endif // SRC_TIMER_WRAP_INL_H_
@@ -0,0 +1,85 @@
1
+ #ifndef SRC_TIMER_WRAP_H_
2
+ #define SRC_TIMER_WRAP_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "memory_tracker.h"
7
+ #include "env.h"
8
+ #include "uv.h"
9
+
10
+ #include <functional>
11
+
12
+ namespace node {
13
+
14
+ // Utility class that makes working with libuv timers a bit easier.
15
+ class TimerWrap final : public MemoryRetainer {
16
+ public:
17
+ using TimerCb = std::function<void()>;
18
+
19
+ template <typename... Args>
20
+ explicit inline TimerWrap(Environment* env, Args&&... args);
21
+
22
+ TimerWrap(const TimerWrap&) = delete;
23
+
24
+ inline Environment* env() const { return env_; }
25
+
26
+ // Stop calling the timer callback.
27
+ void Stop();
28
+ // Render the timer unusable and delete this object.
29
+ void Close();
30
+
31
+ // Starts / Restarts the Timer
32
+ void Update(uint64_t interval, uint64_t repeat = 0);
33
+
34
+ void Ref();
35
+ void Unref();
36
+
37
+ SET_NO_MEMORY_INFO()
38
+ SET_MEMORY_INFO_NAME(TimerWrap)
39
+ SET_SELF_SIZE(TimerWrap)
40
+
41
+ private:
42
+ static void TimerClosedCb(uv_handle_t* handle);
43
+ static void OnTimeout(uv_timer_t* timer);
44
+ ~TimerWrap() = default;
45
+
46
+ Environment* env_;
47
+ TimerCb fn_;
48
+ uv_timer_t timer_;
49
+
50
+ friend std::unique_ptr<TimerWrap>::deleter_type;
51
+ };
52
+
53
+ class TimerWrapHandle : public MemoryRetainer {
54
+ public:
55
+ template <typename... Args>
56
+ explicit inline TimerWrapHandle(Environment* env, Args&&... args);
57
+
58
+ TimerWrapHandle(const TimerWrapHandle&) = delete;
59
+
60
+ ~TimerWrapHandle() { Close(); }
61
+
62
+ void Update(uint64_t interval, uint64_t repeat = 0);
63
+
64
+ void Ref();
65
+ void Unref();
66
+
67
+ void Stop();
68
+ void Close();
69
+
70
+ void MemoryInfo(node::MemoryTracker* tracker) const override;
71
+
72
+ SET_MEMORY_INFO_NAME(TimerWrapHandle)
73
+ SET_SELF_SIZE(TimerWrapHandle)
74
+
75
+ private:
76
+ static void CleanupHook(void* data);
77
+
78
+ TimerWrap* timer_;
79
+ };
80
+
81
+ } // namespace node
82
+
83
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
84
+
85
+ #endif // SRC_TIMER_WRAP_H_
@@ -0,0 +1,70 @@
1
+ #ifndef SRC_TIMERS_H_
2
+ #define SRC_TIMERS_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include <cinttypes>
7
+ #include "node_snapshotable.h"
8
+
9
+ namespace node {
10
+ class ExternalReferenceRegistry;
11
+
12
+ namespace timers {
13
+ class BindingData : public SnapshotableObject {
14
+ public:
15
+ BindingData(Realm* env, v8::Local<v8::Object> obj);
16
+
17
+ using InternalFieldInfo = InternalFieldInfoBase;
18
+
19
+ SET_BINDING_ID(timers_binding_data)
20
+ SERIALIZABLE_OBJECT_METHODS()
21
+
22
+ SET_NO_MEMORY_INFO()
23
+ SET_SELF_SIZE(BindingData)
24
+ SET_MEMORY_INFO_NAME(BindingData)
25
+
26
+ static void SetupTimers(const v8::FunctionCallbackInfo<v8::Value>& args);
27
+
28
+ static void SlowGetLibuvNow(const v8::FunctionCallbackInfo<v8::Value>& args);
29
+ static double FastGetLibuvNow(v8::Local<v8::Object> receiver);
30
+ static double GetLibuvNowImpl(BindingData* data);
31
+
32
+ static void SlowScheduleTimer(
33
+ const v8::FunctionCallbackInfo<v8::Value>& args);
34
+ static void FastScheduleTimer(v8::Local<v8::Object> receiver,
35
+ int64_t duration);
36
+ static void ScheduleTimerImpl(BindingData* data, int64_t duration);
37
+
38
+ static void SlowToggleTimerRef(
39
+ const v8::FunctionCallbackInfo<v8::Value>& args);
40
+ static void FastToggleTimerRef(v8::Local<v8::Object> receiver, bool ref);
41
+ static void ToggleTimerRefImpl(BindingData* data, bool ref);
42
+
43
+ static void SlowToggleImmediateRef(
44
+ const v8::FunctionCallbackInfo<v8::Value>& args);
45
+ static void FastToggleImmediateRef(v8::Local<v8::Object> receiver, bool ref);
46
+ static void ToggleImmediateRefImpl(BindingData* data, bool ref);
47
+
48
+ static void CreatePerIsolateProperties(IsolateData* isolate_data,
49
+ v8::Local<v8::ObjectTemplate> target);
50
+ static void CreatePerContextProperties(v8::Local<v8::Object> target,
51
+ v8::Local<v8::Value> unused,
52
+ v8::Local<v8::Context> context,
53
+ void* priv);
54
+ static void RegisterTimerExternalReferences(
55
+ ExternalReferenceRegistry* registry);
56
+
57
+ private:
58
+ static v8::CFunction fast_get_libuv_now_;
59
+ static v8::CFunction fast_schedule_timers_;
60
+ static v8::CFunction fast_toggle_timer_ref_;
61
+ static v8::CFunction fast_toggle_immediate_ref_;
62
+ };
63
+
64
+ } // namespace timers
65
+
66
+ } // namespace node
67
+
68
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
69
+
70
+ #endif // SRC_TIMERS_H_
@@ -0,0 +1,195 @@
1
+ #ifndef SRC_TRACING_AGENT_H_
2
+ #define SRC_TRACING_AGENT_H_
3
+
4
+ #include "libplatform/v8-tracing.h"
5
+ #include "uv.h"
6
+ #include "util.h"
7
+ #include "node_mutex.h"
8
+
9
+ #include <list>
10
+ #include <set>
11
+ #include <string>
12
+ #include <unordered_map>
13
+
14
+ namespace v8 {
15
+ class ConvertableToTraceFormat;
16
+ class TracingController;
17
+ } // namespace v8
18
+
19
+ namespace node {
20
+ namespace tracing {
21
+
22
+ using v8::platform::tracing::TraceConfig;
23
+ using v8::platform::tracing::TraceObject;
24
+
25
+ class Agent;
26
+
27
+ class AsyncTraceWriter {
28
+ public:
29
+ virtual ~AsyncTraceWriter() = default;
30
+ virtual void AppendTraceEvent(TraceObject* trace_event) = 0;
31
+ virtual void Flush(bool blocking) = 0;
32
+ virtual void InitializeOnThread(uv_loop_t* loop) {}
33
+ };
34
+
35
+ class TracingController : public v8::platform::tracing::TracingController {
36
+ public:
37
+ TracingController() : v8::platform::tracing::TracingController() {}
38
+
39
+ int64_t CurrentTimestampMicroseconds() override {
40
+ return uv_hrtime() / 1000;
41
+ }
42
+ void AddMetadataEvent(
43
+ const unsigned char* category_group_enabled,
44
+ const char* name,
45
+ int num_args,
46
+ const char** arg_names,
47
+ const unsigned char* arg_types,
48
+ const uint64_t* arg_values,
49
+ std::unique_ptr<v8::ConvertableToTraceFormat>* convertable_values,
50
+ unsigned int flags);
51
+ };
52
+
53
+ class AgentWriterHandle {
54
+ public:
55
+ inline AgentWriterHandle() = default;
56
+ inline ~AgentWriterHandle() { reset(); }
57
+
58
+ inline AgentWriterHandle(AgentWriterHandle&& other);
59
+ inline AgentWriterHandle& operator=(AgentWriterHandle&& other);
60
+ inline bool empty() const { return agent_ == nullptr; }
61
+ inline void reset();
62
+
63
+ inline void Enable(const std::set<std::string>& categories);
64
+ inline void Disable(const std::set<std::string>& categories);
65
+
66
+ inline bool IsDefaultHandle();
67
+
68
+ inline Agent* agent() { return agent_; }
69
+
70
+ inline v8::TracingController* GetTracingController();
71
+
72
+ AgentWriterHandle(const AgentWriterHandle& other) = delete;
73
+ AgentWriterHandle& operator=(const AgentWriterHandle& other) = delete;
74
+
75
+ private:
76
+ inline AgentWriterHandle(Agent* agent, int id) : agent_(agent), id_(id) {}
77
+
78
+ Agent* agent_ = nullptr;
79
+ int id_ = 0;
80
+
81
+ friend class Agent;
82
+ };
83
+
84
+ class Agent {
85
+ public:
86
+ Agent();
87
+ ~Agent();
88
+
89
+ TracingController* GetTracingController() {
90
+ TracingController* controller = tracing_controller_.get();
91
+ CHECK_NOT_NULL(controller);
92
+ return controller;
93
+ }
94
+
95
+ enum UseDefaultCategoryMode {
96
+ kUseDefaultCategories,
97
+ kIgnoreDefaultCategories
98
+ };
99
+
100
+ // Destroying the handle disconnects the client
101
+ AgentWriterHandle AddClient(const std::set<std::string>& categories,
102
+ std::unique_ptr<AsyncTraceWriter> writer,
103
+ enum UseDefaultCategoryMode mode);
104
+ // A handle that is only used for managing the default categories
105
+ // (which can then implicitly be used through using `USE_DEFAULT_CATEGORIES`
106
+ // when adding a client later).
107
+ AgentWriterHandle DefaultHandle();
108
+
109
+ // Returns a comma-separated list of enabled categories.
110
+ std::string GetEnabledCategories() const;
111
+
112
+ // Writes to all writers registered through AddClient().
113
+ void AppendTraceEvent(TraceObject* trace_event);
114
+
115
+ void AddMetadataEvent(std::unique_ptr<TraceObject> event);
116
+ // Flushes all writers registered through AddClient().
117
+ void Flush(bool blocking);
118
+
119
+ TraceConfig* CreateTraceConfig() const;
120
+
121
+ private:
122
+ friend class AgentWriterHandle;
123
+
124
+ void InitializeWritersOnThread();
125
+
126
+ void Start();
127
+ void StopTracing();
128
+ void Disconnect(int client);
129
+
130
+ void Enable(int id, const std::set<std::string>& categories);
131
+ void Disable(int id, const std::set<std::string>& categories);
132
+
133
+ uv_thread_t thread_;
134
+ uv_loop_t tracing_loop_;
135
+
136
+ bool started_ = false;
137
+ class ScopedSuspendTracing;
138
+
139
+ // Each individual Writer has one id.
140
+ int next_writer_id_ = 1;
141
+ enum { kDefaultHandleId = -1 };
142
+ // These maps store the original arguments to AddClient(), by id.
143
+ std::unordered_map<int, std::multiset<std::string>> categories_;
144
+ std::unordered_map<int, std::unique_ptr<AsyncTraceWriter>> writers_;
145
+ std::unique_ptr<TracingController> tracing_controller_;
146
+
147
+ // Variables related to initializing per-event-loop properties of individual
148
+ // writers, such as libuv handles.
149
+ Mutex initialize_writer_mutex_;
150
+ ConditionVariable initialize_writer_condvar_;
151
+ uv_async_t initialize_writer_async_;
152
+ std::set<AsyncTraceWriter*> to_be_initialized_;
153
+
154
+ Mutex metadata_events_mutex_;
155
+ std::list<std::unique_ptr<TraceObject>> metadata_events_;
156
+ };
157
+
158
+ void AgentWriterHandle::reset() {
159
+ if (agent_ != nullptr)
160
+ agent_->Disconnect(id_);
161
+ agent_ = nullptr;
162
+ }
163
+
164
+ AgentWriterHandle& AgentWriterHandle::operator=(AgentWriterHandle&& other) {
165
+ reset();
166
+ agent_ = other.agent_;
167
+ id_ = other.id_;
168
+ other.agent_ = nullptr;
169
+ return *this;
170
+ }
171
+
172
+ AgentWriterHandle::AgentWriterHandle(AgentWriterHandle&& other) {
173
+ *this = std::move(other);
174
+ }
175
+
176
+ void AgentWriterHandle::Enable(const std::set<std::string>& categories) {
177
+ if (agent_ != nullptr) agent_->Enable(id_, categories);
178
+ }
179
+
180
+ void AgentWriterHandle::Disable(const std::set<std::string>& categories) {
181
+ if (agent_ != nullptr) agent_->Disable(id_, categories);
182
+ }
183
+
184
+ bool AgentWriterHandle::IsDefaultHandle() {
185
+ return agent_ != nullptr && id_ == Agent::kDefaultHandleId;
186
+ }
187
+
188
+ inline v8::TracingController* AgentWriterHandle::GetTracingController() {
189
+ return agent_ != nullptr ? agent_->GetTracingController() : nullptr;
190
+ }
191
+
192
+ } // namespace tracing
193
+ } // namespace node
194
+
195
+ #endif // SRC_TRACING_AGENT_H_