From 48ccbb9afafd8f9bd2c3a93ac9db51afb2259f6c Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 28 Dec 2009 17:01:49 +0100 Subject: [PATCH] [net2] lower-case socket.type --- lib/net.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/net.js b/lib/net.js index 1b1d285f27b..89688b1f03a 100644 --- a/lib/net.js +++ b/lib/net.js @@ -284,10 +284,12 @@ Socket.prototype.connect = function () { if (self.fd) throw new Error('Socket already opened'); if (typeof(arguments[0]) == 'string' && arguments.length == 1) { - self.fd = process.socket('UNIX'); + self.fd = socket('unix'); + self.type = 'unix'; // TODO check if sockfile exists? } else { - self.fd = process.socket('TCP'); + self.fd = socket('tcp'); + self.type = 'tcp'; // TODO dns resolution on arguments[1] } @@ -386,14 +388,22 @@ exports.createServer = function (listener) { }; +// Listen on a UNIX socket +// server.listen("/tmp/socket"); +// +// Listen on port 8000, accept connections from INADDR_ANY. +// server.listen(8000); +// +// Listen on port 8000, accept connections to "192.168.1.2" +// server.listen(8000, "192.168.1.2"); Server.prototype.listen = function () { var self = this; if (self.fd) throw new Error('Server already opened'); if (typeof(arguments[0]) == 'string' && arguments.length == 1) { // the first argument specifies a path - self.fd = process.socket('UNIX'); - self.type = 'UNIX'; + self.fd = socket('unix'); + self.type = 'unix'; // TODO unlink sockfile if exists? // if (lstat(SOCKFILE, &tstat) == 0) { // assert(S_ISSOCK(tstat.st_mode)); @@ -401,14 +411,14 @@ Server.prototype.listen = function () { // } bind(self.fd, arguments[0]); } else if (arguments.length == 0) { - self.fd = process.socket('TCP'); - self.type = 'TCP'; + self.fd = socket('tcp'); + self.type = 'tcp'; // Don't bind(). OS will assign a port with INADDR_ANY. The port will be // passed to the 'listening' event. } else { // the first argument is the port, the second an IP - self.fd = process.socket('TCP'); - self.type = 'TCP'; + self.fd = socket('tcp'); + self.type = 'tcp'; if (needsLookup(arguments[1])) { getaddrinfo(arguments[1], function (ip) { });