summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/net.js2
-rw-r--r--test/simple/test-net-server-listen-assigned-port.js19
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);
+});
+