@encharm/cws 4.3.0 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -7
- package/dist/bindings/cws_darwin_arm64_node108.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node115.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node83.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node93.node +0 -0
- package/dist/bindings/cws_darwin_x64_node108.node +0 -0
- package/dist/bindings/cws_darwin_x64_node115.node +0 -0
- package/dist/bindings/cws_darwin_x64_node83.node +0 -0
- package/dist/bindings/cws_darwin_x64_node93.node +0 -0
- package/dist/bindings/cws_linux_arm64_node108.node +0 -0
- package/dist/bindings/cws_linux_arm64_node115.node +0 -0
- package/dist/bindings/cws_linux_arm64_node83.node +0 -0
- package/dist/bindings/cws_linux_arm64_node93.node +0 -0
- package/dist/bindings/cws_linux_x64_node108.node +0 -0
- package/dist/bindings/cws_linux_x64_node115.node +0 -0
- package/dist/bindings/cws_linux_x64_node83.node +0 -0
- package/dist/bindings/cws_linux_x64_node93.node +0 -0
- package/dist/bindings/cws_win32_x64_node108.node +0 -0
- package/dist/bindings/cws_win32_x64_node115.node +0 -0
- package/dist/bindings/cws_win32_x64_node83.node +0 -0
- package/dist/bindings/cws_win32_x64_node93.node +0 -0
- package/dist/shared.js +1 -1
- package/package.json +5 -5
- package/src/Addon.cpp +4 -12
- package/src/Addon.h +55 -90
- package/src/Socket.h +1 -0
- package/src/cSNode.cpp +3 -8
- package/src/headers/20/acorn_version.h +6 -0
- package/src/headers/20/aliased_buffer-inl.h +243 -0
- package/src/headers/20/aliased_buffer.h +206 -0
- package/src/headers/20/aliased_struct-inl.h +54 -0
- package/src/headers/20/aliased_struct.h +63 -0
- package/src/headers/20/async_wrap-inl.h +93 -0
- package/src/headers/20/async_wrap.h +252 -0
- package/src/headers/20/base64-inl.h +193 -0
- package/src/headers/20/base64.h +53 -0
- package/src/headers/20/base64_version.h +6 -0
- package/src/headers/20/base_object-inl.h +316 -0
- package/src/headers/20/base_object.h +320 -0
- package/src/headers/20/base_object_types.h +73 -0
- package/src/headers/20/blob_serializer_deserializer-inl.h +361 -0
- package/src/headers/20/blob_serializer_deserializer.h +132 -0
- package/src/headers/20/callback_queue-inl.h +97 -0
- package/src/headers/20/callback_queue.h +79 -0
- package/src/headers/20/cares_wrap.h +524 -0
- package/src/headers/20/cjs_module_lexer_version.h +6 -0
- package/src/headers/20/cleanup_queue-inl.h +62 -0
- package/src/headers/20/cleanup_queue.h +85 -0
- package/src/headers/20/connect_wrap.h +26 -0
- package/src/headers/20/connection_wrap.h +29 -0
- package/src/headers/20/cppgc/DEPS +8 -0
- package/src/headers/20/cppgc/OWNERS +2 -0
- package/src/headers/20/cppgc/README.md +135 -0
- package/src/headers/20/cppgc/allocation.h +310 -0
- package/src/headers/20/cppgc/common.h +28 -0
- package/src/headers/20/cppgc/cross-thread-persistent.h +466 -0
- package/src/headers/20/cppgc/custom-space.h +97 -0
- package/src/headers/20/cppgc/default-platform.h +67 -0
- package/src/headers/20/cppgc/ephemeron-pair.h +30 -0
- package/src/headers/20/cppgc/explicit-management.h +100 -0
- package/src/headers/20/cppgc/garbage-collected.h +106 -0
- package/src/headers/20/cppgc/heap-consistency.h +309 -0
- package/src/headers/20/cppgc/heap-handle.h +48 -0
- package/src/headers/20/cppgc/heap-state.h +82 -0
- package/src/headers/20/cppgc/heap-statistics.h +120 -0
- package/src/headers/20/cppgc/heap.h +202 -0
- package/src/headers/20/cppgc/internal/api-constants.h +68 -0
- package/src/headers/20/cppgc/internal/atomic-entry-flag.h +48 -0
- package/src/headers/20/cppgc/internal/base-page-handle.h +45 -0
- package/src/headers/20/cppgc/internal/caged-heap-local-data.h +111 -0
- package/src/headers/20/cppgc/internal/caged-heap.h +61 -0
- package/src/headers/20/cppgc/internal/compiler-specific.h +38 -0
- package/src/headers/20/cppgc/internal/finalizer-trait.h +93 -0
- package/src/headers/20/cppgc/internal/gc-info.h +157 -0
- package/src/headers/20/cppgc/internal/logging.h +50 -0
- package/src/headers/20/cppgc/internal/member-storage.h +248 -0
- package/src/headers/20/cppgc/internal/name-trait.h +137 -0
- package/src/headers/20/cppgc/internal/persistent-node.h +214 -0
- package/src/headers/20/cppgc/internal/pointer-policies.h +243 -0
- package/src/headers/20/cppgc/internal/write-barrier.h +487 -0
- package/src/headers/20/cppgc/liveness-broker.h +78 -0
- package/src/headers/20/cppgc/macros.h +35 -0
- package/src/headers/20/cppgc/member.h +604 -0
- package/src/headers/20/cppgc/name-provider.h +65 -0
- package/src/headers/20/cppgc/object-size-trait.h +58 -0
- package/src/headers/20/cppgc/persistent.h +373 -0
- package/src/headers/20/cppgc/platform.h +158 -0
- package/src/headers/20/cppgc/prefinalizer.h +75 -0
- package/src/headers/20/cppgc/process-heap-statistics.h +36 -0
- package/src/headers/20/cppgc/sentinel-pointer.h +32 -0
- package/src/headers/20/cppgc/source-location.h +92 -0
- package/src/headers/20/cppgc/testing.h +106 -0
- package/src/headers/20/cppgc/trace-trait.h +120 -0
- package/src/headers/20/cppgc/type-traits.h +250 -0
- package/src/headers/20/cppgc/visitor.h +426 -0
- package/src/headers/20/crypto/crypto_clienthello.h +131 -0
- package/src/headers/20/crypto/crypto_context.h +160 -0
- package/src/headers/20/crypto/crypto_keys.h +416 -0
- package/src/headers/20/crypto/crypto_tls.h +295 -0
- package/src/headers/20/crypto/crypto_util.h +805 -0
- package/src/headers/20/crypto_clienthello.h +131 -0
- package/src/headers/20/debug_utils-inl.h +226 -0
- package/src/headers/20/debug_utils.h +188 -0
- package/src/headers/20/diagnosticfilename-inl.h +33 -0
- package/src/headers/20/encoding_binding.h +59 -0
- package/src/headers/20/env-inl.h +923 -0
- package/src/headers/20/env.h +1193 -0
- package/src/headers/20/env_properties.h +444 -0
- package/src/headers/20/handle_wrap.h +123 -0
- package/src/headers/20/histogram-inl.h +107 -0
- package/src/headers/20/histogram.h +240 -0
- package/src/headers/20/inspector_agent.h +144 -0
- package/src/headers/20/inspector_io.h +78 -0
- package/src/headers/20/inspector_profiler.h +149 -0
- package/src/headers/20/inspector_socket.h +60 -0
- package/src/headers/20/inspector_socket_server.h +110 -0
- package/src/headers/20/js_native_api.h +591 -0
- package/src/headers/20/js_native_api_types.h +168 -0
- package/src/headers/20/js_native_api_v8.h +426 -0
- package/src/headers/20/js_native_api_v8_internals.h +39 -0
- package/src/headers/20/js_stream.h +52 -0
- package/src/headers/20/json_parser.h +38 -0
- package/src/headers/20/json_utils.h +172 -0
- package/src/headers/20/memory_tracker-inl.h +356 -0
- package/src/headers/20/memory_tracker.h +289 -0
- package/src/headers/20/module_wrap.h +117 -0
- package/src/headers/20/node.h +1514 -0
- package/src/headers/20/node_api.h +260 -0
- package/src/headers/20/node_api_internals.h +42 -0
- package/src/headers/20/node_api_types.h +52 -0
- package/src/headers/20/node_binding.h +142 -0
- package/src/headers/20/node_blob.h +159 -0
- package/src/headers/20/node_bob-inl.h +36 -0
- package/src/headers/20/node_bob.h +107 -0
- package/src/headers/20/node_buffer.h +92 -0
- package/src/headers/20/node_builtins.h +197 -0
- package/src/headers/20/node_constants.h +79 -0
- package/src/headers/20/node_context_data.h +98 -0
- package/src/headers/20/node_contextify.h +182 -0
- package/src/headers/20/node_crypto.h +56 -0
- package/src/headers/20/node_dir.h +52 -0
- package/src/headers/20/node_dotenv.h +37 -0
- package/src/headers/20/node_errors.h +313 -0
- package/src/headers/20/node_exit_code.h +54 -0
- package/src/headers/20/node_external_reference.h +172 -0
- package/src/headers/20/node_file-inl.h +357 -0
- package/src/headers/20/node_file.h +524 -0
- package/src/headers/20/node_http2.h +1146 -0
- package/src/headers/20/node_http2_state.h +147 -0
- package/src/headers/20/node_http_common-inl.h +201 -0
- package/src/headers/20/node_http_common.h +532 -0
- package/src/headers/20/node_i18n.h +145 -0
- package/src/headers/20/node_internals.h +443 -0
- package/src/headers/20/node_main_instance.h +67 -0
- package/src/headers/20/node_mem-inl.h +112 -0
- package/src/headers/20/node_mem.h +45 -0
- package/src/headers/20/node_messaging.h +377 -0
- package/src/headers/20/node_metadata.h +138 -0
- package/src/headers/20/node_mutex.h +323 -0
- package/src/headers/20/node_object_wrap.h +132 -0
- package/src/headers/20/node_options-inl.h +478 -0
- package/src/headers/20/node_options.h +538 -0
- package/src/headers/20/node_perf.h +166 -0
- package/src/headers/20/node_perf_common.h +98 -0
- package/src/headers/20/node_platform.h +195 -0
- package/src/headers/20/node_process-inl.h +26 -0
- package/src/headers/20/node_process.h +99 -0
- package/src/headers/20/node_realm-inl.h +139 -0
- package/src/headers/20/node_realm.h +184 -0
- package/src/headers/20/node_report.h +42 -0
- package/src/headers/20/node_revert.h +82 -0
- package/src/headers/20/node_root_certs.h +3443 -0
- package/src/headers/20/node_sea.h +56 -0
- package/src/headers/20/node_shadow_realm.h +46 -0
- package/src/headers/20/node_snapshot_builder.h +54 -0
- package/src/headers/20/node_snapshotable.h +164 -0
- package/src/headers/20/node_sockaddr-inl.h +266 -0
- package/src/headers/20/node_sockaddr.h +405 -0
- package/src/headers/20/node_stat_watcher.h +73 -0
- package/src/headers/20/node_threadsafe_cow-inl.h +54 -0
- package/src/headers/20/node_threadsafe_cow.h +105 -0
- package/src/headers/20/node_union_bytes.h +81 -0
- package/src/headers/20/node_url.h +92 -0
- package/src/headers/20/node_v8.h +77 -0
- package/src/headers/20/node_v8_platform-inl.h +205 -0
- package/src/headers/20/node_version.h +109 -0
- package/src/headers/20/node_wasi.h +184 -0
- package/src/headers/20/node_wasm_web_api.h +55 -0
- package/src/headers/20/node_watchdog.h +154 -0
- package/src/headers/20/node_worker.h +151 -0
- package/src/headers/20/permission/child_process_permission.h +28 -0
- package/src/headers/20/permission/fs_permission.h +152 -0
- package/src/headers/20/permission/permission.h +71 -0
- package/src/headers/20/permission/permission_base.h +49 -0
- package/src/headers/20/permission/worker_permission.h +28 -0
- package/src/headers/20/pipe_wrap.h +80 -0
- package/src/headers/20/req_wrap-inl.h +171 -0
- package/src/headers/20/req_wrap.h +77 -0
- package/src/headers/20/spawn_sync.h +242 -0
- package/src/headers/20/stream_base-inl.h +173 -0
- package/src/headers/20/stream_base.h +469 -0
- package/src/headers/20/stream_pipe.h +76 -0
- package/src/headers/20/stream_wrap.h +131 -0
- package/src/headers/20/string_bytes.h +120 -0
- package/src/headers/20/string_decoder-inl.h +37 -0
- package/src/headers/20/string_decoder.h +50 -0
- package/src/headers/20/string_search.h +638 -0
- package/src/headers/20/tcp_wrap.h +105 -0
- package/src/headers/20/threadpoolwork-inl.h +70 -0
- package/src/headers/20/timer_wrap-inl.h +32 -0
- package/src/headers/20/timer_wrap.h +85 -0
- package/src/headers/20/timers.h +70 -0
- package/src/headers/20/tracing/agent.h +195 -0
- package/src/headers/20/tracing/trace_event.h +720 -0
- package/src/headers/20/tracing/trace_event_common.h +1109 -0
- package/src/headers/20/tty_wrap.h +65 -0
- package/src/headers/20/udp_wrap.h +227 -0
- package/src/headers/20/undici_version.h +6 -0
- package/src/headers/20/util-inl.h +623 -0
- package/src/headers/20/util.h +988 -0
- package/src/headers/20/v8-cppgc.h +245 -0
- package/src/headers/20/v8-fast-api-calls.h +957 -0
- package/dist/bindings/cws_darwin_arm64_node64.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node72.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node79.node +0 -0
- package/dist/bindings/cws_darwin_x64_node64.node +0 -0
- package/dist/bindings/cws_darwin_x64_node72.node +0 -0
- package/dist/bindings/cws_darwin_x64_node79.node +0 -0
- package/dist/bindings/cws_linux_x64_node64.node +0 -0
- package/dist/bindings/cws_linux_x64_node72.node +0 -0
- package/dist/bindings/cws_linux_x64_node79.node +0 -0
- package/dist/bindings/cws_win32_x64_node64.node +0 -0
- package/dist/bindings/cws_win32_x64_node72.node +0 -0
- package/dist/bindings/cws_win32_x64_node79.node +0 -0
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
#ifndef SRC_NODE_SOCKADDR_H_
|
|
2
|
+
#define SRC_NODE_SOCKADDR_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "env.h"
|
|
7
|
+
#include "memory_tracker.h"
|
|
8
|
+
#include "base_object.h"
|
|
9
|
+
#include "node.h"
|
|
10
|
+
#include "node_worker.h"
|
|
11
|
+
#include "uv.h"
|
|
12
|
+
#include "v8.h"
|
|
13
|
+
|
|
14
|
+
#include <memory>
|
|
15
|
+
#include <string>
|
|
16
|
+
#include <list>
|
|
17
|
+
#include <unordered_map>
|
|
18
|
+
|
|
19
|
+
namespace node {
|
|
20
|
+
|
|
21
|
+
class Environment;
|
|
22
|
+
|
|
23
|
+
class SocketAddress : public MemoryRetainer {
|
|
24
|
+
public:
|
|
25
|
+
enum class CompareResult {
|
|
26
|
+
NOT_COMPARABLE = -2,
|
|
27
|
+
LESS_THAN,
|
|
28
|
+
SAME,
|
|
29
|
+
GREATER_THAN
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
struct Hash {
|
|
33
|
+
size_t operator()(const SocketAddress& addr) const;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
inline bool operator==(const SocketAddress& other) const;
|
|
37
|
+
inline bool operator!=(const SocketAddress& other) const;
|
|
38
|
+
|
|
39
|
+
inline bool operator<(const SocketAddress& other) const;
|
|
40
|
+
inline bool operator>(const SocketAddress& other) const;
|
|
41
|
+
inline bool operator<=(const SocketAddress& other) const;
|
|
42
|
+
inline bool operator>=(const SocketAddress& other) const;
|
|
43
|
+
|
|
44
|
+
inline static bool is_numeric_host(const char* hostname);
|
|
45
|
+
inline static bool is_numeric_host(const char* hostname, int family);
|
|
46
|
+
|
|
47
|
+
// Returns true if converting {family, host, port} to *addr succeeded.
|
|
48
|
+
static bool ToSockAddr(
|
|
49
|
+
int32_t family,
|
|
50
|
+
const char* host,
|
|
51
|
+
uint32_t port,
|
|
52
|
+
sockaddr_storage* addr);
|
|
53
|
+
|
|
54
|
+
// Returns true if converting {family, host, port} to *addr succeeded.
|
|
55
|
+
static bool New(
|
|
56
|
+
int32_t family,
|
|
57
|
+
const char* host,
|
|
58
|
+
uint32_t port,
|
|
59
|
+
SocketAddress* addr);
|
|
60
|
+
|
|
61
|
+
static bool New(
|
|
62
|
+
const char* host,
|
|
63
|
+
uint32_t port,
|
|
64
|
+
SocketAddress* addr);
|
|
65
|
+
|
|
66
|
+
// Returns the port for an IPv4 or IPv6 address.
|
|
67
|
+
inline static int GetPort(const sockaddr* addr);
|
|
68
|
+
inline static int GetPort(const sockaddr_storage* addr);
|
|
69
|
+
|
|
70
|
+
// Returns the numeric host as a string for an IPv4 or IPv6 address.
|
|
71
|
+
inline static std::string GetAddress(const sockaddr* addr);
|
|
72
|
+
inline static std::string GetAddress(const sockaddr_storage* addr);
|
|
73
|
+
|
|
74
|
+
// Returns the struct length for an IPv4, IPv6 or UNIX domain.
|
|
75
|
+
inline static size_t GetLength(const sockaddr* addr);
|
|
76
|
+
inline static size_t GetLength(const sockaddr_storage* addr);
|
|
77
|
+
|
|
78
|
+
SocketAddress() = default;
|
|
79
|
+
|
|
80
|
+
inline explicit SocketAddress(const sockaddr* addr);
|
|
81
|
+
inline SocketAddress(const SocketAddress& addr);
|
|
82
|
+
inline SocketAddress& operator=(const sockaddr* other);
|
|
83
|
+
inline SocketAddress& operator=(const SocketAddress& other);
|
|
84
|
+
|
|
85
|
+
inline const sockaddr& operator*() const;
|
|
86
|
+
inline const sockaddr* operator->() const;
|
|
87
|
+
|
|
88
|
+
inline const sockaddr* data() const;
|
|
89
|
+
inline const uint8_t* raw() const;
|
|
90
|
+
inline sockaddr* storage();
|
|
91
|
+
inline size_t length() const;
|
|
92
|
+
|
|
93
|
+
inline int family() const;
|
|
94
|
+
inline std::string address() const;
|
|
95
|
+
inline int port() const;
|
|
96
|
+
|
|
97
|
+
// Returns true if the given other SocketAddress is a match
|
|
98
|
+
// for this one. The addresses are a match if:
|
|
99
|
+
// 1. They are the same family and match identically
|
|
100
|
+
// 2. They are different family but match semantically (
|
|
101
|
+
// for instance, an IPv4 address in IPv6 notation)
|
|
102
|
+
bool is_match(const SocketAddress& other) const;
|
|
103
|
+
|
|
104
|
+
// Compares this SocketAddress to the given other SocketAddress.
|
|
105
|
+
CompareResult compare(const SocketAddress& other) const;
|
|
106
|
+
|
|
107
|
+
// Returns true if this SocketAddress is within the subnet
|
|
108
|
+
// identified by the given network address and CIDR prefix.
|
|
109
|
+
bool is_in_network(const SocketAddress& network, int prefix) const;
|
|
110
|
+
|
|
111
|
+
// If the SocketAddress is an IPv6 address, returns the
|
|
112
|
+
// current value of the IPv6 flow label, if set. Otherwise
|
|
113
|
+
// returns 0.
|
|
114
|
+
inline uint32_t flow_label() const;
|
|
115
|
+
|
|
116
|
+
// If the SocketAddress is an IPv6 address, sets the
|
|
117
|
+
// current value of the IPv6 flow label. If not an
|
|
118
|
+
// IPv6 address, set_flow_label is a non-op. It
|
|
119
|
+
// is important to note that the flow label,
|
|
120
|
+
// while represented as an uint32_t, the flow
|
|
121
|
+
// label is strictly limited to 20 bits, and
|
|
122
|
+
// this will assert if any value larger than
|
|
123
|
+
// 20-bits is specified.
|
|
124
|
+
inline void set_flow_label(uint32_t label = 0);
|
|
125
|
+
|
|
126
|
+
inline void Update(uint8_t* data, size_t len);
|
|
127
|
+
inline void Update(const sockaddr* data, size_t len);
|
|
128
|
+
|
|
129
|
+
static SocketAddress FromSockName(const uv_udp_t& handle);
|
|
130
|
+
static SocketAddress FromSockName(const uv_tcp_t& handle);
|
|
131
|
+
static SocketAddress FromPeerName(const uv_udp_t& handle);
|
|
132
|
+
static SocketAddress FromPeerName(const uv_tcp_t& handle);
|
|
133
|
+
|
|
134
|
+
inline v8::MaybeLocal<v8::Object> ToJS(
|
|
135
|
+
Environment* env,
|
|
136
|
+
v8::Local<v8::Object> obj = v8::Local<v8::Object>()) const;
|
|
137
|
+
|
|
138
|
+
inline std::string ToString() const;
|
|
139
|
+
|
|
140
|
+
SET_NO_MEMORY_INFO()
|
|
141
|
+
SET_MEMORY_INFO_NAME(SocketAddress)
|
|
142
|
+
SET_SELF_SIZE(SocketAddress)
|
|
143
|
+
|
|
144
|
+
template <typename T>
|
|
145
|
+
using Map = std::unordered_map<SocketAddress, T, Hash>;
|
|
146
|
+
|
|
147
|
+
private:
|
|
148
|
+
sockaddr_storage address_;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
class SocketAddressBase : public BaseObject {
|
|
152
|
+
public:
|
|
153
|
+
static bool HasInstance(Environment* env, v8::Local<v8::Value> value);
|
|
154
|
+
static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
|
|
155
|
+
Environment* env);
|
|
156
|
+
static void Initialize(Environment* env, v8::Local<v8::Object> target);
|
|
157
|
+
static BaseObjectPtr<SocketAddressBase> Create(
|
|
158
|
+
Environment* env,
|
|
159
|
+
std::shared_ptr<SocketAddress> address);
|
|
160
|
+
|
|
161
|
+
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
162
|
+
static void Detail(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
163
|
+
static void LegacyDetail(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
164
|
+
static void GetFlowLabel(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
165
|
+
|
|
166
|
+
SocketAddressBase(
|
|
167
|
+
Environment* env,
|
|
168
|
+
v8::Local<v8::Object> wrap,
|
|
169
|
+
std::shared_ptr<SocketAddress> address);
|
|
170
|
+
|
|
171
|
+
inline const std::shared_ptr<SocketAddress>& address() const {
|
|
172
|
+
return address_;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
void MemoryInfo(MemoryTracker* tracker) const override;
|
|
176
|
+
SET_MEMORY_INFO_NAME(SocketAddressBase)
|
|
177
|
+
SET_SELF_SIZE(SocketAddressBase)
|
|
178
|
+
|
|
179
|
+
TransferMode GetTransferMode() const override {
|
|
180
|
+
return TransferMode::kCloneable;
|
|
181
|
+
}
|
|
182
|
+
std::unique_ptr<worker::TransferData> CloneForMessaging() const override;
|
|
183
|
+
|
|
184
|
+
class TransferData : public worker::TransferData {
|
|
185
|
+
public:
|
|
186
|
+
inline explicit TransferData(const SocketAddressBase* wrap)
|
|
187
|
+
: address_(wrap->address_) {}
|
|
188
|
+
|
|
189
|
+
inline explicit TransferData(std::shared_ptr<SocketAddress> address)
|
|
190
|
+
: address_(std::move(address)) {}
|
|
191
|
+
|
|
192
|
+
BaseObjectPtr<BaseObject> Deserialize(
|
|
193
|
+
Environment* env,
|
|
194
|
+
v8::Local<v8::Context> context,
|
|
195
|
+
std::unique_ptr<worker::TransferData> self) override;
|
|
196
|
+
|
|
197
|
+
void MemoryInfo(MemoryTracker* tracker) const override;
|
|
198
|
+
SET_MEMORY_INFO_NAME(SocketAddressBase::TransferData)
|
|
199
|
+
SET_SELF_SIZE(TransferData)
|
|
200
|
+
|
|
201
|
+
private:
|
|
202
|
+
std::shared_ptr<SocketAddress> address_;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
private:
|
|
206
|
+
std::shared_ptr<SocketAddress> address_;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
template <typename T>
|
|
210
|
+
class SocketAddressLRU : public MemoryRetainer {
|
|
211
|
+
public:
|
|
212
|
+
using Type = typename T::Type;
|
|
213
|
+
|
|
214
|
+
inline explicit SocketAddressLRU(size_t max_size);
|
|
215
|
+
|
|
216
|
+
// If the item already exists, returns a reference to
|
|
217
|
+
// the existing item, adjusting items position in the
|
|
218
|
+
// LRU. If the item does not exist, emplaces the item
|
|
219
|
+
// and returns the new item.
|
|
220
|
+
Type* Upsert(const SocketAddress& address);
|
|
221
|
+
|
|
222
|
+
// Returns a reference to the item if it exists, or
|
|
223
|
+
// nullptr. The position in the LRU is not modified.
|
|
224
|
+
Type* Peek(const SocketAddress& address) const;
|
|
225
|
+
|
|
226
|
+
size_t size() const { return map_.size(); }
|
|
227
|
+
size_t max_size() const { return max_size_; }
|
|
228
|
+
|
|
229
|
+
void MemoryInfo(MemoryTracker* tracker) const override;
|
|
230
|
+
SET_MEMORY_INFO_NAME(SocketAddressLRU)
|
|
231
|
+
SET_SELF_SIZE(SocketAddressLRU)
|
|
232
|
+
|
|
233
|
+
private:
|
|
234
|
+
using Pair = std::pair<SocketAddress, Type>;
|
|
235
|
+
using Iterator = typename std::list<Pair>::iterator;
|
|
236
|
+
|
|
237
|
+
void CheckExpired();
|
|
238
|
+
|
|
239
|
+
std::list<Pair> list_;
|
|
240
|
+
SocketAddress::Map<Iterator> map_;
|
|
241
|
+
size_t max_size_;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// A BlockList is used to evaluate whether a given
|
|
245
|
+
// SocketAddress should be accepted for inbound or
|
|
246
|
+
// outbound network activity.
|
|
247
|
+
class SocketAddressBlockList : public MemoryRetainer {
|
|
248
|
+
public:
|
|
249
|
+
explicit SocketAddressBlockList(
|
|
250
|
+
std::shared_ptr<SocketAddressBlockList> parent = {});
|
|
251
|
+
~SocketAddressBlockList() = default;
|
|
252
|
+
|
|
253
|
+
void AddSocketAddress(const std::shared_ptr<SocketAddress>& address);
|
|
254
|
+
|
|
255
|
+
void RemoveSocketAddress(const std::shared_ptr<SocketAddress>& address);
|
|
256
|
+
|
|
257
|
+
void AddSocketAddressRange(
|
|
258
|
+
const std::shared_ptr<SocketAddress>& start,
|
|
259
|
+
const std::shared_ptr<SocketAddress>& end);
|
|
260
|
+
|
|
261
|
+
void AddSocketAddressMask(
|
|
262
|
+
const std::shared_ptr<SocketAddress>& address,
|
|
263
|
+
int prefix);
|
|
264
|
+
|
|
265
|
+
bool Apply(const std::shared_ptr<SocketAddress>& address);
|
|
266
|
+
|
|
267
|
+
size_t size() const { return rules_.size(); }
|
|
268
|
+
|
|
269
|
+
v8::MaybeLocal<v8::Array> ListRules(Environment* env);
|
|
270
|
+
|
|
271
|
+
struct Rule : public MemoryRetainer {
|
|
272
|
+
virtual bool Apply(const std::shared_ptr<SocketAddress>& address) = 0;
|
|
273
|
+
inline v8::MaybeLocal<v8::Value> ToV8String(Environment* env);
|
|
274
|
+
virtual std::string ToString() = 0;
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
struct SocketAddressRule final : Rule {
|
|
278
|
+
std::shared_ptr<SocketAddress> address;
|
|
279
|
+
|
|
280
|
+
explicit SocketAddressRule(const std::shared_ptr<SocketAddress>& address);
|
|
281
|
+
|
|
282
|
+
bool Apply(const std::shared_ptr<SocketAddress>& address) override;
|
|
283
|
+
std::string ToString() override;
|
|
284
|
+
|
|
285
|
+
void MemoryInfo(node::MemoryTracker* tracker) const override;
|
|
286
|
+
SET_MEMORY_INFO_NAME(SocketAddressRule)
|
|
287
|
+
SET_SELF_SIZE(SocketAddressRule)
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
struct SocketAddressRangeRule final : Rule {
|
|
291
|
+
std::shared_ptr<SocketAddress> start;
|
|
292
|
+
std::shared_ptr<SocketAddress> end;
|
|
293
|
+
|
|
294
|
+
SocketAddressRangeRule(
|
|
295
|
+
const std::shared_ptr<SocketAddress>& start,
|
|
296
|
+
const std::shared_ptr<SocketAddress>& end);
|
|
297
|
+
|
|
298
|
+
bool Apply(const std::shared_ptr<SocketAddress>& address) override;
|
|
299
|
+
std::string ToString() override;
|
|
300
|
+
|
|
301
|
+
void MemoryInfo(node::MemoryTracker* tracker) const override;
|
|
302
|
+
SET_MEMORY_INFO_NAME(SocketAddressRangeRule)
|
|
303
|
+
SET_SELF_SIZE(SocketAddressRangeRule)
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
struct SocketAddressMaskRule final : Rule {
|
|
307
|
+
std::shared_ptr<SocketAddress> network;
|
|
308
|
+
int prefix;
|
|
309
|
+
|
|
310
|
+
SocketAddressMaskRule(
|
|
311
|
+
const std::shared_ptr<SocketAddress>& address,
|
|
312
|
+
int prefix);
|
|
313
|
+
|
|
314
|
+
bool Apply(const std::shared_ptr<SocketAddress>& address) override;
|
|
315
|
+
std::string ToString() override;
|
|
316
|
+
|
|
317
|
+
void MemoryInfo(node::MemoryTracker* tracker) const override;
|
|
318
|
+
SET_MEMORY_INFO_NAME(SocketAddressMaskRule)
|
|
319
|
+
SET_SELF_SIZE(SocketAddressMaskRule)
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
void MemoryInfo(node::MemoryTracker* tracker) const override;
|
|
323
|
+
SET_MEMORY_INFO_NAME(SocketAddressBlockList)
|
|
324
|
+
SET_SELF_SIZE(SocketAddressBlockList)
|
|
325
|
+
|
|
326
|
+
private:
|
|
327
|
+
bool ListRules(
|
|
328
|
+
Environment* env,
|
|
329
|
+
std::vector<v8::Local<v8::Value>>* vec);
|
|
330
|
+
|
|
331
|
+
std::shared_ptr<SocketAddressBlockList> parent_;
|
|
332
|
+
std::list<std::unique_ptr<Rule>> rules_;
|
|
333
|
+
SocketAddress::Map<std::list<std::unique_ptr<Rule>>::iterator> address_rules_;
|
|
334
|
+
|
|
335
|
+
Mutex mutex_;
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
class SocketAddressBlockListWrap : public BaseObject {
|
|
339
|
+
public:
|
|
340
|
+
static bool HasInstance(Environment* env, v8::Local<v8::Value> value);
|
|
341
|
+
static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
|
|
342
|
+
Environment* env);
|
|
343
|
+
static void Initialize(v8::Local<v8::Object> target,
|
|
344
|
+
v8::Local<v8::Value> unused,
|
|
345
|
+
v8::Local<v8::Context> context,
|
|
346
|
+
void* priv);
|
|
347
|
+
|
|
348
|
+
static BaseObjectPtr<SocketAddressBlockListWrap> New(Environment* env);
|
|
349
|
+
static BaseObjectPtr<SocketAddressBlockListWrap> New(
|
|
350
|
+
Environment* env,
|
|
351
|
+
std::shared_ptr<SocketAddressBlockList> blocklist);
|
|
352
|
+
|
|
353
|
+
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
354
|
+
static void AddAddress(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
355
|
+
static void AddRange(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
356
|
+
static void AddSubnet(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
357
|
+
static void Check(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
358
|
+
static void GetRules(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
359
|
+
|
|
360
|
+
SocketAddressBlockListWrap(
|
|
361
|
+
Environment* env,
|
|
362
|
+
v8::Local<v8::Object> wrap,
|
|
363
|
+
std::shared_ptr<SocketAddressBlockList> blocklist =
|
|
364
|
+
std::make_shared<SocketAddressBlockList>());
|
|
365
|
+
|
|
366
|
+
void MemoryInfo(node::MemoryTracker* tracker) const override;
|
|
367
|
+
SET_MEMORY_INFO_NAME(SocketAddressBlockListWrap)
|
|
368
|
+
SET_SELF_SIZE(SocketAddressBlockListWrap)
|
|
369
|
+
|
|
370
|
+
TransferMode GetTransferMode() const override {
|
|
371
|
+
return TransferMode::kCloneable;
|
|
372
|
+
}
|
|
373
|
+
std::unique_ptr<worker::TransferData> CloneForMessaging() const override;
|
|
374
|
+
|
|
375
|
+
class TransferData : public worker::TransferData {
|
|
376
|
+
public:
|
|
377
|
+
inline explicit TransferData(const SocketAddressBlockListWrap* wrap)
|
|
378
|
+
: blocklist_(wrap->blocklist_) {}
|
|
379
|
+
|
|
380
|
+
inline explicit TransferData(
|
|
381
|
+
std::shared_ptr<SocketAddressBlockList> blocklist)
|
|
382
|
+
: blocklist_(std::move(blocklist)) {}
|
|
383
|
+
|
|
384
|
+
BaseObjectPtr<BaseObject> Deserialize(
|
|
385
|
+
Environment* env,
|
|
386
|
+
v8::Local<v8::Context> context,
|
|
387
|
+
std::unique_ptr<worker::TransferData> self) override;
|
|
388
|
+
|
|
389
|
+
void MemoryInfo(MemoryTracker* tracker) const override;
|
|
390
|
+
SET_MEMORY_INFO_NAME(SocketAddressBlockListWrap::TransferData)
|
|
391
|
+
SET_SELF_SIZE(TransferData)
|
|
392
|
+
|
|
393
|
+
private:
|
|
394
|
+
std::shared_ptr<SocketAddressBlockList> blocklist_;
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
private:
|
|
398
|
+
std::shared_ptr<SocketAddressBlockList> blocklist_;
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
} // namespace node
|
|
402
|
+
|
|
403
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
404
|
+
|
|
405
|
+
#endif // SRC_NODE_SOCKADDR_H_
|
|
@@ -0,0 +1,73 @@
|
|
|
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_NODE_STAT_WATCHER_H_
|
|
23
|
+
#define SRC_NODE_STAT_WATCHER_H_
|
|
24
|
+
|
|
25
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
26
|
+
|
|
27
|
+
#include "node.h"
|
|
28
|
+
#include "handle_wrap.h"
|
|
29
|
+
#include "uv.h"
|
|
30
|
+
#include "v8.h"
|
|
31
|
+
|
|
32
|
+
namespace node {
|
|
33
|
+
namespace fs {
|
|
34
|
+
class BindingData;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
class Environment;
|
|
38
|
+
class ExternalReferenceRegistry;
|
|
39
|
+
|
|
40
|
+
class StatWatcher : public HandleWrap {
|
|
41
|
+
public:
|
|
42
|
+
static void CreatePerIsolateProperties(IsolateData* isolate_data,
|
|
43
|
+
v8::Local<v8::ObjectTemplate> ctor);
|
|
44
|
+
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
|
|
45
|
+
|
|
46
|
+
protected:
|
|
47
|
+
StatWatcher(fs::BindingData* binding_data,
|
|
48
|
+
v8::Local<v8::Object> wrap,
|
|
49
|
+
bool use_bigint);
|
|
50
|
+
|
|
51
|
+
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
52
|
+
static void Start(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
53
|
+
|
|
54
|
+
SET_NO_MEMORY_INFO()
|
|
55
|
+
SET_MEMORY_INFO_NAME(StatWatcher)
|
|
56
|
+
SET_SELF_SIZE(StatWatcher)
|
|
57
|
+
|
|
58
|
+
private:
|
|
59
|
+
static void Callback(uv_fs_poll_t* handle,
|
|
60
|
+
int status,
|
|
61
|
+
const uv_stat_t* prev,
|
|
62
|
+
const uv_stat_t* curr);
|
|
63
|
+
|
|
64
|
+
uv_fs_poll_t watcher_;
|
|
65
|
+
const bool use_bigint_;
|
|
66
|
+
BaseObjectPtr<fs::BindingData> binding_data_;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
} // namespace node
|
|
70
|
+
|
|
71
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
72
|
+
|
|
73
|
+
#endif // SRC_NODE_STAT_WATCHER_H_
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#ifndef SRC_NODE_THREADSAFE_COW_INL_H_
|
|
2
|
+
#define SRC_NODE_THREADSAFE_COW_INL_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
namespace node {
|
|
7
|
+
|
|
8
|
+
template <typename T>
|
|
9
|
+
T* CopyOnWrite<T>::write() {
|
|
10
|
+
if (data_.use_count() > 1l) {
|
|
11
|
+
data_ = std::make_shared<T>(*data_);
|
|
12
|
+
}
|
|
13
|
+
return data_.get();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
template <typename T>
|
|
17
|
+
ThreadsafeCopyOnWrite<T>::Read::Read(const ThreadsafeCopyOnWrite<T>* cow)
|
|
18
|
+
: cow_(cow), lock_(cow->impl_->mutex) {}
|
|
19
|
+
|
|
20
|
+
template <typename T>
|
|
21
|
+
const T& ThreadsafeCopyOnWrite<T>::Read::operator*() const {
|
|
22
|
+
return cow_->impl_->data;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
template <typename T>
|
|
26
|
+
const T* ThreadsafeCopyOnWrite<T>::Read::operator->() const {
|
|
27
|
+
return &cow_->impl_->data;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
template <typename T>
|
|
31
|
+
ThreadsafeCopyOnWrite<T>::Write::Write(ThreadsafeCopyOnWrite<T>* cow)
|
|
32
|
+
: cow_(cow), impl_(cow->impl_.write()), lock_(impl_->mutex) {}
|
|
33
|
+
|
|
34
|
+
template <typename T>
|
|
35
|
+
T& ThreadsafeCopyOnWrite<T>::Write::operator*() {
|
|
36
|
+
return impl_->data;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
template <typename T>
|
|
40
|
+
T* ThreadsafeCopyOnWrite<T>::Write::operator->() {
|
|
41
|
+
return &impl_->data;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
template <typename T>
|
|
45
|
+
ThreadsafeCopyOnWrite<T>::Impl::Impl(const Impl& other) {
|
|
46
|
+
RwLock::ScopedReadLock lock(other.mutex);
|
|
47
|
+
data = other.data;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
} // namespace node
|
|
51
|
+
|
|
52
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
53
|
+
|
|
54
|
+
#endif // SRC_NODE_THREADSAFE_COW_INL_H_
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#ifndef SRC_NODE_THREADSAFE_COW_H_
|
|
2
|
+
#define SRC_NODE_THREADSAFE_COW_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "util.h"
|
|
7
|
+
#include "uv.h"
|
|
8
|
+
|
|
9
|
+
#include <memory> // std::shared_ptr<T>
|
|
10
|
+
#include <utility> // std::forward<T>
|
|
11
|
+
|
|
12
|
+
namespace node {
|
|
13
|
+
|
|
14
|
+
// Copy-on-write utility. Not threadsafe, i.e. there is no synchronization
|
|
15
|
+
// of the copy operation with other operations.
|
|
16
|
+
template <typename T>
|
|
17
|
+
class CopyOnWrite final {
|
|
18
|
+
public:
|
|
19
|
+
template <typename... Args>
|
|
20
|
+
explicit CopyOnWrite(Args&&... args)
|
|
21
|
+
: data_(std::make_shared<T>(std::forward<Args>(args)...)) {}
|
|
22
|
+
|
|
23
|
+
CopyOnWrite(const CopyOnWrite<T>& other) = default;
|
|
24
|
+
CopyOnWrite& operator=(const CopyOnWrite<T>& other) = default;
|
|
25
|
+
CopyOnWrite(CopyOnWrite<T>&& other) = default;
|
|
26
|
+
CopyOnWrite& operator=(CopyOnWrite<T>&& other) = default;
|
|
27
|
+
|
|
28
|
+
const T* read() const { return data_.get(); }
|
|
29
|
+
T* write();
|
|
30
|
+
|
|
31
|
+
const T& operator*() const { return *read(); }
|
|
32
|
+
const T* operator->() const { return read(); }
|
|
33
|
+
|
|
34
|
+
private:
|
|
35
|
+
std::shared_ptr<T> data_;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// Threadsafe copy-on-write utility. Consumers need to use the Read and
|
|
39
|
+
// Write helpers to access the target data structure.
|
|
40
|
+
template <typename T>
|
|
41
|
+
class ThreadsafeCopyOnWrite final {
|
|
42
|
+
private:
|
|
43
|
+
// Define this early since some of the public members depend on it
|
|
44
|
+
// and some compilers need it to be defined first in that case.
|
|
45
|
+
struct Impl {
|
|
46
|
+
explicit Impl(const T& data) : data(data) {}
|
|
47
|
+
explicit Impl(T&& data) : data(std::move(data)) {}
|
|
48
|
+
|
|
49
|
+
Impl(const Impl& other);
|
|
50
|
+
Impl& operator=(const Impl& other) = delete;
|
|
51
|
+
Impl(Impl&& other) = delete;
|
|
52
|
+
Impl& operator=(Impl&& other) = delete;
|
|
53
|
+
|
|
54
|
+
RwLock mutex;
|
|
55
|
+
T data;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
public:
|
|
59
|
+
template <typename... Args>
|
|
60
|
+
ThreadsafeCopyOnWrite(Args&&... args)
|
|
61
|
+
: impl_(T(std::forward<Args>(args)...)) {}
|
|
62
|
+
|
|
63
|
+
ThreadsafeCopyOnWrite(const ThreadsafeCopyOnWrite<T>& other) = default;
|
|
64
|
+
ThreadsafeCopyOnWrite& operator=(const ThreadsafeCopyOnWrite<T>& other) =
|
|
65
|
+
default;
|
|
66
|
+
ThreadsafeCopyOnWrite(ThreadsafeCopyOnWrite<T>&& other) = default;
|
|
67
|
+
ThreadsafeCopyOnWrite& operator=(ThreadsafeCopyOnWrite<T>&& other) = default;
|
|
68
|
+
|
|
69
|
+
class Read {
|
|
70
|
+
public:
|
|
71
|
+
explicit Read(const ThreadsafeCopyOnWrite<T>* cow);
|
|
72
|
+
|
|
73
|
+
const T& operator*() const;
|
|
74
|
+
const T* operator->() const;
|
|
75
|
+
|
|
76
|
+
private:
|
|
77
|
+
const ThreadsafeCopyOnWrite<T>* cow_;
|
|
78
|
+
RwLock::ScopedReadLock lock_;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
class Write {
|
|
82
|
+
public:
|
|
83
|
+
explicit Write(ThreadsafeCopyOnWrite<T>* cow);
|
|
84
|
+
|
|
85
|
+
T& operator*();
|
|
86
|
+
T* operator->();
|
|
87
|
+
|
|
88
|
+
private:
|
|
89
|
+
ThreadsafeCopyOnWrite<T>* cow_;
|
|
90
|
+
typename ThreadsafeCopyOnWrite<T>::Impl* impl_;
|
|
91
|
+
RwLock::ScopedLock lock_;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
Read read() const { return Read(this); }
|
|
95
|
+
Write write() { return Write(this); }
|
|
96
|
+
|
|
97
|
+
private:
|
|
98
|
+
CopyOnWrite<Impl> impl_;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
} // namespace node
|
|
102
|
+
|
|
103
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
104
|
+
|
|
105
|
+
#endif // SRC_NODE_THREADSAFE_COW_H_
|