@encharm/cws 4.5.2 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/CLAUDE.md +81 -0
- package/README.md +10 -5
- package/dist/bindings/cws_darwin_arm64_node115.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node127.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node137.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node147.node +0 -0
- package/dist/bindings/cws_linux_arm64_node115.node +0 -0
- package/dist/bindings/cws_linux_arm64_node127.node +0 -0
- package/dist/bindings/cws_linux_arm64_node137.node +0 -0
- package/dist/bindings/cws_linux_arm64_node147.node +0 -0
- package/dist/bindings/cws_linux_x64_node115.node +0 -0
- package/dist/bindings/cws_linux_x64_node127.node +0 -0
- package/dist/bindings/cws_linux_x64_node137.node +0 -0
- package/dist/bindings/cws_linux_x64_node147.node +0 -0
- package/dist/bindings/cws_win32_x64_node115.node +0 -0
- package/dist/bindings/cws_win32_x64_node127.node +0 -0
- package/dist/bindings/cws_win32_x64_node137.node +0 -0
- package/dist/bindings/cws_win32_x64_node147.node +0 -0
- package/package.json +1 -1
- package/src/Addon.cpp +2 -1
- package/src/Addon.h +70 -14
- package/src/Hub.h +1 -0
- package/src/Networking.h +11 -0
- package/src/Socket.h +201 -6
- package/src/WebSocket.cpp +4 -1
- package/src/cSNode.cpp +2 -0
- package/src/cSNode.h +4 -0
- package/src/headers/24/tracing/agent.h +195 -0
- package/src/headers/24/tracing/trace_event.h +722 -0
- package/src/headers/26/acorn_version.h +6 -0
- package/src/headers/26/aliased_buffer-inl.h +264 -0
- package/src/headers/26/aliased_buffer.h +205 -0
- package/src/headers/26/aliased_struct-inl.h +143 -0
- package/src/headers/26/aliased_struct.h +248 -0
- package/src/headers/26/amaro_version.h +6 -0
- package/src/headers/26/async_context_frame.h +33 -0
- package/src/headers/26/async_wrap-inl.h +123 -0
- package/src/headers/26/async_wrap.h +254 -0
- package/src/headers/26/base_object-inl.h +333 -0
- package/src/headers/26/base_object.h +339 -0
- package/src/headers/26/base_object_types.h +76 -0
- package/src/headers/26/blob_serializer_deserializer-inl.h +385 -0
- package/src/headers/26/blob_serializer_deserializer.h +142 -0
- package/src/headers/26/builtin_info.h +57 -0
- package/src/headers/26/callback_queue-inl.h +97 -0
- package/src/headers/26/callback_queue.h +79 -0
- package/src/headers/26/cares_wrap.h +475 -0
- package/src/headers/26/cleanup_queue-inl.h +36 -0
- package/src/headers/26/cleanup_queue.h +79 -0
- package/src/headers/26/compile_cache.h +134 -0
- package/src/headers/26/connect_wrap.h +26 -0
- package/src/headers/26/connection_wrap.h +30 -0
- package/src/headers/26/cppgc_helpers-inl.h +69 -0
- package/src/headers/26/cppgc_helpers.h +162 -0
- package/src/headers/26/crypto/crypto_aes.h +107 -0
- package/src/headers/26/crypto/crypto_argon2.h +88 -0
- package/src/headers/26/crypto/crypto_bio.h +193 -0
- package/src/headers/26/crypto/crypto_chacha20_poly1305.h +62 -0
- package/src/headers/26/crypto/crypto_cipher.h +291 -0
- package/src/headers/26/crypto/crypto_common.h +48 -0
- package/src/headers/26/crypto/crypto_context.h +219 -0
- package/src/headers/26/crypto/crypto_dh.h +104 -0
- package/src/headers/26/crypto/crypto_dsa.h +50 -0
- package/src/headers/26/crypto/crypto_ec.h +102 -0
- package/src/headers/26/crypto/crypto_hash.h +157 -0
- package/src/headers/26/crypto/crypto_hkdf.h +62 -0
- package/src/headers/26/crypto/crypto_hmac.h +92 -0
- package/src/headers/26/crypto/crypto_kem.h +131 -0
- package/src/headers/26/crypto/crypto_keygen.h +382 -0
- package/src/headers/26/crypto/crypto_keys.h +366 -0
- package/src/headers/26/crypto/crypto_kmac.h +79 -0
- package/src/headers/26/crypto/crypto_pbkdf2.h +76 -0
- package/src/headers/26/crypto/crypto_pqc.h +39 -0
- package/src/headers/26/crypto/crypto_random.h +127 -0
- package/src/headers/26/crypto/crypto_rsa.h +108 -0
- package/src/headers/26/crypto/crypto_scrypt.h +85 -0
- package/src/headers/26/crypto/crypto_sig.h +159 -0
- package/src/headers/26/crypto/crypto_spkac.h +21 -0
- package/src/headers/26/crypto/crypto_timing.h +20 -0
- package/src/headers/26/crypto/crypto_tls.h +342 -0
- package/src/headers/26/crypto/crypto_turboshake.h +105 -0
- package/src/headers/26/crypto/crypto_util.h +775 -0
- package/src/headers/26/crypto/crypto_x509.h +140 -0
- package/src/headers/26/dataqueue/queue.h +311 -0
- package/src/headers/26/debug_utils-inl.h +291 -0
- package/src/headers/26/debug_utils.h +200 -0
- package/src/headers/26/diagnosticfilename-inl.h +33 -0
- package/src/headers/26/embedded_data.h +17 -0
- package/src/headers/26/encoding_binding.h +59 -0
- package/src/headers/26/env-inl.h +956 -0
- package/src/headers/26/env.h +1294 -0
- package/src/headers/26/env_properties.h +562 -0
- package/src/headers/26/ffi/data.h +30 -0
- package/src/headers/26/ffi/fast.h +96 -0
- package/src/headers/26/ffi/jit_memory.h +26 -0
- package/src/headers/26/ffi/types.h +99 -0
- package/src/headers/26/handle_wrap.h +123 -0
- package/src/headers/26/histogram-inl.h +211 -0
- package/src/headers/26/histogram.h +474 -0
- package/src/headers/26/inspector/dom_storage_agent.h +68 -0
- package/src/headers/26/inspector/inspector_object_utils.h +38 -0
- package/src/headers/26/inspector/io_agent.h +30 -0
- package/src/headers/26/inspector/main_thread_interface.h +116 -0
- package/src/headers/26/inspector/network_agent.h +110 -0
- package/src/headers/26/inspector/network_inspector.h +45 -0
- package/src/headers/26/inspector/network_requests_buffer.h +195 -0
- package/src/headers/26/inspector/network_resource_manager.h +29 -0
- package/src/headers/26/inspector/node_json.h +24 -0
- package/src/headers/26/inspector/node_string.h +101 -0
- package/src/headers/26/inspector/notification_emitter.h +38 -0
- package/src/headers/26/inspector/protocol_helper.h +27 -0
- package/src/headers/26/inspector/runtime_agent.h +41 -0
- package/src/headers/26/inspector/storage_agent.h +33 -0
- package/src/headers/26/inspector/target_agent.h +59 -0
- package/src/headers/26/inspector/target_manager.h +70 -0
- package/src/headers/26/inspector/tracing_agent.h +43 -0
- package/src/headers/26/inspector/worker_agent.h +40 -0
- package/src/headers/26/inspector/worker_inspector.h +124 -0
- package/src/headers/26/inspector_agent.h +168 -0
- package/src/headers/26/inspector_io.h +78 -0
- package/src/headers/26/inspector_profiler.h +149 -0
- package/src/headers/26/inspector_socket.h +60 -0
- package/src/headers/26/inspector_socket_server.h +110 -0
- package/src/headers/26/js_native_api.h +634 -0
- package/src/headers/26/js_native_api_types.h +244 -0
- package/src/headers/26/js_native_api_v8.h +485 -0
- package/src/headers/26/js_native_api_v8_internals.h +45 -0
- package/src/headers/26/js_stream.h +57 -0
- package/src/headers/26/json_utils.h +172 -0
- package/src/headers/26/large_pages/node_large_page.h +34 -0
- package/src/headers/26/lru_cache-inl.h +69 -0
- package/src/headers/26/memory_tracker-inl.h +461 -0
- package/src/headers/26/memory_tracker.h +341 -0
- package/src/headers/26/module_wrap.h +231 -0
- package/src/headers/26/ncrypto.h +2008 -0
- package/src/headers/26/node.h +1693 -0
- package/src/headers/26/node_api.h +265 -0
- package/src/headers/26/node_api_internals.h +48 -0
- package/src/headers/26/node_api_types.h +58 -0
- package/src/headers/26/node_binding.h +170 -0
- package/src/headers/26/node_blob.h +160 -0
- package/src/headers/26/node_bob-inl.h +36 -0
- package/src/headers/26/node_bob.h +107 -0
- package/src/headers/26/node_buffer.h +92 -0
- package/src/headers/26/node_builtins.h +239 -0
- package/src/headers/26/node_concepts.h +46 -0
- package/src/headers/26/node_config_file.h +77 -0
- package/src/headers/26/node_constants.h +82 -0
- package/src/headers/26/node_context_data.h +171 -0
- package/src/headers/26/node_contextify.h +261 -0
- package/src/headers/26/node_crypto.h +66 -0
- package/src/headers/26/node_debug.h +30 -0
- package/src/headers/26/node_diagnostics_channel.h +121 -0
- package/src/headers/26/node_dir.h +52 -0
- package/src/headers/26/node_dotenv.h +45 -0
- package/src/headers/26/node_errors.h +378 -0
- package/src/headers/26/node_exit_code.h +54 -0
- package/src/headers/26/node_external_reference.h +171 -0
- package/src/headers/26/node_ffi.h +212 -0
- package/src/headers/26/node_file-inl.h +421 -0
- package/src/headers/26/node_file.h +561 -0
- package/src/headers/26/node_file_utils.h +39 -0
- package/src/headers/26/node_hash.h +212 -0
- package/src/headers/26/node_http2.h +1202 -0
- package/src/headers/26/node_http2_state.h +159 -0
- package/src/headers/26/node_http_common-inl.h +199 -0
- package/src/headers/26/node_http_common.h +535 -0
- package/src/headers/26/node_i18n.h +132 -0
- package/src/headers/26/node_internals.h +485 -0
- package/src/headers/26/node_locks.h +184 -0
- package/src/headers/26/node_main_instance.h +67 -0
- package/src/headers/26/node_mem-inl.h +113 -0
- package/src/headers/26/node_mem.h +45 -0
- package/src/headers/26/node_messaging.h +389 -0
- package/src/headers/26/node_metadata.h +172 -0
- package/src/headers/26/node_modules.h +102 -0
- package/src/headers/26/node_mutex.h +323 -0
- package/src/headers/26/node_object_wrap.h +145 -0
- package/src/headers/26/node_options-inl.h +524 -0
- package/src/headers/26/node_options.h +710 -0
- package/src/headers/26/node_perf.h +167 -0
- package/src/headers/26/node_perf_common.h +103 -0
- package/src/headers/26/node_platform.h +290 -0
- package/src/headers/26/node_process-inl.h +26 -0
- package/src/headers/26/node_process.h +112 -0
- package/src/headers/26/node_profiling.h +38 -0
- package/src/headers/26/node_realm-inl.h +156 -0
- package/src/headers/26/node_realm.h +236 -0
- package/src/headers/26/node_report.h +43 -0
- package/src/headers/26/node_revert.h +82 -0
- package/src/headers/26/node_root_certs.h +2937 -0
- package/src/headers/26/node_sea.h +101 -0
- package/src/headers/26/node_shadow_realm.h +46 -0
- package/src/headers/26/node_snapshot_builder.h +57 -0
- package/src/headers/26/node_snapshotable.h +167 -0
- package/src/headers/26/node_sockaddr-inl.h +248 -0
- package/src/headers/26/node_sockaddr.h +459 -0
- package/src/headers/26/node_sqlite.h +607 -0
- package/src/headers/26/node_stat_watcher.h +73 -0
- package/src/headers/26/node_task_runner.h +92 -0
- package/src/headers/26/node_threadsafe_cow-inl.h +54 -0
- package/src/headers/26/node_threadsafe_cow.h +105 -0
- package/src/headers/26/node_union_bytes.h +81 -0
- package/src/headers/26/node_url.h +101 -0
- package/src/headers/26/node_url_pattern.h +118 -0
- package/src/headers/26/node_v8.h +78 -0
- package/src/headers/26/node_v8_embedder.h +26 -0
- package/src/headers/26/node_v8_platform-inl.h +96 -0
- package/src/headers/26/node_version.h +116 -0
- package/src/headers/26/node_wasi.h +184 -0
- package/src/headers/26/node_wasm_web_api.h +55 -0
- package/src/headers/26/node_watchdog.h +164 -0
- package/src/headers/26/node_webstorage.h +62 -0
- package/src/headers/26/node_worker.h +162 -0
- package/src/headers/26/path.h +36 -0
- package/src/headers/26/permission/boolean_permission.h +50 -0
- package/src/headers/26/permission/fs_permission.h +192 -0
- package/src/headers/26/permission/permission.h +155 -0
- package/src/headers/26/permission/permission_base.h +79 -0
- package/src/headers/26/pipe_wrap.h +80 -0
- package/src/headers/26/quic/application.h +279 -0
- package/src/headers/26/quic/arena.h +373 -0
- package/src/headers/26/quic/bindingdata.h +440 -0
- package/src/headers/26/quic/cid.h +127 -0
- package/src/headers/26/quic/data.h +358 -0
- package/src/headers/26/quic/defs.h +417 -0
- package/src/headers/26/quic/endpoint.h +519 -0
- package/src/headers/26/quic/guard.h +5 -0
- package/src/headers/26/quic/http3.h +25 -0
- package/src/headers/26/quic/packet.h +166 -0
- package/src/headers/26/quic/preferredaddress.h +72 -0
- package/src/headers/26/quic/session.h +770 -0
- package/src/headers/26/quic/session_manager.h +107 -0
- package/src/headers/26/quic/sessionticket.h +110 -0
- package/src/headers/26/quic/streams.h +518 -0
- package/src/headers/26/quic/tlscontext.h +353 -0
- package/src/headers/26/quic/tokens.h +263 -0
- package/src/headers/26/quic/transportparams.h +184 -0
- package/src/headers/26/req_wrap-inl.h +175 -0
- package/src/headers/26/req_wrap.h +79 -0
- package/src/headers/26/spawn_sync.h +243 -0
- package/src/headers/26/stream_base-inl.h +170 -0
- package/src/headers/26/stream_base.h +487 -0
- package/src/headers/26/stream_pipe.h +76 -0
- package/src/headers/26/stream_wrap.h +137 -0
- package/src/headers/26/string_bytes.h +114 -0
- package/src/headers/26/string_decoder-inl.h +31 -0
- package/src/headers/26/string_decoder.h +49 -0
- package/src/headers/26/tcp_wrap.h +138 -0
- package/src/headers/26/threadpoolwork-inl.h +70 -0
- package/src/headers/26/timer_wrap-inl.h +32 -0
- package/src/headers/26/timer_wrap.h +87 -0
- package/src/headers/26/timers.h +70 -0
- package/src/headers/26/tracing/agent.h +125 -0
- package/src/headers/26/tracing/agent_legacy.h +146 -0
- package/src/headers/26/tracing/agent_perfetto.h +145 -0
- package/src/headers/26/tracing/node_trace_buffer.h +91 -0
- package/src/headers/26/tracing/node_trace_writer.h +79 -0
- package/src/headers/26/tracing/trace_event.h +27 -0
- package/src/headers/26/tracing/trace_event_helper.h +40 -0
- package/src/headers/26/tracing/trace_event_legacy.h +1113 -0
- package/src/headers/26/tracing/trace_event_legacy_inl.h +711 -0
- package/src/headers/26/tracing/trace_event_perfetto.h +47 -0
- package/src/headers/26/tracing/traced_value.h +167 -0
- package/src/headers/26/tty_wrap.h +65 -0
- package/src/headers/26/udp_wrap.h +231 -0
- package/src/headers/26/undici_version.h +6 -0
- package/src/headers/26/util-inl.h +788 -0
- package/src/headers/26/util.h +1207 -0
- package/src/headers/26/v8-cpp-heap-external.h +56 -0
- package/src/headers/26/v8-external-memory-accounter.h +60 -0
- package/src/headers/26/v8-fast-api-calls.h +784 -0
- package/src/headers/26/v8-inspector-protocol.h +13 -0
- package/src/headers/26/v8-inspector.h +458 -0
- package/src/headers/26/v8-metrics.h +273 -0
- package/src/headers/26/v8-trace-categories.h +28 -0
- package/src/headers/26/v8-unwinder-state.h +30 -0
- package/src/headers/26/v8-util.h +549 -0
- package/src/headers/26/v8-value-serializer-version.h +24 -0
- package/src/headers/26/v8-version-string.h +38 -0
- package/src/headers/26/v8-wasm-trap-handler-posix.h +31 -0
- package/src/headers/26/v8-wasm-trap-handler-win.h +28 -0
- package/src/headers/26/zlib_version.h +6 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
4
|
+
|
|
5
|
+
#include <env.h>
|
|
6
|
+
#include <memory_tracker.h>
|
|
7
|
+
#include <ngtcp2/ngtcp2.h>
|
|
8
|
+
#include <node_sockaddr.h>
|
|
9
|
+
#include <optional>
|
|
10
|
+
#include "bindingdata.h"
|
|
11
|
+
#include "cid.h"
|
|
12
|
+
#include "data.h"
|
|
13
|
+
#include "tokens.h"
|
|
14
|
+
|
|
15
|
+
namespace node::quic {
|
|
16
|
+
|
|
17
|
+
class Endpoint;
|
|
18
|
+
class Session;
|
|
19
|
+
|
|
20
|
+
// The Transport Params are the set of configuration options that are sent to
|
|
21
|
+
// the remote peer. They communicate the protocol options the other peer
|
|
22
|
+
// should use when communicating with this session.
|
|
23
|
+
class TransportParams final {
|
|
24
|
+
public:
|
|
25
|
+
static void Initialize(Environment* env, v8::Local<v8::Object> target);
|
|
26
|
+
|
|
27
|
+
enum class Version : int {
|
|
28
|
+
V1 = NGTCP2_TRANSPORT_PARAMS_V1,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
static constexpr uint64_t DEFAULT_MAX_STREAM_DATA = 256 * 1024;
|
|
32
|
+
static constexpr uint64_t DEFAULT_MAX_DATA = 1 * 1024 * 1024;
|
|
33
|
+
static constexpr uint64_t DEFAULT_MAX_IDLE_TIMEOUT = 10; // seconds
|
|
34
|
+
static constexpr uint64_t DEFAULT_MAX_STREAMS_BIDI = 100;
|
|
35
|
+
static constexpr uint64_t DEFAULT_MAX_STREAMS_UNI = 3;
|
|
36
|
+
static constexpr uint64_t DEFAULT_ACTIVE_CONNECTION_ID_LIMIT = 2;
|
|
37
|
+
|
|
38
|
+
struct Config final {
|
|
39
|
+
Side side;
|
|
40
|
+
const CID& ocid;
|
|
41
|
+
const CID& retry_scid;
|
|
42
|
+
Config(Side side,
|
|
43
|
+
const CID& ocid = CID::kInvalid,
|
|
44
|
+
const CID& retry_scid = CID::kInvalid);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
struct Options final : public MemoryRetainer {
|
|
48
|
+
Version transportParamsVersion = Version::V1;
|
|
49
|
+
|
|
50
|
+
// Set only on server Sessions, the preferred address communicates the IP
|
|
51
|
+
// address and port that the server would prefer the client to use when
|
|
52
|
+
// communicating with it. See the QUIC specification for more detail on how
|
|
53
|
+
// the preferred address mechanism works:
|
|
54
|
+
// https://www.rfc-editor.org/rfc/rfc9000.html#name-servers-preferred-address
|
|
55
|
+
std::optional<SocketAddress> preferred_address_ipv4{};
|
|
56
|
+
std::optional<SocketAddress> preferred_address_ipv6{};
|
|
57
|
+
|
|
58
|
+
// The initial size of the flow control window of locally initiated streams.
|
|
59
|
+
// This is the maximum number of bytes that the *remote* endpoint can send
|
|
60
|
+
// when the connection is started.
|
|
61
|
+
// https://www.rfc-editor.org/rfc/rfc9000.html#section-18.2-4.16.1
|
|
62
|
+
uint64_t initial_max_stream_data_bidi_local = DEFAULT_MAX_STREAM_DATA;
|
|
63
|
+
|
|
64
|
+
// The initial size of the flow control window of remotely initiated
|
|
65
|
+
// streams. This is the maximum number of bytes that the remote endpoint can
|
|
66
|
+
// send when the connection is started.
|
|
67
|
+
// https://www.rfc-editor.org/rfc/rfc9000.html#section-18.2-4.18.1
|
|
68
|
+
uint64_t initial_max_stream_data_bidi_remote = DEFAULT_MAX_STREAM_DATA;
|
|
69
|
+
|
|
70
|
+
// The initial size of the flow control window of remotely initiated
|
|
71
|
+
// unidirectional streams. This is the maximum number of bytes that the
|
|
72
|
+
// remote endpoint can send when the connection is started.
|
|
73
|
+
// https://www.rfc-editor.org/rfc/rfc9000.html#section-18.2-4.20.1
|
|
74
|
+
uint64_t initial_max_stream_data_uni = DEFAULT_MAX_STREAM_DATA;
|
|
75
|
+
|
|
76
|
+
// The initial size of the session-level flow control window.
|
|
77
|
+
// https://www.rfc-editor.org/rfc/rfc9000.html#section-18.2-4.14.1
|
|
78
|
+
uint64_t initial_max_data = DEFAULT_MAX_DATA;
|
|
79
|
+
|
|
80
|
+
// The initial maximum number of concurrent bidirectional streams the remote
|
|
81
|
+
// endpoint is permitted to open.
|
|
82
|
+
// https://www.rfc-editor.org/rfc/rfc9000.html#section-18.2-4.22.1
|
|
83
|
+
uint64_t initial_max_streams_bidi = DEFAULT_MAX_STREAMS_BIDI;
|
|
84
|
+
|
|
85
|
+
// The initial maximum number of concurrent unidirectional streams the
|
|
86
|
+
// remote endpoint is permitted to open.
|
|
87
|
+
// https://www.rfc-editor.org/rfc/rfc9000.html#section-18.2-4.24.1
|
|
88
|
+
uint64_t initial_max_streams_uni = DEFAULT_MAX_STREAMS_UNI;
|
|
89
|
+
|
|
90
|
+
// The maximum amount of time that a Session is permitted to remain idle
|
|
91
|
+
// before it is silently closed and state is discarded.
|
|
92
|
+
// https://www.rfc-editor.org/rfc/rfc9000.html#section-18.2-4.4.1
|
|
93
|
+
uint64_t max_idle_timeout = DEFAULT_MAX_IDLE_TIMEOUT;
|
|
94
|
+
|
|
95
|
+
// The maximum number of Connection IDs that the peer can store. A single
|
|
96
|
+
// Session may have several connection IDs over it's lifetime.
|
|
97
|
+
// https://www.rfc-editor.org/rfc/rfc9000.html#section-18.2-6.2.1
|
|
98
|
+
uint64_t active_connection_id_limit = DEFAULT_ACTIVE_CONNECTION_ID_LIMIT;
|
|
99
|
+
|
|
100
|
+
// Establishes the exponent used in ACK Delay field in the ACK frame. See
|
|
101
|
+
// the QUIC specification for details. This is an advanced option that
|
|
102
|
+
// should rarely be modified and only if there is really good reason.
|
|
103
|
+
// https://www.rfc-editor.org/rfc/rfc9000.html#section-18.2-4.26.1
|
|
104
|
+
uint64_t ack_delay_exponent = NGTCP2_DEFAULT_ACK_DELAY_EXPONENT;
|
|
105
|
+
|
|
106
|
+
// The maximum amount of time by which the endpoint will delay sending
|
|
107
|
+
// acknowledgements. This is an advanced option that should rarely be
|
|
108
|
+
// modified and only if there is a really good reason. It is used to
|
|
109
|
+
// determine how long a Session will wait to determine that a packet has
|
|
110
|
+
// been lost.
|
|
111
|
+
// https://www.rfc-editor.org/rfc/rfc9000.html#section-18.2-4.28.1
|
|
112
|
+
uint64_t max_ack_delay = NGTCP2_DEFAULT_MAX_ACK_DELAY;
|
|
113
|
+
|
|
114
|
+
// The maximum size of DATAGRAM frames that the endpoint will accept.
|
|
115
|
+
// Setting the value to 0 will disable DATAGRAM support.
|
|
116
|
+
// https://datatracker.ietf.org/doc/html/rfc9221#section-3
|
|
117
|
+
uint16_t max_datagram_frame_size = kDefaultMaxPacketLength;
|
|
118
|
+
|
|
119
|
+
// When true, communicates that the Session does not support active
|
|
120
|
+
static const Options kDefault;
|
|
121
|
+
|
|
122
|
+
void MemoryInfo(MemoryTracker* tracker) const override;
|
|
123
|
+
SET_MEMORY_INFO_NAME(TransportParams::Options)
|
|
124
|
+
SET_SELF_SIZE(Options)
|
|
125
|
+
|
|
126
|
+
static v8::Maybe<Options> From(Environment* env,
|
|
127
|
+
v8::Local<v8::Value> value);
|
|
128
|
+
|
|
129
|
+
std::string ToString() const;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
explicit TransportParams();
|
|
133
|
+
|
|
134
|
+
// Creates an instance of TransportParams wrapping an existing const
|
|
135
|
+
// ngtcp2_transport_params pointer. Instances created this way are
|
|
136
|
+
// immutable.
|
|
137
|
+
TransportParams(const ngtcp2_transport_params* ptr);
|
|
138
|
+
|
|
139
|
+
TransportParams(const Config& config, const Options& options);
|
|
140
|
+
|
|
141
|
+
// Creates an instance of TransportParams by decoding the given buffer.
|
|
142
|
+
// If the parameters cannot be successfully decoded, the bool() operator
|
|
143
|
+
// will be false.
|
|
144
|
+
TransportParams(const ngtcp2_vec& buf, Version version = Version::V1);
|
|
145
|
+
|
|
146
|
+
void GenerateSessionTokens(Session* session);
|
|
147
|
+
|
|
148
|
+
operator const ngtcp2_transport_params&() const;
|
|
149
|
+
operator const ngtcp2_transport_params*() const;
|
|
150
|
+
|
|
151
|
+
operator bool() const;
|
|
152
|
+
|
|
153
|
+
uint64_t initial_max_streams_bidi() const;
|
|
154
|
+
uint64_t initial_max_streams_uni() const;
|
|
155
|
+
|
|
156
|
+
// Returns a Store containing the encoded transport parameters.
|
|
157
|
+
// If an error occurs during encoding, or if the parameters could
|
|
158
|
+
// not be encoded, an empty Store will be returned.
|
|
159
|
+
Store Encode(Environment* env, Version version = Version::V1) const;
|
|
160
|
+
|
|
161
|
+
// Returns the encoded size in bytes, or 0 on error.
|
|
162
|
+
ssize_t EncodedSize(Version version = Version::V1) const;
|
|
163
|
+
|
|
164
|
+
// Encode into a caller-provided buffer. Returns the number of bytes
|
|
165
|
+
// written, or a negative value on error.
|
|
166
|
+
ssize_t EncodeInto(uint8_t* buf,
|
|
167
|
+
size_t len,
|
|
168
|
+
Version version = Version::V1) const;
|
|
169
|
+
|
|
170
|
+
// Returns a JavaScript object representing the transport parameters.
|
|
171
|
+
v8::MaybeLocal<v8::Object> ToObject(Environment* env) const;
|
|
172
|
+
|
|
173
|
+
private:
|
|
174
|
+
void SetPreferredAddress(const SocketAddress& address);
|
|
175
|
+
void GeneratePreferredAddressToken(Session* session);
|
|
176
|
+
void GenerateStatelessResetToken(const Endpoint& endpoint, const CID& cid);
|
|
177
|
+
|
|
178
|
+
ngtcp2_transport_params params_{};
|
|
179
|
+
const ngtcp2_transport_params* ptr_;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
} // namespace node::quic
|
|
183
|
+
|
|
184
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
#ifndef SRC_REQ_WRAP_INL_H_
|
|
2
|
+
#define SRC_REQ_WRAP_INL_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "req_wrap.h"
|
|
7
|
+
#include "async_wrap-inl.h"
|
|
8
|
+
#include "uv.h"
|
|
9
|
+
|
|
10
|
+
namespace node {
|
|
11
|
+
|
|
12
|
+
ReqWrapBase::ReqWrapBase(Environment* env) {
|
|
13
|
+
CHECK(env->has_run_bootstrapping_code());
|
|
14
|
+
env->req_wrap_queue()->PushBack(this);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
template <typename T>
|
|
18
|
+
ReqWrap<T>::ReqWrap(Environment* env,
|
|
19
|
+
v8::Local<v8::Object> object,
|
|
20
|
+
AsyncWrap::ProviderType provider)
|
|
21
|
+
: AsyncWrap(env, object, provider),
|
|
22
|
+
ReqWrapBase(env) {
|
|
23
|
+
MakeWeak();
|
|
24
|
+
Reset();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
template <typename T>
|
|
28
|
+
ReqWrap<T>::~ReqWrap() {}
|
|
29
|
+
|
|
30
|
+
template <typename T>
|
|
31
|
+
void ReqWrap<T>::Dispatched() {
|
|
32
|
+
req_.data = this;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
template <typename T>
|
|
36
|
+
void ReqWrap<T>::Reset() {
|
|
37
|
+
original_callback_ = nullptr;
|
|
38
|
+
req_.data = nullptr;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
template <typename T>
|
|
42
|
+
ReqWrap<T>* ReqWrap<T>::from_req(T* req) {
|
|
43
|
+
return ContainerOf(&ReqWrap<T>::req_, req);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
template <typename T>
|
|
47
|
+
void ReqWrap<T>::Cancel() {
|
|
48
|
+
if (req_.data == this) // Only cancel if already dispatched.
|
|
49
|
+
uv_cancel(reinterpret_cast<uv_req_t*>(&req_));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
template <typename T>
|
|
53
|
+
bool ReqWrap<T>::IsDispatched() {
|
|
54
|
+
return req_.data != nullptr;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
template <typename T>
|
|
58
|
+
AsyncWrap* ReqWrap<T>::GetAsyncWrap() {
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Below is dark template magic designed to invoke libuv functions that
|
|
63
|
+
// initialize uv_req_t instances in a unified fashion, to allow easier
|
|
64
|
+
// tracking of active/inactive requests.
|
|
65
|
+
|
|
66
|
+
// Invoke a generic libuv function that initializes uv_req_t instances.
|
|
67
|
+
// This is, unfortunately, necessary since they come in three different
|
|
68
|
+
// variants that can not all be invoked in the same way:
|
|
69
|
+
// - int uv_foo(uv_loop_t* loop, uv_req_t* request, ...);
|
|
70
|
+
// - int uv_foo(uv_req_t* request, ...);
|
|
71
|
+
// - void uv_foo(uv_req_t* request, ...);
|
|
72
|
+
template <typename ReqT, typename T>
|
|
73
|
+
struct CallLibuvFunction;
|
|
74
|
+
|
|
75
|
+
// Detect `int uv_foo(uv_loop_t* loop, uv_req_t* request, ...);`.
|
|
76
|
+
template <typename ReqT, typename... Args>
|
|
77
|
+
struct CallLibuvFunction<ReqT, int(*)(uv_loop_t*, ReqT*, Args...)> {
|
|
78
|
+
using T = int(*)(uv_loop_t*, ReqT*, Args...);
|
|
79
|
+
template <typename... PassedArgs>
|
|
80
|
+
static int Call(T fn, uv_loop_t* loop, ReqT* req, PassedArgs... args) {
|
|
81
|
+
return fn(loop, req, args...);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// Detect `int uv_foo(uv_req_t* request, ...);`.
|
|
86
|
+
template <typename ReqT, typename... Args>
|
|
87
|
+
struct CallLibuvFunction<ReqT, int(*)(ReqT*, Args...)> {
|
|
88
|
+
using T = int(*)(ReqT*, Args...);
|
|
89
|
+
template <typename... PassedArgs>
|
|
90
|
+
static int Call(T fn, uv_loop_t* loop, ReqT* req, PassedArgs... args) {
|
|
91
|
+
return fn(req, args...);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// Detect `void uv_foo(uv_req_t* request, ...);`.
|
|
96
|
+
template <typename ReqT, typename... Args>
|
|
97
|
+
struct CallLibuvFunction<ReqT, void(*)(ReqT*, Args...)> {
|
|
98
|
+
using T = void(*)(ReqT*, Args...);
|
|
99
|
+
template <typename... PassedArgs>
|
|
100
|
+
static int Call(T fn, uv_loop_t* loop, ReqT* req, PassedArgs... args) {
|
|
101
|
+
fn(req, args...);
|
|
102
|
+
return 0;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// This is slightly darker magic: This template is 'applied' to each parameter
|
|
107
|
+
// passed to the libuv function. If the parameter type (aka `T`) is a
|
|
108
|
+
// function type, it is assumed that this it is the request callback, and a
|
|
109
|
+
// wrapper that calls the original callback is created.
|
|
110
|
+
// If not, the parameter is passed through verbatim.
|
|
111
|
+
template <typename ReqT, typename T>
|
|
112
|
+
struct MakeLibuvRequestCallback {
|
|
113
|
+
static T For(ReqWrap<ReqT>* req_wrap, T v) {
|
|
114
|
+
static_assert(!IsCallable<T>, "MakeLibuvRequestCallback missed a callback");
|
|
115
|
+
return v;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// Match the `void callback(uv_req_t*, ...);` signature that all libuv
|
|
120
|
+
// callbacks use.
|
|
121
|
+
template <typename ReqT, typename... Args>
|
|
122
|
+
struct MakeLibuvRequestCallback<ReqT, void(*)(ReqT*, Args...)> {
|
|
123
|
+
using F = void(*)(ReqT* req, Args... args);
|
|
124
|
+
|
|
125
|
+
static void Wrapper(ReqT* req, Args... args) {
|
|
126
|
+
BaseObjectPtr<ReqWrap<ReqT>> req_wrap{ReqWrap<ReqT>::from_req(req)};
|
|
127
|
+
req_wrap->Detach();
|
|
128
|
+
req_wrap->env()->DecreaseWaitingRequestCounter();
|
|
129
|
+
F original_callback = reinterpret_cast<F>(req_wrap->original_callback_);
|
|
130
|
+
original_callback(req, args...);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
static F For(ReqWrap<ReqT>* req_wrap, F v) {
|
|
134
|
+
CHECK_NULL(req_wrap->original_callback_);
|
|
135
|
+
req_wrap->original_callback_ =
|
|
136
|
+
reinterpret_cast<typename ReqWrap<ReqT>::callback_t>(v);
|
|
137
|
+
return Wrapper;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
template <typename T>
|
|
142
|
+
template <typename LibuvFunction, typename... Args>
|
|
143
|
+
int ReqWrap<T>::Dispatch(LibuvFunction fn, Args... args) {
|
|
144
|
+
Dispatched();
|
|
145
|
+
// This expands as:
|
|
146
|
+
//
|
|
147
|
+
// int err = fn(env()->event_loop(), req(), arg1, arg2, Wrapper, arg3, ...)
|
|
148
|
+
// ^ ^ ^
|
|
149
|
+
// | | |
|
|
150
|
+
// \-- Omitted if `fn` has no | |
|
|
151
|
+
// first `uv_loop_t*` argument | |
|
|
152
|
+
// | |
|
|
153
|
+
// A function callback whose first argument | |
|
|
154
|
+
// matches the libuv request type is replaced ---/ |
|
|
155
|
+
// by the `Wrapper` method defined above |
|
|
156
|
+
// |
|
|
157
|
+
// Other (non-function) arguments are passed -----/
|
|
158
|
+
// through verbatim
|
|
159
|
+
int err = CallLibuvFunction<T, LibuvFunction>::Call(
|
|
160
|
+
fn,
|
|
161
|
+
env()->event_loop(),
|
|
162
|
+
req(),
|
|
163
|
+
MakeLibuvRequestCallback<T, Args>::For(this, args)...);
|
|
164
|
+
if (err >= 0) {
|
|
165
|
+
ClearWeak();
|
|
166
|
+
env()->IncreaseWaitingRequestCounter();
|
|
167
|
+
}
|
|
168
|
+
return err;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
} // namespace node
|
|
172
|
+
|
|
173
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
174
|
+
|
|
175
|
+
#endif // SRC_REQ_WRAP_INL_H_
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
#ifndef SRC_REQ_WRAP_H_
|
|
2
|
+
#define SRC_REQ_WRAP_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "async_wrap.h"
|
|
7
|
+
#include "util.h"
|
|
8
|
+
#include "v8.h"
|
|
9
|
+
|
|
10
|
+
namespace node {
|
|
11
|
+
|
|
12
|
+
class Environment;
|
|
13
|
+
|
|
14
|
+
class ReqWrapBase {
|
|
15
|
+
public:
|
|
16
|
+
explicit inline ReqWrapBase(Environment* env);
|
|
17
|
+
|
|
18
|
+
virtual ~ReqWrapBase() = default;
|
|
19
|
+
|
|
20
|
+
virtual void Cancel() = 0;
|
|
21
|
+
virtual AsyncWrap* GetAsyncWrap() = 0;
|
|
22
|
+
|
|
23
|
+
private:
|
|
24
|
+
friend int GenDebugSymbols();
|
|
25
|
+
friend class Environment;
|
|
26
|
+
|
|
27
|
+
ListNode<ReqWrapBase> req_wrap_queue_;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
template <typename T>
|
|
31
|
+
class ReqWrap : public AsyncWrap, public ReqWrapBase {
|
|
32
|
+
public:
|
|
33
|
+
inline ReqWrap(Environment* env,
|
|
34
|
+
v8::Local<v8::Object> object,
|
|
35
|
+
AsyncWrap::ProviderType provider);
|
|
36
|
+
inline ~ReqWrap() override;
|
|
37
|
+
// Call this after the req has been dispatched, if that did not already
|
|
38
|
+
// happen by using Dispatch().
|
|
39
|
+
inline void Dispatched();
|
|
40
|
+
// Call this after a request has finished, if re-using this object is planned.
|
|
41
|
+
inline void Reset();
|
|
42
|
+
T* req() { return &req_; }
|
|
43
|
+
inline void Cancel() final;
|
|
44
|
+
inline AsyncWrap* GetAsyncWrap() override;
|
|
45
|
+
|
|
46
|
+
static ReqWrap* from_req(T* req);
|
|
47
|
+
|
|
48
|
+
template <typename LibuvFunction, typename... Args>
|
|
49
|
+
inline int Dispatch(LibuvFunction fn, Args... args);
|
|
50
|
+
|
|
51
|
+
inline bool IsDispatched();
|
|
52
|
+
|
|
53
|
+
private:
|
|
54
|
+
friend int GenDebugSymbols();
|
|
55
|
+
|
|
56
|
+
// Adding `friend struct MakeLibuvRequestCallback` is not enough anymore
|
|
57
|
+
// for some reason. Consider this private.
|
|
58
|
+
public:
|
|
59
|
+
typedef void (*callback_t)();
|
|
60
|
+
callback_t original_callback_ = nullptr;
|
|
61
|
+
|
|
62
|
+
protected:
|
|
63
|
+
// req_wrap_queue_ needs to be at a fixed offset from the start of the class
|
|
64
|
+
// because it is used by ContainerOf to calculate the address of the embedding
|
|
65
|
+
// ReqWrap. ContainerOf compiles down to simple, fixed pointer arithmetic. It
|
|
66
|
+
// is also used by src/node_postmortem_metadata.cc to calculate offsets and
|
|
67
|
+
// generate debug symbols for ReqWrap, which assumes that the position of
|
|
68
|
+
// members in memory are predictable. sizeof(req_) depends on the type of T,
|
|
69
|
+
// so req_wrap_queue_ would no longer be at a fixed offset if it came after
|
|
70
|
+
// req_. For more information please refer to
|
|
71
|
+
// `doc/contributing/node-postmortem-support.md`
|
|
72
|
+
T req_;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
} // namespace node
|
|
76
|
+
|
|
77
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
78
|
+
|
|
79
|
+
#endif // SRC_REQ_WRAP_H_
|
|
@@ -0,0 +1,243 @@
|
|
|
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_SPAWN_SYNC_H_
|
|
23
|
+
#define SRC_SPAWN_SYNC_H_
|
|
24
|
+
|
|
25
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
26
|
+
|
|
27
|
+
#include "node_buffer.h"
|
|
28
|
+
#include "uv.h"
|
|
29
|
+
#include "v8.h"
|
|
30
|
+
|
|
31
|
+
namespace node {
|
|
32
|
+
|
|
33
|
+
class ExternalReferenceRegistry;
|
|
34
|
+
class SyncProcessOutputBuffer;
|
|
35
|
+
class SyncProcessStdioPipe;
|
|
36
|
+
class SyncProcessRunner;
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class SyncProcessOutputBuffer {
|
|
40
|
+
static const unsigned int kBufferSize = 65536;
|
|
41
|
+
|
|
42
|
+
public:
|
|
43
|
+
inline SyncProcessOutputBuffer() = default;
|
|
44
|
+
|
|
45
|
+
inline void OnAlloc(size_t suggested_size, uv_buf_t* buf) const;
|
|
46
|
+
inline void OnRead(const uv_buf_t* buf, size_t nread);
|
|
47
|
+
|
|
48
|
+
inline size_t Copy(char* dest) const;
|
|
49
|
+
|
|
50
|
+
inline unsigned int available() const;
|
|
51
|
+
inline unsigned int used() const;
|
|
52
|
+
|
|
53
|
+
inline SyncProcessOutputBuffer* next() const;
|
|
54
|
+
inline void set_next(SyncProcessOutputBuffer* next);
|
|
55
|
+
|
|
56
|
+
private:
|
|
57
|
+
// Use unsigned int because that's what `uv_buf_init` takes.
|
|
58
|
+
mutable char data_[kBufferSize];
|
|
59
|
+
unsigned int used_ = 0;
|
|
60
|
+
|
|
61
|
+
SyncProcessOutputBuffer* next_ = nullptr;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class SyncProcessStdioPipe {
|
|
66
|
+
enum Lifecycle {
|
|
67
|
+
kUninitialized = 0,
|
|
68
|
+
kInitialized,
|
|
69
|
+
kStarted,
|
|
70
|
+
kClosing,
|
|
71
|
+
kClosed
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
public:
|
|
75
|
+
SyncProcessStdioPipe(SyncProcessRunner* process_handler,
|
|
76
|
+
bool readable,
|
|
77
|
+
bool writable,
|
|
78
|
+
uv_buf_t input_buffer);
|
|
79
|
+
~SyncProcessStdioPipe();
|
|
80
|
+
|
|
81
|
+
int Initialize(uv_loop_t* loop);
|
|
82
|
+
int Start();
|
|
83
|
+
void Close();
|
|
84
|
+
|
|
85
|
+
v8::MaybeLocal<v8::Object> GetOutputAsBuffer(Environment* env) const;
|
|
86
|
+
|
|
87
|
+
inline bool readable() const;
|
|
88
|
+
inline bool writable() const;
|
|
89
|
+
inline uv_stdio_flags uv_flags() const;
|
|
90
|
+
|
|
91
|
+
inline uv_pipe_t* uv_pipe() const;
|
|
92
|
+
inline uv_stream_t* uv_stream() const;
|
|
93
|
+
inline uv_handle_t* uv_handle() const;
|
|
94
|
+
|
|
95
|
+
private:
|
|
96
|
+
inline size_t OutputLength() const;
|
|
97
|
+
inline void CopyOutput(char* dest) const;
|
|
98
|
+
|
|
99
|
+
inline void OnAlloc(size_t suggested_size, uv_buf_t* buf);
|
|
100
|
+
inline void OnRead(const uv_buf_t* buf, ssize_t nread);
|
|
101
|
+
inline void OnWriteDone(int result);
|
|
102
|
+
inline void OnShutdownDone(int result);
|
|
103
|
+
inline void OnClose();
|
|
104
|
+
|
|
105
|
+
inline void SetError(int error);
|
|
106
|
+
|
|
107
|
+
static void AllocCallback(uv_handle_t* handle,
|
|
108
|
+
size_t suggested_size,
|
|
109
|
+
uv_buf_t* buf);
|
|
110
|
+
static void ReadCallback(uv_stream_t* stream,
|
|
111
|
+
ssize_t nread,
|
|
112
|
+
const uv_buf_t* buf);
|
|
113
|
+
static void WriteCallback(uv_write_t* req, int result);
|
|
114
|
+
static void ShutdownCallback(uv_shutdown_t* req, int result);
|
|
115
|
+
static void CloseCallback(uv_handle_t* handle);
|
|
116
|
+
|
|
117
|
+
SyncProcessRunner* process_handler_;
|
|
118
|
+
|
|
119
|
+
bool readable_;
|
|
120
|
+
bool writable_;
|
|
121
|
+
uv_buf_t input_buffer_;
|
|
122
|
+
|
|
123
|
+
SyncProcessOutputBuffer* first_output_buffer_;
|
|
124
|
+
SyncProcessOutputBuffer* last_output_buffer_;
|
|
125
|
+
|
|
126
|
+
mutable uv_pipe_t uv_pipe_;
|
|
127
|
+
uv_write_t write_req_;
|
|
128
|
+
uv_shutdown_t shutdown_req_;
|
|
129
|
+
|
|
130
|
+
Lifecycle lifecycle_;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
class SyncProcessRunner {
|
|
135
|
+
enum Lifecycle {
|
|
136
|
+
kUninitialized = 0,
|
|
137
|
+
kInitialized,
|
|
138
|
+
kHandlesClosed
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
public:
|
|
142
|
+
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
|
|
143
|
+
static void Initialize(v8::Local<v8::Object> target,
|
|
144
|
+
v8::Local<v8::Value> unused,
|
|
145
|
+
v8::Local<v8::Context> context,
|
|
146
|
+
void* priv);
|
|
147
|
+
static void Spawn(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
148
|
+
|
|
149
|
+
private:
|
|
150
|
+
friend class SyncProcessStdioPipe;
|
|
151
|
+
|
|
152
|
+
explicit SyncProcessRunner(Environment* env_);
|
|
153
|
+
~SyncProcessRunner();
|
|
154
|
+
|
|
155
|
+
inline Environment* env() const;
|
|
156
|
+
|
|
157
|
+
v8::MaybeLocal<v8::Object> Run(v8::Local<v8::Value> options);
|
|
158
|
+
v8::Maybe<void> TryInitializeAndRunLoop(v8::Local<v8::Value> options);
|
|
159
|
+
void CloseHandlesAndDeleteLoop();
|
|
160
|
+
|
|
161
|
+
void CloseStdioPipes();
|
|
162
|
+
void CloseKillTimer();
|
|
163
|
+
|
|
164
|
+
void Kill();
|
|
165
|
+
void IncrementBufferSizeAndCheckOverflow(ssize_t length);
|
|
166
|
+
|
|
167
|
+
void OnExit(int64_t exit_status, int term_signal);
|
|
168
|
+
void OnKillTimerTimeout();
|
|
169
|
+
|
|
170
|
+
int GetError();
|
|
171
|
+
void SetError(int error);
|
|
172
|
+
void SetPipeError(int pipe_error);
|
|
173
|
+
|
|
174
|
+
v8::MaybeLocal<v8::Object> BuildResultObject();
|
|
175
|
+
v8::MaybeLocal<v8::Array> BuildOutputArray();
|
|
176
|
+
|
|
177
|
+
v8::Maybe<int> ParseOptions(v8::Local<v8::Value> js_value);
|
|
178
|
+
v8::Maybe<int> ParseStdioOptions(v8::Local<v8::Value> js_value);
|
|
179
|
+
v8::Maybe<int> ParseStdioOption(int child_fd,
|
|
180
|
+
v8::Local<v8::Object> js_stdio_option);
|
|
181
|
+
|
|
182
|
+
inline int AddStdioIgnore(uint32_t child_fd);
|
|
183
|
+
inline int AddStdioPipe(uint32_t child_fd,
|
|
184
|
+
bool readable,
|
|
185
|
+
bool writable,
|
|
186
|
+
uv_buf_t input_buffer);
|
|
187
|
+
inline int AddStdioInheritFD(uint32_t child_fd, int inherit_fd);
|
|
188
|
+
|
|
189
|
+
static bool IsSet(v8::Local<v8::Value> value);
|
|
190
|
+
v8::Maybe<int> CopyJsString(v8::Local<v8::Value> js_value,
|
|
191
|
+
const char** target);
|
|
192
|
+
v8::Maybe<int> CopyJsStringArray(v8::Local<v8::Value> js_value,
|
|
193
|
+
char** target);
|
|
194
|
+
|
|
195
|
+
static void ExitCallback(uv_process_t* handle,
|
|
196
|
+
int64_t exit_status,
|
|
197
|
+
int term_signal);
|
|
198
|
+
static void KillTimerCallback(uv_timer_t* handle);
|
|
199
|
+
static void KillTimerCloseCallback(uv_handle_t* handle);
|
|
200
|
+
|
|
201
|
+
double max_buffer_;
|
|
202
|
+
uint64_t timeout_;
|
|
203
|
+
int kill_signal_;
|
|
204
|
+
|
|
205
|
+
uv_loop_t* uv_loop_;
|
|
206
|
+
|
|
207
|
+
uint32_t stdio_count_;
|
|
208
|
+
std::vector<uv_stdio_container_t> uv_stdio_containers_;
|
|
209
|
+
std::vector<std::unique_ptr<SyncProcessStdioPipe>> stdio_pipes_;
|
|
210
|
+
bool stdio_pipes_initialized_;
|
|
211
|
+
|
|
212
|
+
uv_process_options_t uv_process_options_;
|
|
213
|
+
std::unique_ptr<const char[]> file_buffer_;
|
|
214
|
+
std::unique_ptr<char[]> args_buffer_;
|
|
215
|
+
std::unique_ptr<char[]> env_buffer_;
|
|
216
|
+
std::unique_ptr<const char[]> cwd_buffer_;
|
|
217
|
+
|
|
218
|
+
uv_process_t uv_process_;
|
|
219
|
+
bool killed_;
|
|
220
|
+
|
|
221
|
+
size_t buffered_output_size_;
|
|
222
|
+
int64_t exit_status_;
|
|
223
|
+
int term_signal_;
|
|
224
|
+
|
|
225
|
+
uv_timer_t uv_timer_;
|
|
226
|
+
bool kill_timer_initialized_;
|
|
227
|
+
|
|
228
|
+
// Errors that happen in one of the pipe handlers are stored in the
|
|
229
|
+
// `pipe_error` field. They are treated as "low-priority", only to be
|
|
230
|
+
// reported if no more serious errors happened.
|
|
231
|
+
int error_;
|
|
232
|
+
int pipe_error_;
|
|
233
|
+
|
|
234
|
+
Lifecycle lifecycle_;
|
|
235
|
+
|
|
236
|
+
Environment* env_;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
} // namespace node
|
|
240
|
+
|
|
241
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
242
|
+
|
|
243
|
+
#endif // SRC_SPAWN_SYNC_H_
|