0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

dgram: bring back setMulticastLoopback()

This commit is contained in:
Ben Noordhuis 2012-01-23 23:38:25 +01:00
parent 986e612557
commit 46e86aa803
3 changed files with 33 additions and 4 deletions

View File

@ -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 File

@ -94,6 +94,7 @@ public:
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 File

@ -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');