From 0d31e9875f782c476e6f85791ceb8ae8a6758ae8 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 30 Dec 2009 10:43:47 -0800 Subject: [PATCH] [net2] socket.setNoDelay --- lib/net.js | 6 ++++++ src/node_net2.cc | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/net.js b/lib/net.js index 035272781d..72d852da7b 100644 --- a/lib/net.js +++ b/lib/net.js @@ -19,6 +19,7 @@ var shutdown = process.shutdown; var read = process.read; var write = process.write; var toRead = process.toRead; +var setNoDelay = process.setNoDelay; var socketError = process.socketError; var getsockname = process.getsockname; var getaddrinfo = process.getaddrinfo; @@ -339,6 +340,11 @@ Socket.prototype.address = function () { }; +Socket.prototype.setNoDelay = function (v) { + setNoDelay(this.fd, v); +}; + + Socket.prototype.forceClose = function (exception) { if (this.fd) { this.readable = false; diff --git a/src/node_net2.cc b/src/node_net2.cc index 4056fc28d8..7b7108ad8d 100644 --- a/src/node_net2.cc +++ b/src/node_net2.cc @@ -546,6 +546,23 @@ static Handle ToRead(const Arguments& args) { } +static Handle SetNoDelay(const Arguments& args) { + int flags, r; + HandleScope scope; + + FD_ARG(args[0]) + + flags = args[1]->IsFalse() ? 0 : 1; + r = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (void *)&flags, sizeof(flags)); + + if (r < 0) { + return ThrowException(ErrnoException(errno, "setsockopt")); + } + + return Undefined(); +} + + // G E T A D D R I N F O struct resolve_request { @@ -739,6 +756,7 @@ void InitNet2(Handle target) { NODE_SET_METHOD(target, "accept", Accept); NODE_SET_METHOD(target, "socketError", SocketError); NODE_SET_METHOD(target, "toRead", ToRead); + NODE_SET_METHOD(target, "setNoDelay", SetNoDelay); NODE_SET_METHOD(target, "getsocksame", GetSockName); NODE_SET_METHOD(target, "getaddrinfo", GetAddrInfo); NODE_SET_METHOD(target, "needsLookup", NeedsLookup);