net: honor 'enable' flag in .setNoDelay()
authorBen Noordhuis <info@bnoordhuis.nl>
Thu, 12 Apr 2012 17:13:04 +0000 (19:13 +0200)
committerBen Noordhuis <info@bnoordhuis.nl>
Thu, 12 Apr 2012 17:15:32 +0000 (19:15 +0200)
Fixes #3096.

lib/net.js
src/tcp_wrap.cc

index af74ae1..df29bd2 100644 (file)
@@ -183,9 +183,10 @@ Socket.prototype._onTimeout = function() {
 };
 
 
-Socket.prototype.setNoDelay = function() {
+Socket.prototype.setNoDelay = function(enable) {
+  // backwards compatibility: assume true when `enable` is omitted
   if (this._handle && this._handle.setNoDelay)
-    this._handle.setNoDelay();
+    this._handle.setNoDelay(typeof enable === 'undefined' ? true : !!enable);
 };
 
 
index 2e84f37..79535e1 100644 (file)
@@ -253,7 +253,8 @@ Handle<Value> TCPWrap::SetNoDelay(const Arguments& args) {
 
   UNWRAP
 
-  int r = uv_tcp_nodelay(&wrap->handle_, 1);
+  int enable = static_cast<int>(args[0]->BooleanValue());
+  int r = uv_tcp_nodelay(&wrap->handle_, enable);
   if (r)
     SetErrno(uv_last_error(uv_default_loop()));