@encharm/cws 4.3.0 → 4.4.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 (238) 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 +67 -91
  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 +30 -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 +419 -0
  99. package/src/headers/20/crypto/crypto_tls.h +304 -0
  100. package/src/headers/20/crypto/crypto_util.h +806 -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 +446 -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 +601 -0
  118. package/src/headers/20/js_native_api_types.h +168 -0
  119. package/src/headers/20/js_native_api_v8.h +463 -0
  120. package/src/headers/20/js_native_api_v8_internals.h +45 -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 +1516 -0
  128. package/src/headers/20/node_api.h +261 -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 +82 -0
  138. package/src/headers/20/node_context_data.h +98 -0
  139. package/src/headers/20/node_contextify.h +206 -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 +389 -0
  147. package/src/headers/20/node_file.h +537 -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 +29 -0
  192. package/src/headers/20/permission/fs_permission.h +154 -0
  193. package/src/headers/20/permission/inspector_permission.h +29 -0
  194. package/src/headers/20/permission/permission.h +74 -0
  195. package/src/headers/20/permission/permission_base.h +53 -0
  196. package/src/headers/20/permission/worker_permission.h +29 -0
  197. package/src/headers/20/pipe_wrap.h +80 -0
  198. package/src/headers/20/req_wrap-inl.h +171 -0
  199. package/src/headers/20/req_wrap.h +77 -0
  200. package/src/headers/20/spawn_sync.h +242 -0
  201. package/src/headers/20/stream_base-inl.h +173 -0
  202. package/src/headers/20/stream_base.h +469 -0
  203. package/src/headers/20/stream_pipe.h +76 -0
  204. package/src/headers/20/stream_wrap.h +131 -0
  205. package/src/headers/20/string_bytes.h +120 -0
  206. package/src/headers/20/string_decoder-inl.h +37 -0
  207. package/src/headers/20/string_decoder.h +50 -0
  208. package/src/headers/20/string_search.h +638 -0
  209. package/src/headers/20/tcp_wrap.h +105 -0
  210. package/src/headers/20/threadpoolwork-inl.h +70 -0
  211. package/src/headers/20/timer_wrap-inl.h +32 -0
  212. package/src/headers/20/timer_wrap.h +85 -0
  213. package/src/headers/20/timers.h +70 -0
  214. package/src/headers/20/tracing/agent.h +195 -0
  215. package/src/headers/20/tracing/node_trace_buffer.h +83 -0
  216. package/src/headers/20/tracing/node_trace_writer.h +75 -0
  217. package/src/headers/20/tracing/trace_event.h +720 -0
  218. package/src/headers/20/tracing/trace_event_common.h +1109 -0
  219. package/src/headers/20/tracing/traced_value.h +70 -0
  220. package/src/headers/20/tty_wrap.h +65 -0
  221. package/src/headers/20/udp_wrap.h +227 -0
  222. package/src/headers/20/undici_version.h +6 -0
  223. package/src/headers/20/util-inl.h +623 -0
  224. package/src/headers/20/util.h +988 -0
  225. package/src/headers/20/v8-cppgc.h +245 -0
  226. package/src/headers/20/v8-fast-api-calls.h +957 -0
  227. package/dist/bindings/cws_darwin_arm64_node64.node +0 -0
  228. package/dist/bindings/cws_darwin_arm64_node72.node +0 -0
  229. package/dist/bindings/cws_darwin_arm64_node79.node +0 -0
  230. package/dist/bindings/cws_darwin_x64_node64.node +0 -0
  231. package/dist/bindings/cws_darwin_x64_node72.node +0 -0
  232. package/dist/bindings/cws_darwin_x64_node79.node +0 -0
  233. package/dist/bindings/cws_linux_x64_node64.node +0 -0
  234. package/dist/bindings/cws_linux_x64_node72.node +0 -0
  235. package/dist/bindings/cws_linux_x64_node79.node +0 -0
  236. package/dist/bindings/cws_win32_x64_node64.node +0 -0
  237. package/dist/bindings/cws_win32_x64_node72.node +0 -0
  238. package/dist/bindings/cws_win32_x64_node79.node +0 -0
