@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,149 @@
1
+ #ifndef SRC_INSPECTOR_PROFILER_H_
2
+ #define SRC_INSPECTOR_PROFILER_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #if !HAVE_INSPECTOR
7
+ #error("This header can only be used when inspector is enabled")
8
+ #endif
9
+
10
+ #include <unordered_set>
11
+ #include "inspector_agent.h"
12
+
13
+ namespace node {
14
+ // Forward declaration to break recursive dependency chain with src/env.h.
15
+ class Environment;
16
+
17
+ namespace profiler {
18
+
19
+ class V8ProfilerConnection {
20
+ public:
21
+ class V8ProfilerSessionDelegate : public inspector::InspectorSessionDelegate {
22
+ public:
23
+ explicit V8ProfilerSessionDelegate(V8ProfilerConnection* connection)
24
+ : connection_(connection) {}
25
+
26
+ void SendMessageToFrontend(
27
+ const v8_inspector::StringView& message) override;
28
+
29
+ private:
30
+ V8ProfilerConnection* connection_;
31
+ };
32
+
33
+ explicit V8ProfilerConnection(Environment* env);
34
+ virtual ~V8ProfilerConnection() = default;
35
+
36
+ Environment* env() const { return env_; }
37
+
38
+ // Dispatch a protocol message, and returns the id of the message.
39
+ // `method` does not need to be surrounded by quotes.
40
+ // The optional `params` should be formatted in JSON.
41
+ // The strings should be in one byte characters - which is enough for
42
+ // the commands we use here.
43
+ uint32_t DispatchMessage(const char* method,
44
+ const char* params = nullptr,
45
+ bool is_profile_request = false);
46
+
47
+ // Use DispatchMessage() to dispatch necessary inspector messages
48
+ // to start and end the profiling.
49
+ virtual void Start() = 0;
50
+ virtual void End() = 0;
51
+
52
+ // Return a descriptive name of the profile for debugging.
53
+ virtual const char* type() const = 0;
54
+ // Return if the profile is ending and the response can be parsed.
55
+ virtual bool ending() const = 0;
56
+ // Return the directory where the profile should be placed.
57
+ virtual std::string GetDirectory() const = 0;
58
+ // Return the filename the profile should be written as.
59
+ virtual std::string GetFilename() const = 0;
60
+ // Return the profile object parsed from `message.result`,
61
+ // which will be then written as a JSON.
62
+ virtual v8::MaybeLocal<v8::Object> GetProfile(
63
+ v8::Local<v8::Object> result) = 0;
64
+ virtual void WriteProfile(v8::Local<v8::Object> result);
65
+
66
+ bool HasProfileId(uint32_t id) const {
67
+ return profile_ids_.find(id) != profile_ids_.end();
68
+ }
69
+
70
+ void RemoveProfileId(uint32_t id) { profile_ids_.erase(id); }
71
+
72
+ private:
73
+ uint32_t next_id() { return id_++; }
74
+ std::unique_ptr<inspector::InspectorSession> session_;
75
+ uint32_t id_ = 1;
76
+ std::unordered_set<uint32_t> profile_ids_;
77
+
78
+ protected:
79
+ Environment* env_ = nullptr;
80
+ };
81
+
82
+ class V8CoverageConnection : public V8ProfilerConnection {
83
+ public:
84
+ explicit V8CoverageConnection(Environment* env) : V8ProfilerConnection(env) {}
85
+
86
+ void Start() override;
87
+ void End() override;
88
+
89
+ const char* type() const override { return "coverage"; }
90
+ bool ending() const override { return ending_; }
91
+
92
+ std::string GetDirectory() const override;
93
+ std::string GetFilename() const override;
94
+ v8::MaybeLocal<v8::Object> GetProfile(v8::Local<v8::Object> result) override;
95
+ void WriteProfile(v8::Local<v8::Object> result) override;
96
+ void WriteSourceMapCache();
97
+ void TakeCoverage();
98
+ void StopCoverage();
99
+
100
+ private:
101
+ std::unique_ptr<inspector::InspectorSession> session_;
102
+ bool ending_ = false;
103
+ };
104
+
105
+ class V8CpuProfilerConnection : public V8ProfilerConnection {
106
+ public:
107
+ explicit V8CpuProfilerConnection(Environment* env)
108
+ : V8ProfilerConnection(env) {}
109
+
110
+ void Start() override;
111
+ void End() override;
112
+
113
+ const char* type() const override { return "CPU"; }
114
+ bool ending() const override { return ending_; }
115
+
116
+ std::string GetDirectory() const override;
117
+ std::string GetFilename() const override;
118
+ v8::MaybeLocal<v8::Object> GetProfile(v8::Local<v8::Object> result) override;
119
+
120
+ private:
121
+ std::unique_ptr<inspector::InspectorSession> session_;
122
+ bool ending_ = false;
123
+ };
124
+
125
+ class V8HeapProfilerConnection : public V8ProfilerConnection {
126
+ public:
127
+ explicit V8HeapProfilerConnection(Environment* env)
128
+ : V8ProfilerConnection(env) {}
129
+
130
+ void Start() override;
131
+ void End() override;
132
+
133
+ const char* type() const override { return "heap"; }
134
+ bool ending() const override { return ending_; }
135
+
136
+ std::string GetDirectory() const override;
137
+ std::string GetFilename() const override;
138
+ v8::MaybeLocal<v8::Object> GetProfile(v8::Local<v8::Object> result) override;
139
+
140
+ private:
141
+ std::unique_ptr<inspector::InspectorSession> session_;
142
+ bool ending_ = false;
143
+ };
144
+
145
+ } // namespace profiler
146
+ } // namespace node
147
+
148
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
149
+ #endif // SRC_INSPECTOR_PROFILER_H_
@@ -0,0 +1,60 @@
1
+ #ifndef SRC_INSPECTOR_SOCKET_H_
2
+ #define SRC_INSPECTOR_SOCKET_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "util.h"
7
+ #include "uv.h"
8
+
9
+ #include <string>
10
+ #include <vector>
11
+
12
+ namespace node {
13
+ namespace inspector {
14
+
15
+ class ProtocolHandler;
16
+
17
+ // HTTP Wrapper around a uv_tcp_t
18
+ class InspectorSocket {
19
+ public:
20
+ class Delegate {
21
+ public:
22
+ virtual void OnHttpGet(const std::string& host,
23
+ const std::string& path) = 0;
24
+ virtual void OnSocketUpgrade(const std::string& host,
25
+ const std::string& path,
26
+ const std::string& accept_key) = 0;
27
+ virtual void OnWsFrame(const std::vector<char>& frame) = 0;
28
+ virtual ~Delegate() = default;
29
+ };
30
+
31
+ using DelegatePointer = std::unique_ptr<Delegate>;
32
+ using Pointer = std::unique_ptr<InspectorSocket>;
33
+
34
+ static Pointer Accept(uv_stream_t* server, DelegatePointer delegate);
35
+
36
+ ~InspectorSocket();
37
+
38
+ void AcceptUpgrade(const std::string& accept_key);
39
+ void CancelHandshake();
40
+ void Write(const char* data, size_t len);
41
+ void SwitchProtocol(ProtocolHandler* handler);
42
+ std::string GetHost();
43
+
44
+ InspectorSocket(const InspectorSocket&) = delete;
45
+ InspectorSocket& operator=(const InspectorSocket&) = delete;
46
+
47
+ private:
48
+ static void Shutdown(ProtocolHandler*);
49
+ InspectorSocket() = default;
50
+
51
+ DeleteFnPtr<ProtocolHandler, Shutdown> protocol_handler_;
52
+ };
53
+
54
+
55
+ } // namespace inspector
56
+ } // namespace node
57
+
58
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
59
+
60
+ #endif // SRC_INSPECTOR_SOCKET_H_
@@ -0,0 +1,110 @@
1
+ #ifndef SRC_INSPECTOR_SOCKET_SERVER_H_
2
+ #define SRC_INSPECTOR_SOCKET_SERVER_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "inspector_agent.h"
7
+ #include "inspector_socket.h"
8
+ #include "uv.h"
9
+
10
+ #include <map>
11
+ #include <string>
12
+ #include <vector>
13
+
14
+ #if !HAVE_INSPECTOR
15
+ #error("This header can only be used when inspector is enabled")
16
+ #endif
17
+
18
+ namespace node {
19
+ namespace inspector {
20
+
21
+ std::string FormatWsAddress(const std::string& host, int port,
22
+ const std::string& target_id,
23
+ bool include_protocol);
24
+
25
+ class InspectorSocketServer;
26
+ class SocketSession;
27
+ class ServerSocket;
28
+
29
+ class SocketServerDelegate {
30
+ public:
31
+ virtual void AssignServer(InspectorSocketServer* server) = 0;
32
+ virtual void StartSession(int session_id, const std::string& target_id) = 0;
33
+ virtual void EndSession(int session_id) = 0;
34
+ virtual void MessageReceived(int session_id, const std::string& message) = 0;
35
+ virtual std::vector<std::string> GetTargetIds() = 0;
36
+ virtual std::string GetTargetTitle(const std::string& id) = 0;
37
+ virtual std::string GetTargetUrl(const std::string& id) = 0;
38
+ virtual ~SocketServerDelegate() = default;
39
+ };
40
+
41
+ // HTTP Server, writes messages requested as TransportActions, and responds
42
+ // to HTTP requests and WS upgrades.
43
+
44
+ class InspectorSocketServer {
45
+ public:
46
+ InspectorSocketServer(std::unique_ptr<SocketServerDelegate> delegate,
47
+ uv_loop_t* loop,
48
+ const std::string& host,
49
+ int port,
50
+ const InspectPublishUid& inspect_publish_uid,
51
+ FILE* out = stderr);
52
+ ~InspectorSocketServer();
53
+
54
+ // Start listening on host/port
55
+ bool Start();
56
+
57
+ // Called by the TransportAction sent with InspectorIo::Write():
58
+ // kKill and kStop
59
+ void Stop();
60
+ // kSendMessage
61
+ void Send(int session_id, const std::string& message);
62
+ // kKill
63
+ void TerminateConnections();
64
+ int Port() const;
65
+
66
+ // Session connection lifecycle
67
+ void Accept(int server_port, uv_stream_t* server_socket);
68
+ bool HandleGetRequest(int session_id, const std::string& host,
69
+ const std::string& path);
70
+ void SessionStarted(int session_id, const std::string& target_id,
71
+ const std::string& ws_id);
72
+ void SessionTerminated(int session_id);
73
+ void MessageReceived(int session_id, const std::string& message) {
74
+ delegate_->MessageReceived(session_id, message);
75
+ }
76
+ SocketSession* Session(int session_id);
77
+ bool done() const {
78
+ return server_sockets_.empty() && connected_sessions_.empty();
79
+ }
80
+
81
+ static void CloseServerSocket(ServerSocket*);
82
+ using ServerSocketPtr = DeleteFnPtr<ServerSocket, CloseServerSocket>;
83
+
84
+ private:
85
+ void SendListResponse(InspectorSocket* socket, const std::string& host,
86
+ SocketSession* session);
87
+ std::string GetFrontendURL(bool is_compat,
88
+ const std::string &formatted_address);
89
+ bool TargetExists(const std::string& id);
90
+
91
+ enum class ServerState {kNew, kRunning, kStopped};
92
+ uv_loop_t* loop_;
93
+ std::unique_ptr<SocketServerDelegate> delegate_;
94
+ const std::string host_;
95
+ int port_;
96
+ InspectPublishUid inspect_publish_uid_;
97
+ std::vector<ServerSocketPtr> server_sockets_;
98
+ std::map<int, std::pair<std::string, std::unique_ptr<SocketSession>>>
99
+ connected_sessions_;
100
+ int next_session_id_;
101
+ FILE* out_;
102
+ ServerState state_;
103
+ };
104
+
105
+ } // namespace inspector
106
+ } // namespace node
107
+
108
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
109
+
110
+ #endif // SRC_INSPECTOR_SOCKET_SERVER_H_