Skip to content

Commit

Permalink
net: bring back .setNoDelay() and .setKeepAlive()
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis authored and ry committed Oct 22, 2011
1 parent 401c073 commit ac379b3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@ Socket.prototype._onTimeout = function() {


Socket.prototype.setNoDelay = function() {
/* TODO implement me */
if (this._handle && this._handle.setNoDelay)
this._handle.setNoDelay();
};


Socket.prototype.setKeepAlive = function(setting, msecs) {
/* TODO implement me */
if (this._handle && this._handle.setKeepAlive)
this._handle.setKeepAlive(setting, ~~(msecs / 1000));
};


Expand Down
32 changes: 32 additions & 0 deletions src/tcp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ using v8::TryCatch;
using v8::Context;
using v8::Arguments;
using v8::Integer;
using v8::Undefined;

static Persistent<Function> tcpConstructor;
static Persistent<String> family_symbol;
Expand Down Expand Up @@ -96,6 +97,8 @@ void TCPWrap::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "connect6", Connect6);
NODE_SET_PROTOTYPE_METHOD(t, "getsockname", GetSockName);
NODE_SET_PROTOTYPE_METHOD(t, "getpeername", GetPeerName);
NODE_SET_PROTOTYPE_METHOD(t, "setNoDelay", SetNoDelay);
NODE_SET_PROTOTYPE_METHOD(t, "setKeepAlive", SetKeepAlive);

tcpConstructor = Persistent<Function>::New(t->GetFunction());

Expand Down Expand Up @@ -219,6 +222,35 @@ Handle<Value> TCPWrap::GetPeerName(const Arguments& args) {
}


Handle<Value> TCPWrap::SetNoDelay(const Arguments& args) {
HandleScope scope;

UNWRAP

int r = uv_tcp_nodelay(&wrap->handle_, 1);
if (r)
SetErrno(uv_last_error(uv_default_loop()));

return Undefined();
}


Handle<Value> TCPWrap::SetKeepAlive(const Arguments& args) {
HandleScope scope;

UNWRAP

int enable = args[0]->Int32Value();
unsigned int delay = args[1]->Uint32Value();

int r = uv_tcp_keepalive(&wrap->handle_, enable, delay);
if (r)
SetErrno(uv_last_error(uv_default_loop()));

return Undefined();
}


Handle<Value> TCPWrap::Bind(const Arguments& args) {
HandleScope scope;

Expand Down
2 changes: 2 additions & 0 deletions src/tcp_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class TCPWrap : public StreamWrap {
static v8::Handle<v8::Value> New(const v8::Arguments& args);
static v8::Handle<v8::Value> GetSockName(const v8::Arguments& args);
static v8::Handle<v8::Value> GetPeerName(const v8::Arguments& args);
static v8::Handle<v8::Value> SetNoDelay(const v8::Arguments& args);
static v8::Handle<v8::Value> SetKeepAlive(const v8::Arguments& args);
static v8::Handle<v8::Value> Bind(const v8::Arguments& args);
static v8::Handle<v8::Value> Bind6(const v8::Arguments& args);
static v8::Handle<v8::Value> Listen(const v8::Arguments& args);
Expand Down

0 comments on commit ac379b3

Please sign in to comment.