@kungfu-tech/libnode-win32-x64 22.22.3-kf.0 → 22.22.3-kf.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 (340) hide show
  1. package/dist/node/include/acorn_version.h +6 -0
  2. package/dist/node/include/aliased_buffer-inl.h +244 -0
  3. package/dist/node/include/aliased_buffer.h +206 -0
  4. package/dist/node/include/aliased_struct-inl.h +54 -0
  5. package/dist/node/include/aliased_struct.h +63 -0
  6. package/dist/node/include/amaro_version.h +6 -0
  7. package/dist/node/include/async_context_frame.h +33 -0
  8. package/dist/node/include/async_wrap-inl.h +96 -0
  9. package/dist/node/include/async_wrap.h +243 -0
  10. package/dist/node/include/base_object-inl.h +335 -0
  11. package/dist/node/include/base_object.h +342 -0
  12. package/dist/node/include/base_object_types.h +74 -0
  13. package/dist/node/include/blob_serializer_deserializer-inl.h +385 -0
  14. package/dist/node/include/blob_serializer_deserializer.h +132 -0
  15. package/dist/node/include/callback_queue-inl.h +97 -0
  16. package/dist/node/include/callback_queue.h +79 -0
  17. package/dist/node/include/cares_wrap.h +447 -0
  18. package/dist/node/include/cjs_module_lexer_version.h +6 -0
  19. package/dist/node/include/cleanup_queue-inl.h +36 -0
  20. package/dist/node/include/cleanup_queue.h +79 -0
  21. package/dist/node/include/compile_cache.h +104 -0
  22. package/dist/node/include/connect_wrap.h +26 -0
  23. package/dist/node/include/connection_wrap.h +30 -0
  24. package/dist/node/include/cppgc/allocation.h +310 -0
  25. package/dist/node/include/cppgc/common.h +28 -0
  26. package/dist/node/include/cppgc/cross-thread-persistent.h +466 -0
  27. package/dist/node/include/cppgc/custom-space.h +97 -0
  28. package/dist/node/include/cppgc/default-platform.h +67 -0
  29. package/dist/node/include/cppgc/ephemeron-pair.h +30 -0
  30. package/dist/node/include/cppgc/explicit-management.h +100 -0
  31. package/dist/node/include/cppgc/garbage-collected.h +106 -0
  32. package/dist/node/include/cppgc/heap-consistency.h +309 -0
  33. package/dist/node/include/cppgc/heap-handle.h +48 -0
  34. package/dist/node/include/cppgc/heap-state.h +82 -0
  35. package/dist/node/include/cppgc/heap-statistics.h +120 -0
  36. package/dist/node/include/cppgc/heap.h +202 -0
  37. package/dist/node/include/cppgc/internal/api-constants.h +87 -0
  38. package/dist/node/include/cppgc/internal/atomic-entry-flag.h +48 -0
  39. package/dist/node/include/cppgc/internal/base-page-handle.h +45 -0
  40. package/dist/node/include/cppgc/internal/caged-heap-local-data.h +121 -0
  41. package/dist/node/include/cppgc/internal/caged-heap.h +68 -0
  42. package/dist/node/include/cppgc/internal/compiler-specific.h +38 -0
  43. package/dist/node/include/cppgc/internal/finalizer-trait.h +93 -0
  44. package/dist/node/include/cppgc/internal/gc-info.h +148 -0
  45. package/dist/node/include/cppgc/internal/logging.h +50 -0
  46. package/dist/node/include/cppgc/internal/member-storage.h +256 -0
  47. package/dist/node/include/cppgc/internal/name-trait.h +137 -0
  48. package/dist/node/include/cppgc/internal/persistent-node.h +214 -0
  49. package/dist/node/include/cppgc/internal/pointer-policies.h +243 -0
  50. package/dist/node/include/cppgc/internal/write-barrier.h +487 -0
  51. package/dist/node/include/cppgc/liveness-broker.h +78 -0
  52. package/dist/node/include/cppgc/macros.h +35 -0
  53. package/dist/node/include/cppgc/member.h +629 -0
  54. package/dist/node/include/cppgc/name-provider.h +65 -0
  55. package/dist/node/include/cppgc/object-size-trait.h +58 -0
  56. package/dist/node/include/cppgc/persistent.h +377 -0
  57. package/dist/node/include/cppgc/platform.h +163 -0
  58. package/dist/node/include/cppgc/prefinalizer.h +75 -0
  59. package/dist/node/include/cppgc/process-heap-statistics.h +36 -0
  60. package/dist/node/include/cppgc/sentinel-pointer.h +39 -0
  61. package/dist/node/include/cppgc/source-location.h +16 -0
  62. package/dist/node/include/cppgc/testing.h +106 -0
  63. package/dist/node/include/cppgc/trace-trait.h +128 -0
  64. package/dist/node/include/cppgc/type-traits.h +271 -0
  65. package/dist/node/include/cppgc/visitor.h +504 -0
  66. package/dist/node/include/crypto/crypto_aes.h +88 -0
  67. package/dist/node/include/crypto/crypto_bio.h +193 -0
  68. package/dist/node/include/crypto/crypto_cipher.h +293 -0
  69. package/dist/node/include/crypto/crypto_clienthello-inl.h +90 -0
  70. package/dist/node/include/crypto/crypto_clienthello.h +131 -0
  71. package/dist/node/include/crypto/crypto_common.h +64 -0
  72. package/dist/node/include/crypto/crypto_context.h +171 -0
  73. package/dist/node/include/crypto/crypto_dh.h +126 -0
  74. package/dist/node/include/crypto/crypto_dsa.h +52 -0
  75. package/dist/node/include/crypto/crypto_ec.h +164 -0
  76. package/dist/node/include/crypto/crypto_hash.h +91 -0
  77. package/dist/node/include/crypto/crypto_hkdf.h +61 -0
  78. package/dist/node/include/crypto/crypto_hmac.h +92 -0
  79. package/dist/node/include/crypto/crypto_keygen.h +299 -0
  80. package/dist/node/include/crypto/crypto_keys.h +392 -0
  81. package/dist/node/include/crypto/crypto_pbkdf2.h +74 -0
  82. package/dist/node/include/crypto/crypto_random.h +124 -0
  83. package/dist/node/include/crypto/crypto_rsa.h +136 -0
  84. package/dist/node/include/crypto/crypto_scrypt.h +85 -0
  85. package/dist/node/include/crypto/crypto_sig.h +165 -0
  86. package/dist/node/include/crypto/crypto_spkac.h +21 -0
  87. package/dist/node/include/crypto/crypto_timing.h +20 -0
  88. package/dist/node/include/crypto/crypto_tls.h +305 -0
  89. package/dist/node/include/crypto/crypto_util.h +725 -0
  90. package/dist/node/include/crypto/crypto_x509.h +140 -0
  91. package/dist/node/include/dataqueue/queue.h +306 -0
  92. package/dist/node/include/debug_utils-inl.h +278 -0
  93. package/dist/node/include/debug_utils.h +196 -0
  94. package/dist/node/include/diagnosticfilename-inl.h +33 -0
  95. package/dist/node/include/embedded_data.h +17 -0
  96. package/dist/node/include/encoding_binding.h +61 -0
  97. package/dist/node/include/env-inl.h +984 -0
  98. package/dist/node/include/env.h +1287 -0
  99. package/dist/node/include/env_properties.h +540 -0
  100. package/dist/node/include/handle_wrap.h +123 -0
  101. package/dist/node/include/histogram-inl.h +107 -0
  102. package/dist/node/include/histogram.h +279 -0
  103. package/dist/node/include/inspector/io_agent.h +30 -0
  104. package/dist/node/include/inspector/main_thread_interface.h +116 -0
  105. package/dist/node/include/inspector/network_agent.h +94 -0
  106. package/dist/node/include/inspector/network_inspector.h +45 -0
  107. package/dist/node/include/inspector/network_requests_buffer.h +195 -0
  108. package/dist/node/include/inspector/network_resource_manager.h +29 -0
  109. package/dist/node/include/inspector/node_json.h +24 -0
  110. package/dist/node/include/inspector/node_string.h +101 -0
  111. package/dist/node/include/inspector/protocol_helper.h +27 -0
  112. package/dist/node/include/inspector/runtime_agent.h +41 -0
  113. package/dist/node/include/inspector/target_agent.h +75 -0
  114. package/dist/node/include/inspector/tracing_agent.h +43 -0
  115. package/dist/node/include/inspector/worker_agent.h +40 -0
  116. package/dist/node/include/inspector/worker_inspector.h +124 -0
  117. package/dist/node/include/inspector_agent.h +165 -0
  118. package/dist/node/include/inspector_io.h +78 -0
  119. package/dist/node/include/inspector_profiler.h +149 -0
  120. package/dist/node/include/inspector_socket.h +60 -0
  121. package/dist/node/include/inspector_socket_server.h +110 -0
  122. package/dist/node/include/js_native_api.h +607 -0
  123. package/dist/node/include/js_native_api_types.h +226 -0
  124. package/dist/node/include/js_native_api_v8.h +485 -0
  125. package/dist/node/include/js_native_api_v8_internals.h +45 -0
  126. package/dist/node/include/js_stream.h +52 -0
  127. package/dist/node/include/json_utils.h +172 -0
  128. package/dist/node/include/large_pages/node_large_page.h +34 -0
  129. package/dist/node/include/libplatform/libplatform-export.h +29 -0
  130. package/dist/node/include/libplatform/libplatform.h +112 -0
  131. package/dist/node/include/libplatform/v8-tracing.h +333 -0
  132. package/dist/node/include/memory_tracker-inl.h +359 -0
  133. package/dist/node/include/memory_tracker.h +289 -0
  134. package/dist/node/include/module_wrap.h +216 -0
  135. package/dist/node/include/node.h +1593 -0
  136. package/dist/node/include/node_api.h +265 -0
  137. package/dist/node/include/node_api_internals.h +48 -0
  138. package/dist/node/include/node_api_types.h +56 -0
  139. package/dist/node/include/node_binding.h +161 -0
  140. package/dist/node/include/node_blob.h +159 -0
  141. package/dist/node/include/node_bob-inl.h +36 -0
  142. package/dist/node/include/node_bob.h +107 -0
  143. package/dist/node/include/node_buffer.h +92 -0
  144. package/dist/node/include/node_builtins.h +220 -0
  145. package/dist/node/include/node_config_file.h +46 -0
  146. package/dist/node/include/node_constants.h +82 -0
  147. package/dist/node/include/node_context_data.h +168 -0
  148. package/dist/node/include/node_contextify.h +204 -0
  149. package/dist/node/include/node_crypto.h +56 -0
  150. package/dist/node/include/node_debug.h +30 -0
  151. package/dist/node/include/node_dir.h +52 -0
  152. package/dist/node/include/node_dotenv.h +45 -0
  153. package/dist/node/include/node_errors.h +380 -0
  154. package/dist/node/include/node_exit_code.h +54 -0
  155. package/dist/node/include/node_external_reference.h +165 -0
  156. package/dist/node/include/node_file-inl.h +406 -0
  157. package/dist/node/include/node_file.h +537 -0
  158. package/dist/node/include/node_http2.h +1177 -0
  159. package/dist/node/include/node_http2_state.h +159 -0
  160. package/dist/node/include/node_http_common-inl.h +202 -0
  161. package/dist/node/include/node_http_common.h +535 -0
  162. package/dist/node/include/node_i18n.h +132 -0
  163. package/dist/node/include/node_internals.h +483 -0
  164. package/dist/node/include/node_main_instance.h +67 -0
  165. package/dist/node/include/node_mem-inl.h +113 -0
  166. package/dist/node/include/node_mem.h +45 -0
  167. package/dist/node/include/node_messaging.h +389 -0
  168. package/dist/node/include/node_metadata.h +164 -0
  169. package/dist/node/include/node_modules.h +91 -0
  170. package/dist/node/include/node_mutex.h +323 -0
  171. package/dist/node/include/node_object_wrap.h +132 -0
  172. package/dist/node/include/node_options-inl.h +490 -0
  173. package/dist/node/include/node_options.h +615 -0
  174. package/dist/node/include/node_perf.h +166 -0
  175. package/dist/node/include/node_perf_common.h +102 -0
  176. package/dist/node/include/node_platform.h +238 -0
  177. package/dist/node/include/node_process-inl.h +26 -0
  178. package/dist/node/include/node_process.h +112 -0
  179. package/dist/node/include/node_realm-inl.h +151 -0
  180. package/dist/node/include/node_realm.h +183 -0
  181. package/dist/node/include/node_report.h +43 -0
  182. package/dist/node/include/node_revert.h +82 -0
  183. package/dist/node/include/node_root_certs.h +3520 -0
  184. package/dist/node/include/node_sea.h +74 -0
  185. package/dist/node/include/node_shadow_realm.h +46 -0
  186. package/dist/node/include/node_snapshot_builder.h +57 -0
  187. package/dist/node/include/node_snapshotable.h +174 -0
  188. package/dist/node/include/node_sockaddr-inl.h +257 -0
  189. package/dist/node/include/node_sockaddr.h +394 -0
  190. package/dist/node/include/node_sqlite.h +270 -0
  191. package/dist/node/include/node_stat_watcher.h +73 -0
  192. package/dist/node/include/node_task_runner.h +92 -0
  193. package/dist/node/include/node_threadsafe_cow-inl.h +54 -0
  194. package/dist/node/include/node_threadsafe_cow.h +105 -0
  195. package/dist/node/include/node_union_bytes.h +81 -0
  196. package/dist/node/include/node_url.h +96 -0
  197. package/dist/node/include/node_v8.h +77 -0
  198. package/dist/node/include/node_v8_platform-inl.h +185 -0
  199. package/dist/node/include/node_version.h +110 -0
  200. package/dist/node/include/node_wasi.h +184 -0
  201. package/dist/node/include/node_wasm_web_api.h +55 -0
  202. package/dist/node/include/node_watchdog.h +154 -0
  203. package/dist/node/include/node_webstorage.h +60 -0
  204. package/dist/node/include/node_worker.h +158 -0
  205. package/dist/node/include/path.h +33 -0
  206. package/dist/node/include/permission/addon_permission.h +31 -0
  207. package/dist/node/include/permission/child_process_permission.h +31 -0
  208. package/dist/node/include/permission/fs_permission.h +167 -0
  209. package/dist/node/include/permission/inspector_permission.h +31 -0
  210. package/dist/node/include/permission/permission.h +138 -0
  211. package/dist/node/include/permission/permission_base.h +65 -0
  212. package/dist/node/include/permission/wasi_permission.h +31 -0
  213. package/dist/node/include/permission/worker_permission.h +31 -0
  214. package/dist/node/include/pipe_wrap.h +80 -0
  215. package/dist/node/include/quic/application.h +159 -0
  216. package/dist/node/include/quic/bindingdata.h +272 -0
  217. package/dist/node/include/quic/cid.h +127 -0
  218. package/dist/node/include/quic/data.h +148 -0
  219. package/dist/node/include/quic/defs.h +245 -0
  220. package/dist/node/include/quic/endpoint.h +458 -0
  221. package/dist/node/include/quic/http3.h +15 -0
  222. package/dist/node/include/quic/logstream.h +81 -0
  223. package/dist/node/include/quic/packet.h +152 -0
  224. package/dist/node/include/quic/preferredaddress.h +72 -0
  225. package/dist/node/include/quic/session.h +443 -0
  226. package/dist/node/include/quic/sessionticket.h +108 -0
  227. package/dist/node/include/quic/streams.h +232 -0
  228. package/dist/node/include/quic/tlscontext.h +227 -0
  229. package/dist/node/include/quic/tokens.h +256 -0
  230. package/dist/node/include/quic/transportparams.h +165 -0
  231. package/dist/node/include/req_wrap-inl.h +171 -0
  232. package/dist/node/include/req_wrap.h +77 -0
  233. package/dist/node/include/spawn_sync.h +243 -0
  234. package/dist/node/include/stream_base-inl.h +173 -0
  235. package/dist/node/include/stream_base.h +478 -0
  236. package/dist/node/include/stream_pipe.h +76 -0
  237. package/dist/node/include/stream_wrap.h +132 -0
  238. package/dist/node/include/string_bytes.h +113 -0
  239. package/dist/node/include/string_decoder-inl.h +31 -0
  240. package/dist/node/include/string_decoder.h +49 -0
  241. package/dist/node/include/tcp_wrap.h +105 -0
  242. package/dist/node/include/threadpoolwork-inl.h +70 -0
  243. package/dist/node/include/timer_wrap-inl.h +32 -0
  244. package/dist/node/include/timer_wrap.h +85 -0
  245. package/dist/node/include/timers.h +70 -0
  246. package/dist/node/include/tracing/agent.h +195 -0
  247. package/dist/node/include/tracing/node_trace_buffer.h +83 -0
  248. package/dist/node/include/tracing/node_trace_writer.h +75 -0
  249. package/dist/node/include/tracing/trace_event.h +722 -0
  250. package/dist/node/include/tracing/trace_event_common.h +1109 -0
  251. package/dist/node/include/tracing/traced_value.h +129 -0
  252. package/dist/node/include/tty_wrap.h +65 -0
  253. package/dist/node/include/udp_wrap.h +230 -0
  254. package/dist/node/include/undici_version.h +6 -0
  255. package/dist/node/include/util-inl.h +700 -0
  256. package/dist/node/include/util.h +1021 -0
  257. package/dist/node/include/uv/aix.h +32 -0
  258. package/dist/node/include/uv/bsd.h +34 -0
  259. package/dist/node/include/uv/darwin.h +61 -0
  260. package/dist/node/include/uv/errno.h +483 -0
  261. package/dist/node/include/uv/linux.h +34 -0
  262. package/dist/node/include/uv/os390.h +33 -0
  263. package/dist/node/include/uv/posix.h +31 -0
  264. package/dist/node/include/uv/sunos.h +44 -0
  265. package/dist/node/include/uv/threadpool.h +37 -0
  266. package/dist/node/include/uv/tree.h +521 -0
  267. package/dist/node/include/uv/unix.h +512 -0
  268. package/dist/node/include/uv/version.h +43 -0
  269. package/dist/node/include/uv/win.h +698 -0
  270. package/dist/node/include/uv.h +1990 -0
  271. package/dist/node/include/v8-array-buffer.h +525 -0
  272. package/dist/node/include/v8-callbacks.h +462 -0
  273. package/dist/node/include/v8-container.h +183 -0
  274. package/dist/node/include/v8-context.h +485 -0
  275. package/dist/node/include/v8-cppgc.h +245 -0
  276. package/dist/node/include/v8-data.h +80 -0
  277. package/dist/node/include/v8-date.h +48 -0
  278. package/dist/node/include/v8-debug.h +168 -0
  279. package/dist/node/include/v8-embedder-heap.h +82 -0
  280. package/dist/node/include/v8-embedder-state-scope.h +52 -0
  281. package/dist/node/include/v8-exception.h +223 -0
  282. package/dist/node/include/v8-extension.h +62 -0
  283. package/dist/node/include/v8-external.h +37 -0
  284. package/dist/node/include/v8-fast-api-calls.h +984 -0
  285. package/dist/node/include/v8-forward.h +82 -0
  286. package/dist/node/include/v8-function-callback.h +607 -0
  287. package/dist/node/include/v8-function.h +140 -0
  288. package/dist/node/include/v8-handle-base.h +137 -0
  289. package/dist/node/include/v8-initialization.h +289 -0
  290. package/dist/node/include/v8-inspector-protocol.h +13 -0
  291. package/dist/node/include/v8-inspector.h +419 -0
  292. package/dist/node/include/v8-internal.h +1397 -0
  293. package/dist/node/include/v8-isolate.h +1767 -0
  294. package/dist/node/include/v8-json.h +47 -0
  295. package/dist/node/include/v8-local-handle.h +758 -0
  296. package/dist/node/include/v8-locker.h +138 -0
  297. package/dist/node/include/v8-maybe.h +160 -0
  298. package/dist/node/include/v8-memory-span.h +198 -0
  299. package/dist/node/include/v8-message.h +233 -0
  300. package/dist/node/include/v8-metrics.h +264 -0
  301. package/dist/node/include/v8-microtask-queue.h +157 -0
  302. package/dist/node/include/v8-microtask.h +28 -0
  303. package/dist/node/include/v8-object.h +824 -0
  304. package/dist/node/include/v8-persistent-handle.h +582 -0
  305. package/dist/node/include/v8-platform.h +1358 -0
  306. package/dist/node/include/v8-primitive-object.h +118 -0
  307. package/dist/node/include/v8-primitive.h +877 -0
  308. package/dist/node/include/v8-profiler.h +1302 -0
  309. package/dist/node/include/v8-promise.h +174 -0
  310. package/dist/node/include/v8-proxy.h +50 -0
  311. package/dist/node/include/v8-regexp.h +106 -0
  312. package/dist/node/include/v8-script.h +904 -0
  313. package/dist/node/include/v8-snapshot.h +266 -0
  314. package/dist/node/include/v8-source-location.h +92 -0
  315. package/dist/node/include/v8-statistics.h +238 -0
  316. package/dist/node/include/v8-template.h +1297 -0
  317. package/dist/node/include/v8-traced-handle.h +432 -0
  318. package/dist/node/include/v8-typed-array.h +390 -0
  319. package/dist/node/include/v8-unwinder-state.h +31 -0
  320. package/dist/node/include/v8-unwinder.h +132 -0
  321. package/dist/node/include/v8-util.h +665 -0
  322. package/dist/node/include/v8-value-serializer-version.h +24 -0
  323. package/dist/node/include/v8-value-serializer.h +316 -0
  324. package/dist/node/include/v8-value.h +655 -0
  325. package/dist/node/include/v8-version-string.h +38 -0
  326. package/dist/node/include/v8-version.h +20 -0
  327. package/dist/node/include/v8-wasm-trap-handler-posix.h +31 -0
  328. package/dist/node/include/v8-wasm-trap-handler-win.h +28 -0
  329. package/dist/node/include/v8-wasm.h +201 -0
  330. package/dist/node/include/v8-weak-callback-info.h +80 -0
  331. package/dist/node/include/v8.h +88 -0
  332. package/dist/node/include/v8config.h +981 -0
  333. package/dist/node/include/zlib_version.h +6 -0
  334. package/dist/node/libnode.dll +0 -0
  335. package/dist/node/libnode.lib +0 -0
  336. package/dist/node/libnodebuildinfo.json +10 -0
  337. package/dist/node/link_node.lib +0 -0
  338. package/dist/node/link_node.node +0 -0
  339. package/libnode.release.json +2 -2
  340. package/package.json +1 -1
