diff options
author | James M Snell <jasnell@gmail.com> | 2021-03-25 22:19:30 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2021-04-02 16:16:40 +0300 |
commit | 0b90d352948393e5f92ceb2ef749c643b1002a68 (patch) | |
tree | af799b4214eb4d855b6582fadc0f17d2e724ac84 /src/node_sockaddr.h | |
parent | fb9257f6597f0581592826d236cfc7196afebaca (diff) |
net: add SocketAddress class
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/37917
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'src/node_sockaddr.h')
-rw-r--r-- | src/node_sockaddr.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/node_sockaddr.h b/src/node_sockaddr.h index 670a8b78d85..62dcab6badd 100644 --- a/src/node_sockaddr.h +++ b/src/node_sockaddr.h @@ -148,6 +148,60 @@ class SocketAddress : public MemoryRetainer { sockaddr_storage address_; }; +class SocketAddressBase : public BaseObject { + public: + static bool HasInstance(Environment* env, v8::Local<v8::Value> value); + static v8::Local<v8::FunctionTemplate> GetConstructorTemplate( + Environment* env); + static void Initialize(Environment* env, v8::Local<v8::Object> target); + static BaseObjectPtr<SocketAddressBase> Create( + Environment* env, + std::shared_ptr<SocketAddress> address); + + static void New(const v8::FunctionCallbackInfo<v8::Value>& args); + static void Detail(const v8::FunctionCallbackInfo<v8::Value>& args); + static void LegacyDetail(const v8::FunctionCallbackInfo<v8::Value>& args); + static void GetFlowLabel(const v8::FunctionCallbackInfo<v8::Value>& args); + + SocketAddressBase( + Environment* env, + v8::Local<v8::Object> wrap, + std::shared_ptr<SocketAddress> address); + + void MemoryInfo(MemoryTracker* tracker) const override; + SET_MEMORY_INFO_NAME(SocketAddressBase); + SET_SELF_SIZE(SocketAddressBase); + + TransferMode GetTransferMode() const override { + return TransferMode::kCloneable; + } + std::unique_ptr<worker::TransferData> CloneForMessaging() const override; + + class TransferData : public worker::TransferData { + public: + inline explicit TransferData(const SocketAddressBase* wrap) + : address_(wrap->address_) {} + + inline explicit TransferData(std::shared_ptr<SocketAddress> address) + : address_(std::move(address)) {} + + BaseObjectPtr<BaseObject> Deserialize( + Environment* env, + v8::Local<v8::Context> context, + std::unique_ptr<worker::TransferData> self) override; + + void MemoryInfo(MemoryTracker* tracker) const override; + SET_MEMORY_INFO_NAME(SocketAddressBase::TransferData) + SET_SELF_SIZE(TransferData) + + private: + std::shared_ptr<SocketAddress> address_; + }; + + private: + std::shared_ptr<SocketAddress> address_; +}; + template <typename T> class SocketAddressLRU : public MemoryRetainer { public: |