summaryrefslogtreecommitdiff
path: root/test/parallel/test-net-socket-local-address.js
diff options
context:
space:
mode:
authorRyan Graham <r.m.graham@gmail.com>2015-07-02 15:26:21 -0700
committerSam Roberts <vieuxtech@gmail.com>2015-08-06 10:45:59 -0700
commit5d2acfb8e5d00549152995ee671ff168d5c00e38 (patch)
tree72f8b9ab98077654f112b63835dc6ebec2bdbeb6 /test/parallel/test-net-socket-local-address.js
parent67987d9d83517e8d812f13dc5e9eca1d1b9d21ac (diff)
downloadnode-new-5d2acfb8e5d00549152995ee671ff168d5c00e38.tar.gz
net: ensure Socket reported address is current
Any time the connection state or the underlying handle itself changes, the socket's name (aka, local address) can change. To deal with this we need to reset the cached sockname any time we set or unset the internal handle or an existing handle establishes a connection. PR-URL: https://github.com/nodejs/io.js/pull/2095 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'test/parallel/test-net-socket-local-address.js')
-rw-r--r--test/parallel/test-net-socket-local-address.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/parallel/test-net-socket-local-address.js b/test/parallel/test-net-socket-local-address.js
new file mode 100644
index 0000000000..4c0e31d08c
--- /dev/null
+++ b/test/parallel/test-net-socket-local-address.js
@@ -0,0 +1,34 @@
+'use strict';
+var common = require('../common');
+var assert = require('assert');
+var net = require('net');
+
+var conns = 0;
+var clientLocalPorts = [];
+var serverRemotePorts = [];
+
+var server = net.createServer(function(socket) {
+ serverRemotePorts.push(socket.remotePort);
+ conns++;
+});
+
+var client = new net.Socket();
+
+server.on('close', function() {
+ assert.deepEqual(clientLocalPorts, serverRemotePorts,
+ 'client and server should agree on the ports used');
+ assert.equal(2, conns);
+});
+
+server.listen(common.PORT, common.localhostIPv4, testConnect);
+
+function testConnect() {
+ if (conns == 2) {
+ return server.close();
+ }
+ client.connect(common.PORT, common.localhostIPv4, function() {
+ clientLocalPorts.push(this.localPort);
+ this.once('close', testConnect);
+ this.destroy();
+ });
+}