@@ -128,6 +128,10 @@ void UDPWrap::Initialize(Local<Object> target,
128128 GetSockOrPeerName<UDPWrap, uv_udp_getsockname>);
129129 env->SetProtoMethod (t, " addMembership" , AddMembership);
130130 env->SetProtoMethod (t, " dropMembership" , DropMembership);
131+ env->SetProtoMethod (t, " addSourceSpecificMembership" ,
132+ AddSourceSpecificMembership);
133+ env->SetProtoMethod (t, " dropSourceSpecificMembership" ,
134+ DropSourceSpecificMembership);
131135 env->SetProtoMethod (t, " setMulticastInterface" , SetMulticastInterface);
132136 env->SetProtoMethod (t, " setMulticastTTL" , SetMulticastTTL);
133137 env->SetProtoMethod (t, " setMulticastLoopback" , SetMulticastLoopback);
@@ -397,6 +401,44 @@ void UDPWrap::DropMembership(const FunctionCallbackInfo<Value>& args) {
397401 SetMembership (args, UV_LEAVE_GROUP);
398402}
399403
404+ void UDPWrap::SetSourceMembership (const FunctionCallbackInfo<Value>& args,
405+ uv_membership membership) {
406+ UDPWrap* wrap;
407+ ASSIGN_OR_RETURN_UNWRAP (&wrap,
408+ args.Holder (),
409+ args.GetReturnValue ().Set (UV_EBADF));
410+
411+ CHECK_EQ (args.Length (), 3 );
412+
413+ node::Utf8Value source_address (args.GetIsolate (), args[0 ]);
414+ node::Utf8Value group_address (args.GetIsolate (), args[1 ]);
415+ node::Utf8Value iface (args.GetIsolate (), args[2 ]);
416+
417+ if (*iface == nullptr ) return ;
418+ const char * iface_cstr = *iface;
419+ if (args[2 ]->IsUndefined () || args[2 ]->IsNull ()) {
420+ iface_cstr = nullptr ;
421+ }
422+
423+ int err = uv_udp_set_source_membership (&wrap->handle_ ,
424+ *group_address,
425+ iface_cstr,
426+ *source_address,
427+ membership);
428+ args.GetReturnValue ().Set (err);
429+ }
430+
431+ void UDPWrap::AddSourceSpecificMembership (
432+ const FunctionCallbackInfo<Value>& args) {
433+ SetSourceMembership (args, UV_JOIN_GROUP);
434+ }
435+
436+
437+ void UDPWrap::DropSourceSpecificMembership (
438+ const FunctionCallbackInfo<Value>& args) {
439+ SetSourceMembership (args, UV_LEAVE_GROUP);
440+ }
441+
400442
401443void UDPWrap::DoSend (const FunctionCallbackInfo<Value>& args, int family) {
402444 Environment* env = Environment::GetCurrent (args);
0 commit comments