Browse files

dgram: bring back setMulticastLoopback()

  • Loading branch information...
1 parent 986e612 commit 46e86aa80348dd8e31ade16a3b19eeee6baee0de @bnoordhuis bnoordhuis committed Jan 23, 2012
Showing with 33 additions and 4 deletions.
  1. +7 −1 lib/dgram.js
  2. +20 −0 src/udp_wrap.cc
  3. +6 −3 test/simple/test-dgram-multicast-multi-process.js
View
8 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
};
View
20 src/udp_wrap.cc
@@ -94,6 +94,7 @@ class UDPWrap: public HandleWrap {
static Handle<Value> AddMembership(const Arguments& args);
static Handle<Value> DropMembership(const Arguments& args);
static Handle<Value> SetMulticastTTL(const Arguments& args);
+ static Handle<Value> SetMulticastLoopback(const Arguments& args);
static Handle<Value> SetBroadcast(const Arguments& args);
private:
@@ -156,6 +157,7 @@ void UDPWrap::Initialize(Handle<Object> 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<Value> UDPWrap::DropMembership(const Arguments& args) {
return SetMembership(args, UV_LEAVE_GROUP);
}
+
Handle<Value> UDPWrap::SetMulticastTTL(const Arguments& args) {
HandleScope scope;
UNWRAP
@@ -277,6 +280,23 @@ Handle<Value> UDPWrap::SetMulticastTTL(const Arguments& args) {
return scope.Close(Integer::New(r));
}
+
+Handle<Value> 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<Value> UDPWrap::DoSend(const Arguments& args, int family) {
HandleScope scope;
int r;
View
9 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');

0 comments on commit 46e86aa

Please sign in to comment.