@@ -0,0 +1,79 @@
1
+ #ifndef SRC_CALLBACK_QUEUE_H_
2
+ #define SRC_CALLBACK_QUEUE_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include <atomic>
7
+ #include <memory>
8
+
9
+ namespace node {
10
+
11
+ namespace CallbackFlags {
12
+ enum Flags {
13
+ kUnrefed = 0,
14
+ kRefed = 1,
15
+ };
16
+ }
17
+
18
+ // A queue of C++ functions that take Args... as arguments and return R
19
+ // (this is similar to the signature of std::function).
20
+ // New entries are added using `CreateCallback()`/`Push()`, and removed using
21
+ // `Shift()`.
22
+ // The `refed` flag is left for easier use in situations in which some of these
23
+ // should be run even if nothing else is keeping the event loop alive.
24
+ template <typename R, typename... Args>
25
+ class CallbackQueue {
26
+ public:
27
+ class Callback {
28
+ public:
29
+ explicit inline Callback(CallbackFlags::Flags flags);
30
+
31
+ virtual ~Callback() = default;
32
+ virtual R Call(Args... args) = 0;
33
+
34
+ inline CallbackFlags::Flags flags() const;
35
+
36
+ private:
37
+ inline std::unique_ptr<Callback> get_next();
38
+ inline void set_next(std::unique_ptr<Callback> next);
39
+
40
+ CallbackFlags::Flags flags_;
41
+ std::unique_ptr<Callback> next_;
42
+
43
+ friend class CallbackQueue;
44
+ };
45
+
46
+ template <typename Fn>
47
+ inline std::unique_ptr<Callback> CreateCallback(
48
+ Fn&& fn, CallbackFlags::Flags);
49
+
50
+ inline std::unique_ptr<Callback> Shift();
51
+ inline void Push(std::unique_ptr<Callback> cb);
52
+ // ConcatMove adds elements from 'other' to the end of this list, and clears
53
+ // 'other' afterwards.
54
+ inline void ConcatMove(CallbackQueue&& other);
55
+
56
+ // size() is atomic and may be called from any thread.
57
+ inline size_t size() const;
58
+
59
+ private:
60
+ template <typename Fn>
61
+ class CallbackImpl final : public Callback {
62
+ public:
63
+ CallbackImpl(Fn&& callback, CallbackFlags::Flags flags);
64
+ R Call(Args... args) override;
65
+
66
+ private:
67
+ Fn callback_;
68
+ };
69
+
70
+ std::atomic<size_t> size_ {0};
71
+ std::unique_ptr<Callback> head_;
72
+ Callback* tail_ = nullptr;
73
+ };
74
+
75
+ } // namespace node
76
+
77
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
78
+
79
+ #endif // SRC_CALLBACK_QUEUE_H_
@@ -0,0 +1,524 @@
1
+ #ifndef SRC_CARES_WRAP_H_
2
+ #define SRC_CARES_WRAP_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #define CARES_STATICLIB
7
+
8
+ #include "async_wrap.h"
9
+ #include "base_object.h"
10
+ #include "env.h"
11
+ #include "memory_tracker.h"
12
+ #include "node.h"
13
+ #include "node_internals.h"
14
+ #include "util.h"
15
+
16
+ #include "ares.h"
17
+ #include "v8.h"
18
+ #include "uv.h"
19
+
20
+ #include <unordered_set>
21
+
22
+ #ifdef __POSIX__
23
+ # include <netdb.h>
24
+ #endif // __POSIX__
25
+
26
+ # include <ares_nameser.h>
27
+
28
+ namespace node {
29
+ namespace cares_wrap {
30
+
31
+ constexpr int ns_t_cname_or_a = -1;
32
+ constexpr int DNS_ESETSRVPENDING = -1000;
33
+
34
+ class ChannelWrap;
35
+
36
+ inline void safe_free_hostent(struct hostent* host);
37
+
38
+ using HostEntPointer = DeleteFnPtr<hostent, ares_free_hostent>;
39
+ using SafeHostEntPointer = DeleteFnPtr<hostent, safe_free_hostent>;
40
+
41
+ inline const char* ToErrorCodeString(int status) {
42
+ switch (status) {
43
+ #define V(code) case ARES_##code: return #code;
44
+ V(EADDRGETNETWORKPARAMS)
45
+ V(EBADFAMILY)
46
+ V(EBADFLAGS)
47
+ V(EBADHINTS)
48
+ V(EBADNAME)
49
+ V(EBADQUERY)
50
+ V(EBADRESP)
51
+ V(EBADSTR)
52
+ V(ECANCELLED)
53
+ V(ECONNREFUSED)
54
+ V(EDESTRUCTION)
55
+ V(EFILE)
56
+ V(EFORMERR)
57
+ V(ELOADIPHLPAPI)
58
+ V(ENODATA)
59
+ V(ENOMEM)
60
+ V(ENONAME)
61
+ V(ENOTFOUND)
62
+ V(ENOTIMP)
63
+ V(ENOTINITIALIZED)
64
+ V(EOF)
65
+ V(EREFUSED)
66
+ V(ESERVFAIL)
67
+ V(ETIMEOUT)
68
+ #undef V
69
+ }
70
+
71
+ return "UNKNOWN_ARES_ERROR";
72
+ }
73
+
74
+ inline void cares_wrap_hostent_cpy(
75
+ struct hostent* dest,
76
+ const struct hostent* src) {
77
+ dest->h_addr_list = nullptr;
78
+ dest->h_addrtype = 0;
79
+ dest->h_aliases = nullptr;
80
+ dest->h_length = 0;
81
+ dest->h_name = nullptr;
82
+
83
+ /* copy `h_name` */
84
+ size_t name_size = strlen(src->h_name) + 1;
85
+ dest->h_name = node::Malloc<char>(name_size);
86
+ memcpy(dest->h_name, src->h_name, name_size);
87
+
88
+ /* copy `h_aliases` */
89
+ size_t alias_count;
90
+ for (alias_count = 0;
91
+ src->h_aliases[alias_count] != nullptr;
92
+ alias_count++) {
93
+ }
94
+
95
+ dest->h_aliases = node::Malloc<char*>(alias_count + 1);
96
+ for (size_t i = 0; i < alias_count; i++) {
97
+ const size_t cur_alias_size = strlen(src->h_aliases[i]) + 1;
98
+ dest->h_aliases[i] = node::Malloc(cur_alias_size);
99
+ memcpy(dest->h_aliases[i], src->h_aliases[i], cur_alias_size);
100
+ }
101
+ dest->h_aliases[alias_count] = nullptr;
102
+
103
+ /* copy `h_addr_list` */
104
+ size_t list_count;
105
+ for (list_count = 0;
106
+ src->h_addr_list[list_count] != nullptr;
107
+ list_count++) {
108
+ }
109
+
110
+ dest->h_addr_list = node::Malloc<char*>(list_count + 1);
111
+ for (size_t i = 0; i < list_count; i++) {
112
+ dest->h_addr_list[i] = node::Malloc(src->h_length);
113
+ memcpy(dest->h_addr_list[i], src->h_addr_list[i], src->h_length);
114
+ }
115
+ dest->h_addr_list[list_count] = nullptr;
116
+
117
+ /* work after work */
118
+ dest->h_length = src->h_length;
119
+ dest->h_addrtype = src->h_addrtype;
120
+ }
121
+
122
+
123
+ struct NodeAresTask final : public MemoryRetainer {
124
+ ChannelWrap* channel;
125
+ ares_socket_t sock;
126
+ uv_poll_t poll_watcher;
127
+
128
+ inline void MemoryInfo(MemoryTracker* trakcer) const override;
129
+ SET_MEMORY_INFO_NAME(NodeAresTask)
130
+ SET_SELF_SIZE(NodeAresTask)
131
+
132
+ struct Hash {
133
+ inline size_t operator()(NodeAresTask* a) const {
134
+ return std::hash<ares_socket_t>()(a->sock);
135
+ }
136
+ };
137
+
138
+ struct Equal {
139
+ inline bool operator()(NodeAresTask* a, NodeAresTask* b) const {
140
+ return a->sock == b->sock;
141
+ }
142
+ };
143
+
144
+ static NodeAresTask* Create(ChannelWrap* channel, ares_socket_t sock);
145
+
146
+ using List = std::unordered_set<NodeAresTask*, Hash, Equal>;
147
+ };
148
+
149
+ class ChannelWrap final : public AsyncWrap {
150
+ public:
151
+ ChannelWrap(
152
+ Environment* env,
153
+ v8::Local<v8::Object> object,
154
+ int timeout,
155
+ int tries);
156
+ ~ChannelWrap() override;
157
+
158
+ static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
159
+
160
+ void Setup();
161
+ void EnsureServers();
162
+ void StartTimer();
163
+ void CloseTimer();
164
+
165
+ void ModifyActivityQueryCount(int count);
166
+
167
+ inline uv_timer_t* timer_handle() { return timer_handle_; }
168
+ inline ares_channel cares_channel() { return channel_; }
169
+ inline void set_query_last_ok(bool ok) { query_last_ok_ = ok; }
170
+ inline void set_is_servers_default(bool is_default) {
171
+ is_servers_default_ = is_default;
172
+ }
173
+ inline int active_query_count() { return active_query_count_; }
174
+ inline NodeAresTask::List* task_list() { return &task_list_; }
175
+
176
+ void MemoryInfo(MemoryTracker* tracker) const override;
177
+ SET_MEMORY_INFO_NAME(ChannelWrap)
178
+ SET_SELF_SIZE(ChannelWrap)
179
+
180
+ static void AresTimeout(uv_timer_t* handle);
181
+
182
+ private:
183
+ uv_timer_t* timer_handle_ = nullptr;
184
+ ares_channel channel_ = nullptr;
185
+ bool query_last_ok_ = true;
186
+ bool is_servers_default_ = true;
187
+ bool library_inited_ = false;
188
+ int timeout_;
189
+ int tries_;
190
+ int active_query_count_ = 0;
191
+ NodeAresTask::List task_list_;
192
+ };
193
+
194
+ class GetAddrInfoReqWrap final : public ReqWrap<uv_getaddrinfo_t> {
195
+ public:
196
+ GetAddrInfoReqWrap(Environment* env,
197
+ v8::Local<v8::Object> req_wrap_obj,
198
+ bool verbatim);
199
+
200
+ SET_NO_MEMORY_INFO()
201
+ SET_MEMORY_INFO_NAME(GetAddrInfoReqWrap)
202
+ SET_SELF_SIZE(GetAddrInfoReqWrap)
203
+
204
+ bool verbatim() const { return verbatim_; }
205
+
206
+ private:
207
+ const bool verbatim_;
208
+ };
209
+
210
+ class GetNameInfoReqWrap final : public ReqWrap<uv_getnameinfo_t> {
211
+ public:
212
+ GetNameInfoReqWrap(Environment* env, v8::Local<v8::Object> req_wrap_obj);
213
+
214
+ SET_NO_MEMORY_INFO()
215
+ SET_MEMORY_INFO_NAME(GetNameInfoReqWrap)
216
+ SET_SELF_SIZE(GetNameInfoReqWrap)
217
+ };
218
+
219
+ struct ResponseData final {
220
+ int status;
221
+ bool is_host;
222
+ SafeHostEntPointer host;
223
+ MallocedBuffer<unsigned char> buf;
224
+ };
225
+
226
+ template <typename Traits>
227
+ class QueryWrap final : public AsyncWrap {
228
+ public:
229
+ QueryWrap(ChannelWrap* channel, v8::Local<v8::Object> req_wrap_obj)
230
+ : AsyncWrap(channel->env(), req_wrap_obj, AsyncWrap::PROVIDER_QUERYWRAP),
231
+ channel_(channel),
232
+ trace_name_(Traits::name) {}
233
+
234
+ ~QueryWrap() {
235
+ CHECK_EQ(false, persistent().IsEmpty());
236
+
237
+ // Let Callback() know that this object no longer exists.
238
+ if (callback_ptr_ != nullptr)
239
+ *callback_ptr_ = nullptr;
240
+ }
241
+
242
+ int Send(const char* name) {
243
+ return Traits::Send(this, name);
244
+ }
245
+
246
+ void AresQuery(const char* name, int dnsclass, int type) {
247
+ channel_->EnsureServers();
248
+ TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(
249
+ TRACING_CATEGORY_NODE2(dns, native), trace_name_, this,
250
+ "name", TRACE_STR_COPY(name));
251
+ ares_query(
252
+ channel_->cares_channel(),
253
+ name,
254
+ dnsclass,
255
+ type,
256
+ Callback,
257
+ MakeCallbackPointer());
258
+ }
259
+
260
+ void ParseError(int status) {
261
+ CHECK_NE(status, ARES_SUCCESS);
262
+ v8::HandleScope handle_scope(env()->isolate());
263
+ v8::Context::Scope context_scope(env()->context());
264
+ const char* code = ToErrorCodeString(status);
265
+ v8::Local<v8::Value> arg = OneByteString(env()->isolate(), code);
266
+ TRACE_EVENT_NESTABLE_ASYNC_END1(
267
+ TRACING_CATEGORY_NODE2(dns, native), trace_name_, this,
268
+ "error", status);
269
+ MakeCallback(env()->oncomplete_string(), 1, &arg);
270
+ }
271
+
272
+ const BaseObjectPtr<ChannelWrap>& channel() const { return channel_; }
273
+
274
+ void AfterResponse() {
275
+ CHECK(response_data_);
276
+
277
+ int status = response_data_->status;
278
+
279
+ if (status != ARES_SUCCESS)
280
+ return ParseError(status);
281
+
282
+ status = Traits::Parse(this, response_data_);
283
+
284
+ if (status != ARES_SUCCESS)
285
+ ParseError(status);
286
+ }
287
+
288
+ void* MakeCallbackPointer() {
289
+ CHECK_NULL(callback_ptr_);
290
+ callback_ptr_ = new QueryWrap<Traits>*(this);
291
+ return callback_ptr_;
292
+ }
293
+
294
+ static QueryWrap<Traits>* FromCallbackPointer(void* arg) {
295
+ std::unique_ptr<QueryWrap<Traits>*> wrap_ptr {
296
+ static_cast<QueryWrap<Traits>**>(arg)
297
+ };
298
+ QueryWrap<Traits>* wrap = *wrap_ptr.get();
299
+ if (wrap == nullptr) return nullptr;
300
+ wrap->callback_ptr_ = nullptr;
301
+ return wrap;
302
+ }
303
+
304
+ static void Callback(
305
+ void* arg,
306
+ int status,
307
+ int timeouts,
308
+ unsigned char* answer_buf,
309
+ int answer_len) {
310
+ QueryWrap<Traits>* wrap = FromCallbackPointer(arg);
311
+ if (wrap == nullptr) return;
312
+
313
+ unsigned char* buf_copy = nullptr;
314
+ if (status == ARES_SUCCESS) {
315
+ buf_copy = node::Malloc<unsigned char>(answer_len);
316
+ memcpy(buf_copy, answer_buf, answer_len);
317
+ }
318
+
319
+ wrap->response_data_ = std::make_unique<ResponseData>();
320
+ ResponseData* data = wrap->response_data_.get();
321
+ data->status = status;
322
+ data->is_host = false;
323
+ data->buf = MallocedBuffer<unsigned char>(buf_copy, answer_len);
324
+
325
+ wrap->QueueResponseCallback(status);
326
+ }
327
+
328
+ static void Callback(
329
+ void* arg,
330
+ int status,
331
+ int timeouts,
332
+ struct hostent* host) {
333
+ QueryWrap<Traits>* wrap = FromCallbackPointer(arg);
334
+ if (wrap == nullptr) return;
335
+
336
+ struct hostent* host_copy = nullptr;
337
+ if (status == ARES_SUCCESS) {
338
+ host_copy = node::Malloc<hostent>(1);
339
+ cares_wrap_hostent_cpy(host_copy, host);
340
+ }
341
+
342
+ wrap->response_data_ = std::make_unique<ResponseData>();
343
+ ResponseData* data = wrap->response_data_.get();
344
+ data->status = status;
345
+ data->host.reset(host_copy);
346
+ data->is_host = true;
347
+
348
+ wrap->QueueResponseCallback(status);
349
+ }
350
+
351
+ void QueueResponseCallback(int status) {
352
+ BaseObjectPtr<QueryWrap<Traits>> strong_ref{this};
353
+ env()->SetImmediate([this, strong_ref](Environment*) {
354
+ AfterResponse();
355
+
356
+ // Delete once strong_ref goes out of scope.
357
+ Detach();
358
+ });
359
+
360
+ channel_->set_query_last_ok(status != ARES_ECONNREFUSED);
361
+ channel_->ModifyActivityQueryCount(-1);
362
+ }
363
+
364
+ void CallOnComplete(
365
+ v8::Local<v8::Value> answer,
366
+ v8::Local<v8::Value> extra = v8::Local<v8::Value>()) {
367
+ v8::HandleScope handle_scope(env()->isolate());
368
+ v8::Context::Scope context_scope(env()->context());
369
+ v8::Local<v8::Value> argv[] = {
370
+ v8::Integer::New(env()->isolate(), 0),
371
+ answer,
372
+ extra
373
+ };
374
+ const int argc = arraysize(argv) - extra.IsEmpty();
375
+ TRACE_EVENT_NESTABLE_ASYNC_END0(
376
+ TRACING_CATEGORY_NODE2(dns, native), trace_name_, this);
377
+
378
+ MakeCallback(env()->oncomplete_string(), argc, argv);
379
+ }
380
+
381
+ void MemoryInfo(MemoryTracker* tracker) const override {
382
+ tracker->TrackField("channel", channel_);
383
+ if (response_data_) {
384
+ tracker->TrackFieldWithSize("response", response_data_->buf.size);
385
+ }
386
+ }
387
+
388
+ SET_MEMORY_INFO_NAME(QueryWrap)
389
+ SET_SELF_SIZE(QueryWrap<Traits>)
390
+
391
+ private:
392
+ BaseObjectPtr<ChannelWrap> channel_;
393
+
394
+ std::unique_ptr<ResponseData> response_data_;
395
+ const char* trace_name_;
396
+ // Pointer to pointer to 'this' that can be reset from the destructor,
397
+ // in order to let Callback() know that 'this' no longer exists.
398
+ QueryWrap<Traits>** callback_ptr_ = nullptr;
399
+ };
400
+
401
+ struct AnyTraits final {
402
+ static constexpr const char* name = "resolveAny";
403
+ static int Send(QueryWrap<AnyTraits>* wrap, const char* name);
404
+ static int Parse(
405
+ QueryWrap<AnyTraits>* wrap,
406
+ const std::unique_ptr<ResponseData>& response);
407
+ };
408
+
409
+ struct ATraits final {
410
+ static constexpr const char* name = "resolve4";
411
+ static int Send(QueryWrap<ATraits>* wrap, const char* name);
412
+ static int Parse(
413
+ QueryWrap<ATraits>* wrap,
414
+ const std::unique_ptr<ResponseData>& response);
415
+ };
416
+
417
+ struct AaaaTraits final {
418
+ static constexpr const char* name = "resolve6";
419
+ static int Send(QueryWrap<AaaaTraits>* wrap, const char* name);
420
+ static int Parse(
421
+ QueryWrap<AaaaTraits>* wrap,
422
+ const std::unique_ptr<ResponseData>& response);
423
+ };
424
+
425
+ struct CaaTraits final {
426
+ static constexpr const char* name = "resolveCaa";
427
+ static int Send(QueryWrap<CaaTraits>* wrap, const char* name);
428
+ static int Parse(
429
+ QueryWrap<CaaTraits>* wrap,
430
+ const std::unique_ptr<ResponseData>& response);
431
+ };
432
+
433
+ struct CnameTraits final {
434
+ static constexpr const char* name = "resolveCname";
435
+ static int Send(QueryWrap<CnameTraits>* wrap, const char* name);
436
+ static int Parse(
437
+ QueryWrap<CnameTraits>* wrap,
438
+ const std::unique_ptr<ResponseData>& response);
439
+ };
440
+
441
+ struct MxTraits final {
442
+ static constexpr const char* name = "resolveMx";
443
+ static int Send(QueryWrap<MxTraits>* wrap, const char* name);
444
+ static int Parse(
445
+ QueryWrap<MxTraits>* wrap,
446
+ const std::unique_ptr<ResponseData>& response);
447
+ };
448
+
449
+ struct NsTraits final {
450
+ static constexpr const char* name = "resolveNs";
451
+ static int Send(QueryWrap<NsTraits>* wrap, const char* name);
452
+ static int Parse(
453
+ QueryWrap<NsTraits>* wrap,
454
+ const std::unique_ptr<ResponseData>& response);
455
+ };
456
+
457
+ struct TxtTraits final {
458
+ static constexpr const char* name = "resolveTxt";
459
+ static int Send(QueryWrap<TxtTraits>* wrap, const char* name);
460
+ static int Parse(
461
+ QueryWrap<TxtTraits>* wrap,
462
+ const std::unique_ptr<ResponseData>& response);
463
+ };
464
+
465
+ struct SrvTraits final {
466
+ static constexpr const char* name = "resolveSrv";
467
+ static int Send(QueryWrap<SrvTraits>* wrap, const char* name);
468
+ static int Parse(
469
+ QueryWrap<SrvTraits>* wrap,
470
+ const std::unique_ptr<ResponseData>& response);
471
+ };
472
+
473
+ struct PtrTraits final {
474
+ static constexpr const char* name = "resolvePtr";
475
+ static int Send(QueryWrap<PtrTraits>* wrap, const char* name);
476
+ static int Parse(
477
+ QueryWrap<PtrTraits>* wrap,
478
+ const std::unique_ptr<ResponseData>& response);
479
+ };
480
+
481
+ struct NaptrTraits final {
482
+ static constexpr const char* name = "resolveNaptr";
483
+ static int Send(QueryWrap<NaptrTraits>* wrap, const char* name);
484
+ static int Parse(
485
+ QueryWrap<NaptrTraits>* wrap,
486
+ const std::unique_ptr<ResponseData>& response);
487
+ };
488
+
489
+ struct SoaTraits final {
490
+ static constexpr const char* name = "resolveSoa";
491
+ static int Send(QueryWrap<SoaTraits>* wrap, const char* name);
492
+ static int Parse(
493
+ QueryWrap<SoaTraits>* wrap,
494
+ const std::unique_ptr<ResponseData>& response);
495
+ };
496
+
497
+ struct ReverseTraits final {
498
+ static constexpr const char* name = "reverse";
499
+ static int Send(QueryWrap<ReverseTraits>* wrap, const char* name);
500
+ static int Parse(
501
+ QueryWrap<ReverseTraits>* wrap,
502
+ const std::unique_ptr<ResponseData>& response);
503
+ };
504
+
505
+ using QueryAnyWrap = QueryWrap<AnyTraits>;
506
+ using QueryAWrap = QueryWrap<ATraits>;
507
+ using QueryAaaaWrap = QueryWrap<AaaaTraits>;
508
+ using QueryCaaWrap = QueryWrap<CaaTraits>;
509
+ using QueryCnameWrap = QueryWrap<CnameTraits>;
510
+ using QueryMxWrap = QueryWrap<MxTraits>;
511
+ using QueryNsWrap = QueryWrap<NsTraits>;
512
+ using QueryTxtWrap = QueryWrap<TxtTraits>;
513
+ using QuerySrvWrap = QueryWrap<SrvTraits>;
514
+ using QueryPtrWrap = QueryWrap<PtrTraits>;
515
+ using QueryNaptrWrap = QueryWrap<NaptrTraits>;
516
+ using QuerySoaWrap = QueryWrap<SoaTraits>;
517
+ using GetHostByAddrWrap = QueryWrap<ReverseTraits>;
518
+
519
+ } // namespace cares_wrap
520
+ } // namespace node
521
+
522
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
523
+
524
+ #endif // SRC_CARES_WRAP_H_
@@ -0,0 +1,6 @@
1
+ // This is an auto generated file, please do not edit.
2
+ // Refer to tools/dep_updaters/update-cjs-module-lexer.sh
3
+ #ifndef SRC_CJS_MODULE_LEXER_VERSION_H_
4
+ #define SRC_CJS_MODULE_LEXER_VERSION_H_
5
+ #define CJS_MODULE_LEXER_VERSION "1.2.2"
6
+ #endif // SRC_CJS_MODULE_LEXER_VERSION_H_
@@ -0,0 +1,62 @@
1
+ #ifndef SRC_CLEANUP_QUEUE_INL_H_
2
+ #define SRC_CLEANUP_QUEUE_INL_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "base_object.h"
7
+ #include "cleanup_queue.h"
8
+ #include "memory_tracker-inl.h"
9
+ #include "util.h"
10
+
11
+ namespace node {
12
+
13
+ inline void CleanupQueue::MemoryInfo(MemoryTracker* tracker) const {
14
+ ForEachBaseObject([&](BaseObject* obj) {
15
+ if (obj->IsDoneInitializing()) tracker->Track(obj);
16
+ });
17
+ }
18
+
19
+ inline size_t CleanupQueue::SelfSize() const {
20
+ return sizeof(CleanupQueue) +
21
+ cleanup_hooks_.size() * sizeof(CleanupHookCallback);
22
+ }
23
+
24
+ bool CleanupQueue::empty() const {
25
+ return cleanup_hooks_.empty();
26
+ }
27
+
28
+ void CleanupQueue::Add(Callback cb, void* arg) {
29
+ auto insertion_info =
30
+ cleanup_hooks_.emplace(cb, arg, cleanup_hook_counter_++);
31
+ // Make sure there was no existing element with these values.
32
+ CHECK_EQ(insertion_info.second, true);
33
+ }
34
+
35
+ void CleanupQueue::Remove(Callback cb, void* arg) {
36
+ CleanupHookCallback search{cb, arg, 0};
37
+ cleanup_hooks_.erase(search);
38
+ }
39
+
40
+ template <typename T>
41
+ void CleanupQueue::ForEachBaseObject(T&& iterator) const {
42
+ std::vector<CleanupHookCallback> callbacks = GetOrdered();
43
+
44
+ for (const auto& hook : callbacks) {
45
+ BaseObject* obj = GetBaseObject(hook);
46
+ if (obj != nullptr) iterator(obj);
47
+ }
48
+ }
49
+
50
+ BaseObject* CleanupQueue::GetBaseObject(
51
+ const CleanupHookCallback& callback) const {
52
+ if (callback.fn_ == BaseObject::DeleteMe)
53
+ return static_cast<BaseObject*>(callback.arg_);
54
+ else
55
+ return nullptr;
56
+ }
57
+
58
+ } // namespace node
59
+
60
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
61
+
62
+ #endif // SRC_CLEANUP_QUEUE_INL_H_