@@ -0,0 +1,478 @@
1
+ #ifndef SRC_STREAM_BASE_H_
2
+ #define SRC_STREAM_BASE_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "env.h"
7
+ #include "async_wrap.h"
8
+ #include "node.h"
9
+ #include "util.h"
10
+
11
+ #include "v8.h"
12
+
13
+ namespace node {
14
+
15
+ // Forward declarations
16
+ class Environment;
17
+ class ShutdownWrap;
18
+ class WriteWrap;
19
+ class StreamBase;
20
+ class StreamResource;
21
+ class ExternalReferenceRegistry;
22
+
23
+ struct StreamWriteResult {
24
+ bool async;
25
+ int err;
26
+ WriteWrap* wrap;
27
+ size_t bytes;
28
+ BaseObjectPtr<AsyncWrap> wrap_obj;
29
+ };
30
+
31
+ using JSMethodFunction = void(const v8::FunctionCallbackInfo<v8::Value>& args);
32
+
33
+ class StreamReq {
34
+ public:
35
+ // The kSlot internal field here mirrors BaseObject::InternalFields::kSlot
36
+ // here because instances derived from StreamReq will also derive from
37
+ // BaseObject, and the slots are used for the identical purpose.
38
+ enum InternalFields {
39
+ kSlot = BaseObject::kSlot,
40
+ kStreamReqField = BaseObject::kInternalFieldCount,
41
+ kInternalFieldCount
42
+ };
43
+
44
+ inline explicit StreamReq(
45
+ StreamBase* stream,
46
+ v8::Local<v8::Object> req_wrap_obj);
47
+
48
+ virtual ~StreamReq() = default;
49
+ virtual AsyncWrap* GetAsyncWrap() = 0;
50
+ inline v8::Local<v8::Object> object();
51
+
52
+ // TODO(RaisinTen): Update the return type to a Maybe, so that we can indicate
53
+ // if there is a pending exception/termination.
54
+ void Done(int status, const char* error_str = nullptr);
55
+ inline void Dispose();
56
+
57
+ StreamBase* stream() const { return stream_; }
58
+
59
+ static inline StreamReq* FromObject(v8::Local<v8::Object> req_wrap_obj);
60
+
61
+ // Sets all internal fields of `req_wrap_obj` to `nullptr`.
62
+ // This is what the `WriteWrap` and `ShutdownWrap` JS constructors do,
63
+ // and what we use in C++ after creating these objects from their
64
+ // v8::ObjectTemplates, to avoid the overhead of calling the
65
+ // constructor explicitly.
66
+ static inline void ResetObject(v8::Local<v8::Object> req_wrap_obj);
67
+
68
+ protected:
69
+ virtual void OnDone(int status) = 0;
70
+
71
+ inline void AttachToObject(v8::Local<v8::Object> req_wrap_obj);
72
+
73
+ private:
74
+ StreamBase* const stream_;
75
+ };
76
+
77
+ class ShutdownWrap : public StreamReq {
78
+ public:
79
+ inline ShutdownWrap(
80
+ StreamBase* stream,
81
+ v8::Local<v8::Object> req_wrap_obj);
82
+
83
+ static inline ShutdownWrap* FromObject(v8::Local<v8::Object> req_wrap_obj);
84
+ template <typename T, bool kIsWeak>
85
+ static inline ShutdownWrap* FromObject(
86
+ const BaseObjectPtrImpl<T, kIsWeak>& base_obj);
87
+
88
+ // Call stream()->EmitAfterShutdown() and dispose of this request wrap.
89
+ void OnDone(int status) override;
90
+ };
91
+
92
+ class WriteWrap : public StreamReq {
93
+ public:
94
+ inline void SetBackingStore(std::unique_ptr<v8::BackingStore> bs);
95
+
96
+ inline WriteWrap(
97
+ StreamBase* stream,
98
+ v8::Local<v8::Object> req_wrap_obj);
99
+
100
+ static inline WriteWrap* FromObject(v8::Local<v8::Object> req_wrap_obj);
101
+ template <typename T, bool kIsWeak>
102
+ static inline WriteWrap* FromObject(
103
+ const BaseObjectPtrImpl<T, kIsWeak>& base_obj);
104
+
105
+ // Call stream()->EmitAfterWrite() and dispose of this request wrap.
106
+ void OnDone(int status) override;
107
+
108
+ private:
109
+ std::unique_ptr<v8::BackingStore> backing_store_;
110
+ };
111
+
112
+
113
+ // This is the generic interface for objects that control Node.js' C++ streams.
114
+ // For example, the default `EmitToJSStreamListener` emits a stream's data
115
+ // as Buffers in JS, or `TLSWrap` reads and decrypts data from a stream.
116
+ class StreamListener {
117
+ public:
118
+ virtual ~StreamListener();
119
+
120
+ // This is called when a stream wants to allocate memory before
121
+ // reading data into the freshly allocated buffer (i.e. it is always followed
122
+ // by a `OnStreamRead()` call).
123
+ // This memory may be statically or dynamically allocated; for example,
124
+ // a protocol parser may want to read data into a static buffer if it knows
125
+ // that all data is going to be fully handled during the next
126
+ // `OnStreamRead()` call.
127
+ // The returned buffer does not need to contain `suggested_size` bytes.
128
+ // The default implementation of this method returns a buffer that has exactly
129
+ // the suggested size and is allocated using malloc().
130
+ // It is not valid to return a zero-length buffer from this method.
131
+ // It is not guaranteed that the corresponding `OnStreamRead()` call
132
+ // happens in the same event loop turn as this call.
133
+ virtual uv_buf_t OnStreamAlloc(size_t suggested_size) = 0;
134
+
135
+ // `OnStreamRead()` is called when data is available on the socket and has
136
+ // been read into the buffer provided by `OnStreamAlloc()`.
137
+ // The `buf` argument is the return value of `uv_buf_t`, or may be a buffer
138
+ // with base nullptr in case of an error.
139
+ // `nread` is the number of read bytes (which is at most the buffer length),
140
+ // or, if negative, a libuv error code.
141
+ virtual void OnStreamRead(ssize_t nread,
142
+ const uv_buf_t& buf) = 0;
143
+
144
+ // This is called once a write has finished. `status` may be 0 or,
145
+ // if negative, a libuv error code.
146
+ // By default, this is simply passed on to the previous listener
147
+ // (and raises an assertion if there is none).
148
+ virtual void OnStreamAfterWrite(WriteWrap* w, int status);
149
+
150
+ // This is called once a shutdown has finished. `status` may be 0 or,
151
+ // if negative, a libuv error code.
152
+ // By default, this is simply passed on to the previous listener
153
+ // (and raises an assertion if there is none).
154
+ virtual void OnStreamAfterShutdown(ShutdownWrap* w, int status);
155
+
156
+ // This is called by the stream if it determines that it wants more data
157
+ // to be written to it. Not all streams support this.
158
+ // This callback will not be called as long as there are active writes.
159
+ // It is not supported by all streams; `stream->HasWantsWrite()` returns
160
+ // true if it is supported by a stream.
161
+ virtual void OnStreamWantsWrite(size_t suggested_size) {}
162
+
163
+ // This is called immediately before the stream is destroyed.
164
+ virtual void OnStreamDestroy() {}
165
+
166
+ // The stream this is currently associated with, or nullptr if there is none.
167
+ StreamResource* stream() const { return stream_; }
168
+
169
+ protected:
170
+ // Pass along a read error to the `StreamListener` instance that was active
171
+ // before this one. For example, a protocol parser does not care about read
172
+ // errors and may instead want to let the original handler
173
+ // (e.g. the JS handler) take care of the situation.
174
+ inline void PassReadErrorToPreviousListener(ssize_t nread);
175
+
176
+ StreamResource* stream_ = nullptr;
177
+ StreamListener* previous_listener_ = nullptr;
178
+
179
+ friend class StreamResource;
180
+ };
181
+
182
+
183
+ // An (incomplete) stream listener class that calls the `.oncomplete()`
184
+ // method of the JS objects associated with the wrap objects.
185
+ class ReportWritesToJSStreamListener : public StreamListener {
186
+ public:
187
+ void OnStreamAfterWrite(WriteWrap* w, int status) override;
188
+ void OnStreamAfterShutdown(ShutdownWrap* w, int status) override;
189
+
190
+ private:
191
+ void OnStreamAfterReqFinished(StreamReq* req_wrap, int status);
192
+ };
193
+
194
+
195
+ // A default emitter that just pushes data chunks as Buffer instances to
196
+ // JS land via the handle’s .ondata method.
197
+ class EmitToJSStreamListener : public ReportWritesToJSStreamListener {
198
+ public:
199
+ uv_buf_t OnStreamAlloc(size_t suggested_size) override;
200
+ void OnStreamRead(ssize_t nread, const uv_buf_t& buf) override;
201
+ };
202
+
203
+
204
+ // An alternative listener that uses a custom, user-provided buffer
205
+ // for reading data.
206
+ class CustomBufferJSListener : public ReportWritesToJSStreamListener {
207
+ public:
208
+ uv_buf_t OnStreamAlloc(size_t suggested_size) override;
209
+ void OnStreamRead(ssize_t nread, const uv_buf_t& buf) override;
210
+ void OnStreamDestroy() override { delete this; }
211
+
212
+ explicit CustomBufferJSListener(uv_buf_t buffer) : buffer_(buffer) {}
213
+
214
+ private:
215
+ uv_buf_t buffer_;
216
+ };
217
+
218
+
219
+ // A generic stream, comparable to JS land’s `Duplex` streams.
220
+ // A stream is always controlled through one `StreamListener` instance.
221
+ class StreamResource {
222
+ public:
223
+ virtual ~StreamResource();
224
+
225
+ // These need to be implemented on the readable side of this stream:
226
+
227
+ // Start reading from the underlying resource. This is called by the consumer
228
+ // when more data is desired. Use `EmitAlloc()` and `EmitRead()` to
229
+ // pass data along to the consumer.
230
+ virtual int ReadStart() = 0;
231
+ // Stop reading from the underlying resource. This is called by the
232
+ // consumer when its buffers are full and no more data can be handled.
233
+ virtual int ReadStop() = 0;
234
+
235
+ // These need to be implemented on the writable side of this stream:
236
+ // All of these methods may return an error code synchronously.
237
+ // In that case, the finish callback should *not* be called.
238
+
239
+ // Perform a shutdown operation, and either call req_wrap->Done() when
240
+ // finished and return 0, return 1 for synchronous success, or
241
+ // a libuv error code for synchronous failures.
242
+ virtual int DoShutdown(ShutdownWrap* req_wrap) = 0;
243
+ // Try to write as much data as possible synchronously, and modify
244
+ // `*bufs` and `*count` accordingly. This is a no-op by default.
245
+ // Return 0 for success and a libuv error code for failures.
246
+ virtual int DoTryWrite(uv_buf_t** bufs, size_t* count);
247
+ // Indicates whether this subclass overrides the DoTryWrite
248
+ virtual inline bool HasDoTryWrite() const { return false; }
249
+ // Initiate a write of data.
250
+ // Upon an immediate failure, a libuv error code is returned,
251
+ // w->Done() will never be called and caller should free `bufs`.
252
+ // Otherwise, 0 is returned and w->Done(status) will be called
253
+ // with status set to either
254
+ // (1) 0 after all data are written, or
255
+ // (2) a libuv error code when an error occurs
256
+ // in either case, w->Done() will never be called before DoWrite() returns.
257
+ // When 0 is returned:
258
+ // (1) memory specified by `bufs` and `count` must remain valid until
259
+ // w->Done() gets called.
260
+ // (2) `bufs` might or might not be changed, caller should not rely on this.
261
+ // (3) `bufs` should be freed after w->Done() gets called.
262
+ virtual int DoWrite(WriteWrap* w,
263
+ uv_buf_t* bufs,
264
+ size_t count,
265
+ uv_stream_t* send_handle) = 0;
266
+
267
+ // Returns true if the stream supports the `OnStreamWantsWrite()` interface.
268
+ virtual bool HasWantsWrite() const { return false; }
269
+
270
+ // Optionally, this may provide an error message to be used for
271
+ // failing writes.
272
+ virtual const char* Error() const;
273
+ // Clear the current error (i.e. that would be returned by Error()).
274
+ virtual void ClearError();
275
+
276
+ // Transfer ownership of this stream to `listener`. The previous listener
277
+ // will not receive any more callbacks while the new listener was active.
278
+ inline void PushStreamListener(StreamListener* listener);
279
+ // Remove a listener, and, if this was the currently active one,
280
+ // transfer ownership back to the previous listener.
281
+ void RemoveStreamListener(StreamListener* listener);
282
+
283
+ protected:
284
+ // Call the current listener's OnStreamAlloc() method.
285
+ inline uv_buf_t EmitAlloc(size_t suggested_size);
286
+ // Call the current listener's OnStreamRead() method and update the
287
+ // stream's read byte counter.
288
+ inline void EmitRead(
289
+ ssize_t nread,
290
+ const uv_buf_t& buf = uv_buf_init(nullptr, 0));
291
+ // Call the current listener's OnStreamAfterWrite() method.
292
+ inline void EmitAfterWrite(WriteWrap* w, int status);
293
+ // Call the current listener's OnStreamAfterShutdown() method.
294
+ inline void EmitAfterShutdown(ShutdownWrap* w, int status);
295
+ // Call the current listener's OnStreamWantsWrite() method.
296
+ inline void EmitWantsWrite(size_t suggested_size);
297
+
298
+ StreamListener* listener_ = nullptr;
299
+ uint64_t bytes_read_ = 0;
300
+ uint64_t bytes_written_ = 0;
301
+
302
+ friend class StreamListener;
303
+ };
304
+
305
+
306
+ class StreamBase : public StreamResource {
307
+ public:
308
+ // The kSlot field here mirrors that of BaseObject::InternalFields::kSlot
309
+ // because instances deriving from StreamBase generally also derived from
310
+ // BaseObject (it's possible for it not to, however).
311
+ enum InternalFields {
312
+ kSlot = BaseObject::kSlot,
313
+ kStreamBaseField = BaseObject::kInternalFieldCount,
314
+ kOnReadFunctionField,
315
+ kInternalFieldCount
316
+ };
317
+
318
+ static void AddMethods(IsolateData* isolate_data,
319
+ v8::Local<v8::FunctionTemplate> target);
320
+ static void AddMethods(Environment* env,
321
+ v8::Local<v8::FunctionTemplate> target);
322
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
323
+ virtual bool IsAlive() = 0;
324
+ virtual bool IsClosing() = 0;
325
+ virtual bool IsIPCPipe();
326
+ virtual int GetFD();
327
+
328
+ enum StreamBaseJSChecks { DONT_SKIP_NREAD_CHECKS, SKIP_NREAD_CHECKS };
329
+
330
+ v8::MaybeLocal<v8::Value> CallJSOnreadMethod(
331
+ ssize_t nread,
332
+ v8::Local<v8::ArrayBuffer> ab,
333
+ size_t offset = 0,
334
+ StreamBaseJSChecks checks = DONT_SKIP_NREAD_CHECKS);
335
+
336
+ // This is named `stream_env` to avoid name clashes, because a lot of
337
+ // subclasses are also `BaseObject`s.
338
+ Environment* stream_env() const { return env_; }
339
+
340
+ // TODO(RaisinTen): Update the return type to a Maybe, so that we can indicate
341
+ // if there is a pending exception/termination.
342
+ // Shut down the current stream. This request can use an existing
343
+ // ShutdownWrap object (that was created in JS), or a new one will be created.
344
+ // Returns 1 in case of a synchronous completion, 0 in case of asynchronous
345
+ // completion, and a libuv error case in case of synchronous failure.
346
+ int Shutdown(v8::Local<v8::Object> req_wrap_obj = v8::Local<v8::Object>());
347
+
348
+ // TODO(RaisinTen): Update the return type to a Maybe, so that we can indicate
349
+ // if there is a pending exception/termination.
350
+ // Write data to the current stream. This request can use an existing
351
+ // WriteWrap object (that was created in JS), or a new one will be created.
352
+ // This will first try to write synchronously using `DoTryWrite()`, then
353
+ // asynchronously using `DoWrite()`.
354
+ // Caller can pass `skip_try_write` as true if it has already called
355
+ // `DoTryWrite()` and ends up with a partial write, or it knows that the
356
+ // write is too large to finish synchronously.
357
+ // If the return value indicates a synchronous completion, no callback will
358
+ // be invoked.
359
+ StreamWriteResult Write(
360
+ uv_buf_t* bufs,
361
+ size_t count,
362
+ uv_stream_t* send_handle = nullptr,
363
+ v8::Local<v8::Object> req_wrap_obj = v8::Local<v8::Object>(),
364
+ bool skip_try_write = false);
365
+
366
+ // These can be overridden by subclasses to get more specific wrap instances.
367
+ // For example, a subclass Foo could create a FooWriteWrap or FooShutdownWrap
368
+ // (inheriting from ShutdownWrap/WriteWrap) that has extra fields, like
369
+ // an associated libuv request.
370
+ virtual ShutdownWrap* CreateShutdownWrap(v8::Local<v8::Object> object);
371
+ virtual WriteWrap* CreateWriteWrap(v8::Local<v8::Object> object);
372
+
373
+ // One of these must be implemented
374
+ virtual AsyncWrap* GetAsyncWrap() = 0;
375
+ virtual v8::Local<v8::Object> GetObject();
376
+
377
+ static inline StreamBase* FromObject(v8::Local<v8::Object> obj);
378
+
379
+ protected:
380
+ inline explicit StreamBase(Environment* env);
381
+
382
+ // JS Methods
383
+ int ReadStartJS(const v8::FunctionCallbackInfo<v8::Value>& args);
384
+ int ReadStopJS(const v8::FunctionCallbackInfo<v8::Value>& args);
385
+ int Shutdown(const v8::FunctionCallbackInfo<v8::Value>& args);
386
+ int Writev(const v8::FunctionCallbackInfo<v8::Value>& args);
387
+ int WriteBuffer(const v8::FunctionCallbackInfo<v8::Value>& args);
388
+ template <enum encoding enc>
389
+ int WriteString(const v8::FunctionCallbackInfo<v8::Value>& args);
390
+ int UseUserBuffer(const v8::FunctionCallbackInfo<v8::Value>& args);
391
+
392
+ static void GetFD(const v8::FunctionCallbackInfo<v8::Value>& args);
393
+ static void GetExternal(const v8::FunctionCallbackInfo<v8::Value>& args);
394
+ static void GetBytesRead(const v8::FunctionCallbackInfo<v8::Value>& args);
395
+ static void GetBytesWritten(const v8::FunctionCallbackInfo<v8::Value>& args);
396
+ inline void AttachToObject(v8::Local<v8::Object> obj);
397
+
398
+ template <int (StreamBase::*Method)(
399
+ const v8::FunctionCallbackInfo<v8::Value>& args)>
400
+ static void JSMethod(const v8::FunctionCallbackInfo<v8::Value>& args);
401
+
402
+ // Internal, used only in StreamBase methods + env.cc.
403
+ enum StreamBaseStateFields {
404
+ kReadBytesOrError,
405
+ kArrayBufferOffset,
406
+ kBytesWritten,
407
+ kLastWriteWasAsync,
408
+ kNumStreamBaseStateFields
409
+ };
410
+
411
+ private:
412
+ Environment* env_;
413
+ EmitToJSStreamListener default_listener_;
414
+
415
+ void SetWriteResult(const StreamWriteResult& res);
416
+ static void AddAccessor(v8::Isolate* isolate,
417
+ v8::Local<v8::Signature> sig,
418
+ enum v8::PropertyAttribute attributes,
419
+ v8::Local<v8::FunctionTemplate> t,
420
+ JSMethodFunction* getter,
421
+ JSMethodFunction* setter,
422
+ v8::Local<v8::String> str);
423
+ static void AddMethod(v8::Isolate* isolate,
424
+ v8::Local<v8::Signature> sig,
425
+ enum v8::PropertyAttribute attributes,
426
+ v8::Local<v8::FunctionTemplate> t,
427
+ JSMethodFunction* stream_method,
428
+ v8::Local<v8::String> str);
429
+
430
+ friend class WriteWrap;
431
+ friend class ShutdownWrap;
432
+ friend class Environment; // For kNumStreamBaseStateFields.
433
+ };
434
+
435
+
436
+ // These are helpers for creating `ShutdownWrap`/`WriteWrap` instances.
437
+ // `OtherBase` must have a constructor that matches the `AsyncWrap`
438
+ // constructors’s (Environment*, Local<Object>, AsyncWrap::Provider) signature
439
+ // and be a subclass of `AsyncWrap`.
440
+ template <typename OtherBase>
441
+ class SimpleShutdownWrap : public ShutdownWrap, public OtherBase {
442
+ public:
443
+ SimpleShutdownWrap(StreamBase* stream,
444
+ v8::Local<v8::Object> req_wrap_obj);
445
+
446
+ AsyncWrap* GetAsyncWrap() override { return this; }
447
+
448
+ SET_NO_MEMORY_INFO()
449
+ SET_MEMORY_INFO_NAME(SimpleShutdownWrap)
450
+ SET_SELF_SIZE(SimpleShutdownWrap)
451
+
452
+ bool IsNotIndicativeOfMemoryLeakAtExit() const override {
453
+ return OtherBase::IsNotIndicativeOfMemoryLeakAtExit();
454
+ }
455
+ };
456
+
457
+ template <typename OtherBase>
458
+ class SimpleWriteWrap : public WriteWrap, public OtherBase {
459
+ public:
460
+ SimpleWriteWrap(StreamBase* stream,
461
+ v8::Local<v8::Object> req_wrap_obj);
462
+
463
+ AsyncWrap* GetAsyncWrap() override { return this; }
464
+
465
+ SET_NO_MEMORY_INFO()
466
+ SET_MEMORY_INFO_NAME(SimpleWriteWrap)
467
+ SET_SELF_SIZE(SimpleWriteWrap)
468
+
469
+ bool IsNotIndicativeOfMemoryLeakAtExit() const override {
470
+ return OtherBase::IsNotIndicativeOfMemoryLeakAtExit();
471
+ }
472
+ };
473
+
474
+ } // namespace node
475
+
476
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
477
+
478
+ #endif // SRC_STREAM_BASE_H_
@@ -0,0 +1,76 @@
1
+ #ifndef SRC_STREAM_PIPE_H_
2
+ #define SRC_STREAM_PIPE_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "stream_base.h"
7
+
8
+ namespace node {
9
+
10
+ class StreamPipe : public AsyncWrap {
11
+ public:
12
+ ~StreamPipe() override;
13
+
14
+ void Unpipe(bool is_in_deletion = false);
15
+
16
+ static v8::Maybe<StreamPipe*> New(StreamBase* source,
17
+ StreamBase* sink,
18
+ v8::Local<v8::Object> obj);
19
+ static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
20
+ static void Start(const v8::FunctionCallbackInfo<v8::Value>& args);
21
+ static void Unpipe(const v8::FunctionCallbackInfo<v8::Value>& args);
22
+ static void IsClosed(const v8::FunctionCallbackInfo<v8::Value>& args);
23
+ static void PendingWrites(const v8::FunctionCallbackInfo<v8::Value>& args);
24
+
25
+ SET_NO_MEMORY_INFO()
26
+ SET_MEMORY_INFO_NAME(StreamPipe)
27
+ SET_SELF_SIZE(StreamPipe)
28
+
29
+ private:
30
+ StreamPipe(StreamBase* source, StreamBase* sink, v8::Local<v8::Object> obj);
31
+
32
+ inline StreamBase* source();
33
+ inline StreamBase* sink();
34
+
35
+ int pending_writes_ = 0;
36
+ bool is_reading_ = false;
37
+ bool is_eof_ = false;
38
+ bool is_closed_ = true;
39
+ bool sink_destroyed_ = false;
40
+ bool source_destroyed_ = false;
41
+ bool uses_wants_write_ = false;
42
+
43
+ // Set a default value so that when we’re coming from Start(), we know
44
+ // that we don’t want to read just yet.
45
+ // This will likely need to be changed when supporting streams without
46
+ // `OnStreamWantsWrite()` support.
47
+ size_t wanted_data_ = 0;
48
+
49
+ void ProcessData(size_t nread, std::unique_ptr<v8::BackingStore> bs);
50
+
51
+ class ReadableListener : public StreamListener {
52
+ public:
53
+ uv_buf_t OnStreamAlloc(size_t suggested_size) override;
54
+ void OnStreamRead(ssize_t nread, const uv_buf_t& buf) override;
55
+ void OnStreamDestroy() override;
56
+ };
57
+
58
+ class WritableListener : public StreamListener {
59
+ public:
60
+ uv_buf_t OnStreamAlloc(size_t suggested_size) override;
61
+ void OnStreamRead(ssize_t nread, const uv_buf_t& buf) override;
62
+ void OnStreamAfterWrite(WriteWrap* w, int status) override;
63
+ void OnStreamAfterShutdown(ShutdownWrap* w, int status) override;
64
+ void OnStreamWantsWrite(size_t suggested_size) override;
65
+ void OnStreamDestroy() override;
66
+ };
67
+
68
+ ReadableListener readable_listener_;
69
+ WritableListener writable_listener_;
70
+ };
71
+
72
+ } // namespace node
73
+
74
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
75
+
76
+ #endif // SRC_STREAM_PIPE_H_
@@ -0,0 +1,132 @@
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_STREAM_WRAP_H_
23
+ #define SRC_STREAM_WRAP_H_
24
+
25
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
26
+
27
+ #include "stream_base.h"
28
+ #include "handle_wrap.h"
29
+ #include "v8.h"
30
+
31
+ namespace node {
32
+
33
+ class Environment;
34
+ class ExternalReferenceRegistry;
35
+
36
+ class LibuvStreamWrap : public HandleWrap, public StreamBase {
37
+ public:
38
+ static void Initialize(v8::Local<v8::Object> target,
39
+ v8::Local<v8::Value> unused,
40
+ v8::Local<v8::Context> context,
41
+ void* priv);
42
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
43
+ int GetFD() override;
44
+ bool IsAlive() override;
45
+ bool IsClosing() override;
46
+ bool IsIPCPipe() override;
47
+
48
+ // JavaScript functions
49
+ int ReadStart() override;
50
+ int ReadStop() override;
51
+
52
+ // Resource implementation
53
+ int DoShutdown(ShutdownWrap* req_wrap) override;
54
+ int DoTryWrite(uv_buf_t** bufs, size_t* count) override;
55
+ inline bool HasDoTryWrite() const override { return true; }
56
+ int DoWrite(WriteWrap* w,
57
+ uv_buf_t* bufs,
58
+ size_t count,
59
+ uv_stream_t* send_handle) override;
60
+
61
+ inline uv_stream_t* stream() const {
62
+ return stream_;
63
+ }
64
+
65
+ inline bool is_named_pipe() const {
66
+ return stream()->type == UV_NAMED_PIPE;
67
+ }
68
+
69
+ inline bool is_named_pipe_ipc() const {
70
+ return is_named_pipe() &&
71
+ reinterpret_cast<const uv_pipe_t*>(stream())->ipc != 0;
72
+ }
73
+
74
+ inline bool is_tcp() const {
75
+ return stream()->type == UV_TCP;
76
+ }
77
+
78
+ ShutdownWrap* CreateShutdownWrap(v8::Local<v8::Object> object) override;
79
+ WriteWrap* CreateWriteWrap(v8::Local<v8::Object> object) override;
80
+
81
+ static LibuvStreamWrap* From(Environment* env, v8::Local<v8::Object> object);
82
+
83
+ protected:
84
+ LibuvStreamWrap(Environment* env,
85
+ v8::Local<v8::Object> object,
86
+ uv_stream_t* stream,
87
+ AsyncWrap::ProviderType provider);
88
+
89
+ AsyncWrap* GetAsyncWrap() override;
90
+
91
+ static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
92
+ Environment* env);
93
+
94
+ protected:
95
+ inline void set_fd(int fd) {
96
+ #ifdef _WIN32
97
+ fd_ = fd;
98
+ #endif
99
+ }
100
+
101
+
102
+ private:
103
+ static void GetWriteQueueSize(
104
+ const v8::FunctionCallbackInfo<v8::Value>& info);
105
+ static void SetBlocking(const v8::FunctionCallbackInfo<v8::Value>& args);
106
+
107
+ // Callbacks for libuv
108
+ void OnUvAlloc(size_t suggested_size, uv_buf_t* buf);
109
+ v8::Maybe<void> OnUvRead(ssize_t nread, const uv_buf_t* buf);
110
+
111
+ static void AfterUvWrite(uv_write_t* req, int status);
112
+ static void AfterUvShutdown(uv_shutdown_t* req, int status);
113
+
114
+ uv_stream_t* const stream_;
115
+
116
+ #ifdef _WIN32
117
+ // We don't always have an FD that we could look up on the stream_
118
+ // object itself on Windows. However, for some cases, we open handles
119
+ // using FDs; In that case, we can store and provide the value.
120
+ // This became necessary because it allows to detect situations
121
+ // where multiple handles refer to the same stdio FDs (in particular,
122
+ // a possible IPC channel and a regular process.std??? stream).
123
+ int fd_ = -1;
124
+ #endif
125
+ };
126
+
127
+
128
+ } // namespace node
129
+
130
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
131
+
132
+ #endif // SRC_STREAM_WRAP_H_