From 46e86aa80348dd8e31ade16a3b19eeee6baee0de Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 23 Jan 2012 23:38:25 +0100 Subject: [PATCH] dgram: bring back setMulticastLoopback() --- lib/dgram.js | 8 +++++++- src/udp_wrap.cc | 20 +++++++++++++++++++ .../test-dgram-multicast-multi-process.js | 9 ++++++--- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/lib/dgram.js b/lib/dgram.js index ee239558199..8c2ec6fcea6 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -248,7 +248,13 @@ Socket.prototype.setMulticastTTL = function(arg) { Socket.prototype.setMulticastLoopback = function(arg) { - throw new Error('not yet implemented'); + arg = arg ? 1 : 0; + + if (this._handle.setMulticastLoopback(arg)) { + throw errnoException(errno, 'setMulticastLoopback'); + } + + return arg; // 0.4 compatibility }; diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index e1be2d92da1..99d5936b6dd 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -94,6 +94,7 @@ public: static Handle AddMembership(const Arguments& args); static Handle DropMembership(const Arguments& args); static Handle SetMulticastTTL(const Arguments& args); + static Handle SetMulticastLoopback(const Arguments& args); static Handle SetBroadcast(const Arguments& args); private: @@ -156,6 +157,7 @@ void UDPWrap::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(t, "addMembership", AddMembership); NODE_SET_PROTOTYPE_METHOD(t, "dropMembership", DropMembership); NODE_SET_PROTOTYPE_METHOD(t, "setMulticastTTL", SetMulticastTTL); + NODE_SET_PROTOTYPE_METHOD(t, "setMulticastLoopback", SetMulticastLoopback); NODE_SET_PROTOTYPE_METHOD(t, "setBroadcast", SetBroadcast); target->Set(String::NewSymbol("UDP"), @@ -262,6 +264,7 @@ Handle UDPWrap::DropMembership(const Arguments& args) { return SetMembership(args, UV_LEAVE_GROUP); } + Handle UDPWrap::SetMulticastTTL(const Arguments& args) { HandleScope scope; UNWRAP @@ -277,6 +280,23 @@ Handle UDPWrap::SetMulticastTTL(const Arguments& args) { return scope.Close(Integer::New(r)); } + +Handle UDPWrap::SetMulticastLoopback(const Arguments& args) { + HandleScope scope; + UNWRAP + + assert(args.Length() == 1); + + int on = args[0]->Int32Value(); + int r = uv_udp_set_multicast_loop(&wrap->handle_, on); + + if (r) + SetErrno(uv_last_error(uv_default_loop())); + + return scope.Close(Integer::New(r)); +} + + Handle UDPWrap::DoSend(const Arguments& args, int family) { HandleScope scope; int r; diff --git a/test/simple/test-dgram-multicast-multi-process.js b/test/simple/test-dgram-multicast-multi-process.js index 65d9dfc61c6..75fba18ae22 100644 --- a/test/simple/test-dgram-multicast-multi-process.js +++ b/test/simple/test-dgram-multicast-multi-process.js @@ -98,10 +98,13 @@ if (cluster.isMaster) { } var sendSocket = dgram.createSocket('udp4'); + sendSocket.bind(); // FIXME a libuv limitation makes it necessary to bind() + // before calling any of the set*() functions - the bind() + // call is what creates the actual socket... - //sendSocket.setBroadcast(true); - //sendSocket.setMulticastTTL(1); - //sendSocket.setMulticastLoopback(true); + sendSocket.setBroadcast(true); + sendSocket.setMulticastTTL(1); + sendSocket.setMulticastLoopback(true); sendSocket.on('close', function() { console.error('sendSocket closed');