summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2011-06-29 15:24:55 +0200
committerRyan Dahl <ry@tinyclouds.org>2011-06-29 15:25:11 +0200
commit20996dbc2b5474b3b289f2b79f72eeed26f2a0ec (patch)
tree26c777c9fad7fed2482295b335d435aa7e9816a0
parentd64e070e26cc3545367ef38098a0fe963be0ea8d (diff)
downloadnode-new-20996dbc2b5474b3b289f2b79f72eeed26f2a0ec.tar.gz
Revert "Add support for file descriptor type detection."
This reverts commit 911cbd0cef02c93f821c0c80a3d5dbad2b692c42. This patch is broken on Linux and I don't want to think about the functionality during the Windows port. We can reconsider it after v0.6.
-rw-r--r--lib/net_legacy.js36
-rw-r--r--src/node_net.cc72
-rw-r--r--test/simple/test-gets-auto-fd.js24
3 files changed, 4 insertions, 128 deletions
diff --git a/lib/net_legacy.js b/lib/net_legacy.js
index 941c80eb3d..4254dc9a44 100644
--- a/lib/net_legacy.js
+++ b/lib/net_legacy.js
@@ -226,7 +226,7 @@ function Socket(options) {
this.allowHalfOpen = options.allowHalfOpen || false;
} else if (typeof options == 'number') {
this.fd = arguments[0];
- this.type = arguments[1] || null;
+ this.type = arguments[1];
}
if (parseInt(this.fd, 10) >= 0) {
@@ -235,7 +235,6 @@ function Socket(options) {
setImplmentationMethods(this);
}
}
-
util.inherits(Socket, stream.Stream);
exports.Socket = Socket;
@@ -251,7 +250,7 @@ Socket.prototype.open = function(fd, type) {
initSocket(this);
this.fd = fd;
- this.type = type || getFdType(fd)
+ this.type = type || null;
this.readable = true;
setImplmentationMethods(this);
@@ -1147,43 +1146,16 @@ Server.prototype.close = function() {
}
};
-function getFdType(fd) {
- var type = 'file';
- var family;
- try {
- type = binding.getsocktype(fd);
- family = binding.getsockfamily(fd);
- if (family == "AF_UNIX") {
- type = "unix";
- } else if (type == "SOCK_STREAM" && family == "AF_INET") {
- type = "tcp";
- } else if (type == "SOCK_STREAM" && family == "AF_INET6") {
- type = "tcp6";
- } else if (type == "SOCK_DGRAM" && family == "AF_INET") {
- type = "udp";
- } else if (type == "SOCK_DGRAM" && family == "AF_INET6") {
- type = "udp6";
- }
- } catch (e) {
- if (e.code == 'ENOTSOCK') {
- type = 'file';
- } else {
- throw e;
- }
- }
- return type;
-}
-exports.getFdType = getFdType;
var dummyFD = null;
var lastEMFILEWarning = 0;
-// Ensures to have at least one free file-descriptor free.
+// Ensures to have at least on free file-descriptor free.
// callback should only use 1 file descriptor and close it before end of call
function rescueEMFILE(callback) {
// Output a warning, but only at most every 5 seconds.
var now = new Date();
if (now - lastEMFILEWarning > 5000) {
- console.error('(node) Hit max file limit. Increase "ulimit -n"');
+ console.error('(node) Hit max file limit. Increase "ulimit - n"');
lastEMFILEWarning = now;
}
diff --git a/src/node_net.cc b/src/node_net.cc
index d2017d5cad..a0bda02035 100644
--- a/src/node_net.cc
+++ b/src/node_net.cc
@@ -591,42 +591,6 @@ static Handle<Value> GetSockName(const Arguments& args) {
return scope.Close(info);
}
-static Handle<Value> GetSockFamily(const Arguments& args) {
- HandleScope scope;
-
- FD_ARG(args[0])
-
- Local<Value> result;
-
- struct sockaddr_storage address_storage;
- socklen_t len = sizeof(struct sockaddr_storage);
-
-#ifdef __POSIX__
- if (0 > getsockname(fd, (struct sockaddr *) &address_storage, &len)) {
- return ThrowException(ErrnoException(errno, "getsockname"));
- }
-
-#else // __MINGW32__
- if (SOCKET_ERROR == getsockname(_get_osfhandle(fd),
- (struct sockaddr *) &address_storage, &len)) {
- return ThrowException(ErrnoException(WSAGetLastError(), "getsockname"));
- }
-#endif // __MINGW32__
- switch ((address_storage).ss_family) {
- case AF_INET6:
- result = String::New("AF_INET6");
- break;
- case AF_INET:
- result = String::New("AF_INET");
- break;
- case AF_UNIX:
- result = String::New("AF_UNIX");
- break;
- default:
- result = Integer::New((address_storage).ss_family);
- }
- scope.Close(result);
-}
static Handle<Value> GetPeerName(const Arguments& args) {
HandleScope scope;
@@ -756,40 +720,6 @@ static Handle<Value> SocketError(const Arguments& args) {
return scope.Close(Integer::New(error));
}
-static Handle<Value> GetSockType(const Arguments& args) {
- HandleScope scope;
-
- FD_ARG(args[0])
-
- int type;
- socklen_t len = sizeof(int);
-
-#ifdef __POSIX__
- int r = getsockopt(fd, SOL_SOCKET, SO_TYPE, &type, &len);
-
- if (r < 0) {
- return ThrowException(ErrnoException(errno, "getsockopt"));
- }
-#else // __MINGW32__
- int r = getsockopt(_get_osfhandle(fd), SOL_SOCKET, SO_TYPE, (char*)&type, &len);
-
- if (r < 0) {
- return ThrowException(ErrnoException(WSAGetLastError(), "getsockopt"));
- }
-#endif
- Local<Value> result;
- switch (type) {
- case SOCK_STREAM:
- result = String::New("SOCK_STREAM");
- break;
- case SOCK_DGRAM:
- result = String::New("SOCK_DGRAM");
- break;
- default:
- result = Integer::New(type);
- }
- return scope.Close(result);
-}
// var bytesRead = t.read(fd, buffer, offset, length);
// returns null on EAGAIN or EINTR, raises an exception on all other errors
@@ -1830,8 +1760,6 @@ void InitNet(Handle<Object> target) {
NODE_SET_METHOD(target, "getaddrinfo", GetAddrInfo);
NODE_SET_METHOD(target, "isIP", IsIP);
NODE_SET_METHOD(target, "errnoException", CreateErrnoException);
- NODE_SET_METHOD(target, "getsocktype", GetSockType);
- NODE_SET_METHOD(target, "getsockfamily", GetSockFamily);
errno_symbol = NODE_PSYMBOL("errno");
syscall_symbol = NODE_PSYMBOL("syscall");
diff --git a/test/simple/test-gets-auto-fd.js b/test/simple/test-gets-auto-fd.js
deleted file mode 100644
index bd0f6627e2..0000000000
--- a/test/simple/test-gets-auto-fd.js
+++ /dev/null
@@ -1,24 +0,0 @@
-var assert = require('assert');
-var net = require('net');
-var common = require('../common');
-
-var server = net.createServer();
-
-//test unix sockets
-var fds = process.binding('net').socketpair();
-var unixsocket = new net.Socket(fds[0]);
-assert.ok(unixsocket.type == 'unix', 'Should be UNIX');
-
-//test that stdin is default file
-assert.ok(process.stdin.type == 'file', 'Should be File');
-
-//test tcp sockets.
-server.listen(function() {
- var client = net.createConnection(this.address().port);
- client.on('connect', function() {
- var newStream = new net.Socket(client.fd);
- assert.ok(newStream.type == 'tcp', 'Should be TCP');
- client.destroy();
- server.close();
- });
-});