Browse Source

[net2] socket.setNoDelay

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
0d31e9875f
  1. 6
      lib/net.js
  2. 18
      src/node_net2.cc

6
lib/net.js

@ -19,6 +19,7 @@ var shutdown = process.shutdown;
var read = process.read; var read = process.read;
var write = process.write; var write = process.write;
var toRead = process.toRead; var toRead = process.toRead;
var setNoDelay = process.setNoDelay;
var socketError = process.socketError; var socketError = process.socketError;
var getsockname = process.getsockname; var getsockname = process.getsockname;
var getaddrinfo = process.getaddrinfo; 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) { Socket.prototype.forceClose = function (exception) {
if (this.fd) { if (this.fd) {
this.readable = false; this.readable = false;

18
src/node_net2.cc

@ -546,6 +546,23 @@ static Handle<Value> ToRead(const Arguments& args) {
} }
static Handle<Value> 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 // G E T A D D R I N F O
struct resolve_request { struct resolve_request {
@ -739,6 +756,7 @@ void InitNet2(Handle<Object> target) {
NODE_SET_METHOD(target, "accept", Accept); NODE_SET_METHOD(target, "accept", Accept);
NODE_SET_METHOD(target, "socketError", SocketError); NODE_SET_METHOD(target, "socketError", SocketError);
NODE_SET_METHOD(target, "toRead", ToRead); NODE_SET_METHOD(target, "toRead", ToRead);
NODE_SET_METHOD(target, "setNoDelay", SetNoDelay);
NODE_SET_METHOD(target, "getsocksame", GetSockName); NODE_SET_METHOD(target, "getsocksame", GetSockName);
NODE_SET_METHOD(target, "getaddrinfo", GetAddrInfo); NODE_SET_METHOD(target, "getaddrinfo", GetAddrInfo);
NODE_SET_METHOD(target, "needsLookup", NeedsLookup); NODE_SET_METHOD(target, "needsLookup", NeedsLookup);

Loading…
Cancel
Save