2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2011-04-13 12:19:15 -04:00
|
|
|
var common = require('../common');
|
|
|
|
var assert = require('assert');
|
|
|
|
|
|
|
|
var net = require('net');
|
|
|
|
|
2011-08-11 17:41:30 +02:00
|
|
|
var conns = 0, conns_closed = 0;
|
2011-04-13 12:19:15 -04:00
|
|
|
|
2015-03-19 09:27:26 +11:00
|
|
|
var remoteAddrCandidates = [ common.localhostIPv4 ];
|
2014-08-11 13:29:00 -07:00
|
|
|
if (common.hasIPv6) remoteAddrCandidates.push('::ffff:127.0.0.1');
|
|
|
|
|
|
|
|
var remoteFamilyCandidates = ['IPv4'];
|
|
|
|
if (common.hasIPv6) remoteFamilyCandidates.push('IPv6');
|
|
|
|
|
2011-04-13 12:19:15 -04:00
|
|
|
var server = net.createServer(function(socket) {
|
|
|
|
conns++;
|
2014-08-11 13:29:00 -07:00
|
|
|
assert.notEqual(-1, remoteAddrCandidates.indexOf(socket.remoteAddress));
|
|
|
|
assert.notEqual(-1, remoteFamilyCandidates.indexOf(socket.remoteFamily));
|
2011-09-05 02:09:24 +02:00
|
|
|
assert.ok(socket.remotePort);
|
2016-05-29 03:06:56 -04:00
|
|
|
assert.notEqual(socket.remotePort, this.address().port);
|
2011-04-13 12:19:15 -04:00
|
|
|
socket.on('end', function() {
|
2011-08-11 17:41:30 +02:00
|
|
|
if (++conns_closed == 2) server.close();
|
2011-04-13 12:19:15 -04:00
|
|
|
});
|
2015-03-10 16:48:19 -04:00
|
|
|
socket.on('close', function() {
|
|
|
|
assert.notEqual(-1, remoteAddrCandidates.indexOf(socket.remoteAddress));
|
|
|
|
assert.notEqual(-1, remoteFamilyCandidates.indexOf(socket.remoteFamily));
|
|
|
|
});
|
2012-12-13 09:51:31 -08:00
|
|
|
socket.resume();
|
2011-04-13 12:19:15 -04:00
|
|
|
});
|
|
|
|
|
2016-05-29 03:06:56 -04:00
|
|
|
server.listen(0, 'localhost', function() {
|
|
|
|
var client = net.createConnection(this.address().port, 'localhost');
|
|
|
|
var client2 = net.createConnection(this.address().port);
|
2011-04-13 12:19:15 -04:00
|
|
|
client.on('connect', function() {
|
2014-08-11 13:29:00 -07:00
|
|
|
assert.notEqual(-1, remoteAddrCandidates.indexOf(client.remoteAddress));
|
|
|
|
assert.notEqual(-1, remoteFamilyCandidates.indexOf(client.remoteFamily));
|
2016-05-29 03:06:56 -04:00
|
|
|
assert.equal(client.remotePort, server.address().port);
|
2011-04-13 12:19:15 -04:00
|
|
|
client.end();
|
|
|
|
});
|
2015-03-10 16:48:19 -04:00
|
|
|
client.on('close', function() {
|
|
|
|
assert.notEqual(-1, remoteAddrCandidates.indexOf(client.remoteAddress));
|
|
|
|
assert.notEqual(-1, remoteFamilyCandidates.indexOf(client.remoteFamily));
|
|
|
|
});
|
2011-04-13 12:19:15 -04:00
|
|
|
client2.on('connect', function() {
|
2014-08-11 13:29:00 -07:00
|
|
|
assert.notEqual(-1, remoteAddrCandidates.indexOf(client2.remoteAddress));
|
|
|
|
assert.notEqual(-1, remoteFamilyCandidates.indexOf(client2.remoteFamily));
|
2016-05-29 03:06:56 -04:00
|
|
|
assert.equal(client2.remotePort, server.address().port);
|
2011-04-13 12:19:15 -04:00
|
|
|
client2.end();
|
|
|
|
});
|
2015-03-10 16:48:19 -04:00
|
|
|
client2.on('close', function() {
|
|
|
|
assert.notEqual(-1, remoteAddrCandidates.indexOf(client2.remoteAddress));
|
|
|
|
assert.notEqual(-1, remoteFamilyCandidates.indexOf(client2.remoteFamily));
|
|
|
|
});
|
2011-04-13 12:19:15 -04:00
|
|
|
});
|
|
|
|
|
2011-08-11 15:57:03 +02:00
|
|
|
process.on('exit', function() {
|
2011-04-13 12:19:15 -04:00
|
|
|
assert.equal(2, conns);
|
2011-08-11 15:57:03 +02:00
|
|
|
});
|