mirror of
https://github.com/nodejs/node.git
synced 2025-05-10 05:30:00 +00:00

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>
35 lines
825 B
JavaScript
35 lines
825 B
JavaScript
'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();
|
|
});
|
|
}
|