Skip to content

Commit 46e86aa

Browse files
committed
dgram: bring back setMulticastLoopback()
1 parent 986e612 commit 46e86aa

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

lib/dgram.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,13 @@ Socket.prototype.setMulticastTTL = function(arg) {
248248

249249

250250
Socket.prototype.setMulticastLoopback = function(arg) {
251-
throw new Error('not yet implemented');
251+
arg = arg ? 1 : 0;
252+
253+
if (this._handle.setMulticastLoopback(arg)) {
254+
throw errnoException(errno, 'setMulticastLoopback');
255+
}
256+
257+
return arg; // 0.4 compatibility
252258
};
253259

254260

src/udp_wrap.cc

+20
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class UDPWrap: public HandleWrap {
9494
static Handle<Value> AddMembership(const Arguments& args);
9595
static Handle<Value> DropMembership(const Arguments& args);
9696
static Handle<Value> SetMulticastTTL(const Arguments& args);
97+
static Handle<Value> SetMulticastLoopback(const Arguments& args);
9798
static Handle<Value> SetBroadcast(const Arguments& args);
9899

99100
private:
@@ -156,6 +157,7 @@ void UDPWrap::Initialize(Handle<Object> target) {
156157
NODE_SET_PROTOTYPE_METHOD(t, "addMembership", AddMembership);
157158
NODE_SET_PROTOTYPE_METHOD(t, "dropMembership", DropMembership);
158159
NODE_SET_PROTOTYPE_METHOD(t, "setMulticastTTL", SetMulticastTTL);
160+
NODE_SET_PROTOTYPE_METHOD(t, "setMulticastLoopback", SetMulticastLoopback);
159161
NODE_SET_PROTOTYPE_METHOD(t, "setBroadcast", SetBroadcast);
160162

161163
target->Set(String::NewSymbol("UDP"),
@@ -262,6 +264,7 @@ Handle<Value> UDPWrap::DropMembership(const Arguments& args) {
262264
return SetMembership(args, UV_LEAVE_GROUP);
263265
}
264266

267+
265268
Handle<Value> UDPWrap::SetMulticastTTL(const Arguments& args) {
266269
HandleScope scope;
267270
UNWRAP
@@ -277,6 +280,23 @@ Handle<Value> UDPWrap::SetMulticastTTL(const Arguments& args) {
277280
return scope.Close(Integer::New(r));
278281
}
279282

283+
284+
Handle<Value> UDPWrap::SetMulticastLoopback(const Arguments& args) {
285+
HandleScope scope;
286+
UNWRAP
287+
288+
assert(args.Length() == 1);
289+
290+
int on = args[0]->Int32Value();
291+
int r = uv_udp_set_multicast_loop(&wrap->handle_, on);
292+
293+
if (r)
294+
SetErrno(uv_last_error(uv_default_loop()));
295+
296+
return scope.Close(Integer::New(r));
297+
}
298+
299+
280300
Handle<Value> UDPWrap::DoSend(const Arguments& args, int family) {
281301
HandleScope scope;
282302
int r;

test/simple/test-dgram-multicast-multi-process.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,13 @@ if (cluster.isMaster) {
9898
}
9999

100100
var sendSocket = dgram.createSocket('udp4');
101+
sendSocket.bind(); // FIXME a libuv limitation makes it necessary to bind()
102+
// before calling any of the set*() functions - the bind()
103+
// call is what creates the actual socket...
101104

102-
//sendSocket.setBroadcast(true);
103-
//sendSocket.setMulticastTTL(1);
104-
//sendSocket.setMulticastLoopback(true);
105+
sendSocket.setBroadcast(true);
106+
sendSocket.setMulticastTTL(1);
107+
sendSocket.setMulticastLoopback(true);
105108

106109
sendSocket.on('close', function() {
107110
console.error('sendSocket closed');

0 commit comments

Comments
 (0)