Skip to content

Commit

Permalink
src: register udp_wrap external references
Browse files Browse the repository at this point in the history
PR-URL: #50943
Refs: #50924
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
joyeecheung authored and richardlau committed Mar 25, 2024
1 parent b05d496 commit 9365e12
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/node_external_reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class ExternalReferenceRegistry {
V(task_queue) \
V(tcp_wrap) \
V(tty_wrap) \
V(udp_wrap) \
V(url) \
V(util) \
V(pipe_wrap) \
Expand Down
39 changes: 38 additions & 1 deletion src/udp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@

#include "udp_wrap.h"
#include "env-inl.h"
#include "handle_wrap.h"
#include "node_buffer.h"
#include "node_errors.h"
#include "node_external_reference.h"
#include "node_sockaddr-inl.h"
#include "handle_wrap.h"
#include "req_wrap-inl.h"
#include "util-inl.h"

Expand Down Expand Up @@ -133,6 +134,12 @@ void UDPWrapBase::AddMethods(Environment* env, Local<FunctionTemplate> t) {
SetProtoMethod(env->isolate(), t, "recvStop", RecvStop);
}

void UDPWrapBase::RegisterExternalReferences(
ExternalReferenceRegistry* registry) {
registry->Register(RecvStart);
registry->Register(RecvStop);
}

UDPWrap::UDPWrap(Environment* env, Local<Object> object)
: HandleWrap(env,
object,
Expand Down Expand Up @@ -229,6 +236,34 @@ void UDPWrap::Initialize(Local<Object> target,
constants).Check();
}

void UDPWrap::RegisterExternalReferences(ExternalReferenceRegistry* registry) {
UDPWrapBase::RegisterExternalReferences(registry);
registry->Register(New);
registry->Register(GetFD);

registry->Register(Open);
registry->Register(Bind);
registry->Register(Connect);
registry->Register(Send);
registry->Register(Bind6);
registry->Register(Connect6);
registry->Register(Send6);
registry->Register(Disconnect);
registry->Register(GetSockOrPeerName<UDPWrap, uv_udp_getpeername>);
registry->Register(GetSockOrPeerName<UDPWrap, uv_udp_getsockname>);
registry->Register(AddMembership);
registry->Register(DropMembership);
registry->Register(AddSourceSpecificMembership);
registry->Register(DropSourceSpecificMembership);
registry->Register(SetMulticastInterface);
registry->Register(SetLibuvInt32<uv_udp_set_multicast_ttl>);
registry->Register(SetLibuvInt32<uv_udp_set_multicast_loop>);
registry->Register(SetLibuvInt32<uv_udp_set_broadcast>);
registry->Register(SetLibuvInt32<uv_udp_set_ttl>);
registry->Register(BufferSize);
registry->Register(GetSendQueueSize);
registry->Register(GetSendQueueCount);
}

void UDPWrap::New(const FunctionCallbackInfo<Value>& args) {
CHECK(args.IsConstructCall());
Expand Down Expand Up @@ -807,3 +842,5 @@ void UDPWrap::GetSendQueueCount(const FunctionCallbackInfo<Value>& args) {
} // namespace node

NODE_BINDING_CONTEXT_AWARE_INTERNAL(udp_wrap, node::UDPWrap::Initialize)
NODE_BINDING_EXTERNAL_REFERENCE(udp_wrap,
node::UDPWrap::RegisterExternalReferences)
3 changes: 3 additions & 0 deletions src/udp_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

namespace node {

class ExternalReferenceRegistry;
class UDPWrapBase;

// A listener that can be attached to an `UDPWrapBase` object and generally
Expand Down Expand Up @@ -110,6 +111,7 @@ class UDPWrapBase {
static void RecvStart(const v8::FunctionCallbackInfo<v8::Value>& args);
static void RecvStop(const v8::FunctionCallbackInfo<v8::Value>& args);
static void AddMethods(Environment* env, v8::Local<v8::FunctionTemplate> t);
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);

private:
UDPListener* listener_ = nullptr;
Expand All @@ -126,6 +128,7 @@ class UDPWrap final : public HandleWrap,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv);
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
static void GetFD(const v8::FunctionCallbackInfo<v8::Value>& args);
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Open(const v8::FunctionCallbackInfo<v8::Value>& args);
Expand Down

0 comments on commit 9365e12

Please sign in to comment.