Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

dgram: bring back setTTL()

  • Loading branch information...
bnoordhuis committed Jan 23, 2012
1 parent 46e86aa commit 2775c0e97ebdeed64743e4f56741118fdcfd8dda
Showing with 27 additions and 43 deletions.
  1. +9 −1 lib/dgram.js
  2. +17 −42 src/udp_wrap.cc
  3. +1 −0 test/simple/test-dgram-multicast-multi-process.js
@@ -230,7 +230,15 @@ Socket.prototype.setBroadcast = function(arg) {


Socket.prototype.setTTL = function(arg) {
throw new Error('not yet implemented');
if (typeof arg !== 'number') {
throw new TypeError('Argument must be a number');
}

if (this._handle.setTTL(arg)) {
throw errnoException(errno, 'setTTL');
}

return arg;
};


@@ -96,6 +96,7 @@ class UDPWrap: public HandleWrap {
static Handle<Value> SetMulticastTTL(const Arguments& args);
static Handle<Value> SetMulticastLoopback(const Arguments& args);
static Handle<Value> SetBroadcast(const Arguments& args);
static Handle<Value> SetTTL(const Arguments& args);

private:
static inline char* NewSlab(v8::Handle<v8::Object> global, v8::Handle<v8::Object> wrap_obj);
@@ -159,6 +160,7 @@ void UDPWrap::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "setMulticastTTL", SetMulticastTTL);
NODE_SET_PROTOTYPE_METHOD(t, "setMulticastLoopback", SetMulticastLoopback);
NODE_SET_PROTOTYPE_METHOD(t, "setBroadcast", SetBroadcast);
NODE_SET_PROTOTYPE_METHOD(t, "setTTL", SetTTL);

target->Set(String::NewSymbol("UDP"),
Persistent<FunctionTemplate>::New(t)->GetFunction());
@@ -215,20 +217,25 @@ Handle<Value> UDPWrap::Bind6(const Arguments& args) {
return DoBind(args, AF_INET6);
}

Handle<Value> UDPWrap::SetBroadcast(const Arguments& args) {
HandleScope scope;
UNWRAP

assert(args.Length() == 1);
#define X(name, fn) \
Handle<Value> UDPWrap::name(const Arguments& args) { \
HandleScope scope; \
UNWRAP \
assert(args.Length() == 1); \
int flag = args[0]->Int32Value(); \
int r = fn(&wrap->handle_, flag); \
if (r) SetErrno(uv_last_error(uv_default_loop())); \
return scope.Close(Integer::New(r)); \
}

int on = args[0]->Uint32Value();
int r = uv_udp_set_broadcast(&wrap->handle_, on);
X(SetTTL, uv_udp_set_ttl)
X(SetBroadcast, uv_udp_set_broadcast)
X(SetMulticastTTL, uv_udp_set_multicast_ttl)
X(SetMulticastLoopback, uv_udp_set_multicast_loop)

if (r)
SetErrno(uv_last_error(uv_default_loop()));
#undef X

return scope.Close(Integer::New(r));
}

Handle<Value> UDPWrap::SetMembership(const Arguments& args,
uv_membership membership) {
@@ -265,38 +272,6 @@ Handle<Value> UDPWrap::DropMembership(const Arguments& args) {
}


Handle<Value> UDPWrap::SetMulticastTTL(const Arguments& args) {
HandleScope scope;
UNWRAP

assert(args.Length() == 1);

int ttl = args[0]->Uint32Value();
int r = uv_udp_set_multicast_ttl(&wrap->handle_, ttl);

if (r)
SetErrno(uv_last_error(uv_default_loop()));

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;
@@ -102,6 +102,7 @@ if (cluster.isMaster) {
// before calling any of the set*() functions - the bind()
// call is what creates the actual socket...

sendSocket.setTTL(1);
sendSocket.setBroadcast(true);
sendSocket.setMulticastTTL(1);
sendSocket.setMulticastLoopback(true);

0 comments on commit 2775c0e

Please sign in to comment.
You can’t perform that action at this time.