diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2010-11-15 20:22:54 -0800 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-11-15 20:22:54 -0800 |
commit | 4144024e6b5d221d5aaf85771d17e382c79a20fe (patch) | |
tree | ff77637c34c27ae607bfff22de33059d7a67322e | |
parent | 939fba40fd55d67f873e2edc89503029c616c17e (diff) | |
download | nodejs-4144024e6b5d221d5aaf85771d17e382c79a20fe.tar.gz nodejs-4144024e6b5d221d5aaf85771d17e382c79a20fe.tar.bz2 nodejs-4144024e6b5d221d5aaf85771d17e382c79a20fe.zip |
Test and fix for self-assigned port from net.Server
-rw-r--r-- | lib/net.js | 2 | ||||
-rw-r--r-- | test/simple/test-net-server-listen-assigned-port.js | 19 |
2 files changed, 20 insertions, 1 deletions
diff --git a/lib/net.js b/lib/net.js index 65a8c5e55..b9bbad776 100644 --- a/lib/net.js +++ b/lib/net.js @@ -1075,7 +1075,7 @@ Server.prototype.listen = function () { self.addListener('listening', lastArg); } - var port = toPort(arguments[0]); + var port = toPort(arguments[0] != lastArg ? arguments[0] : null); if (port === false) { // the first argument specifies a path self.fd = socket('unix'); diff --git a/test/simple/test-net-server-listen-assigned-port.js b/test/simple/test-net-server-listen-assigned-port.js new file mode 100644 index 000000000..4bfffec44 --- /dev/null +++ b/test/simple/test-net-server-listen-assigned-port.js @@ -0,0 +1,19 @@ +var common = require('../common'); +net = require('net'); +assert = require('assert'); + +var address; + +var server = net.createServer(function (socket) { +}); + +server.listen(function() { + address = server.address(); + console.log("opened server on %j", address); + server.close(); +}); + +process.on('exit', function () { + assert.ok(address.port > 100); +}); + |