forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest-net-connect-options-ipv6.js
More file actions
56 lines (51 loc) · 1.31 KB
/
Copy pathtest-net-connect-options-ipv6.js
File metadata and controls
56 lines (51 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
if (!common.hasIPv6) {
console.log('1..0 # Skipped: no IPv6 support');
return;
}
const hosts = common.localIPv6Hosts;
var hostIdx = 0;
var host = hosts[hostIdx];
var localhostTries = 10;
const server = net.createServer({allowHalfOpen: true}, function(socket) {
socket.resume();
socket.on('end', common.mustCall(function() {}));
socket.end();
});
server.listen(common.PORT, '::1', tryConnect);
function tryConnect() {
const client = net.connect({
host: host,
port: common.PORT,
family: 6,
allowHalfOpen: true
}, function() {
console.error('client connect cb');
client.resume();
client.on('end', common.mustCall(function() {
setTimeout(function() {
assert(client.writable);
client.end();
}, 10);
}));
client.on('close', function() {
server.close();
});
}).on('error', function(err) {
if (err.syscall === 'getaddrinfo' && err.code === 'ENOTFOUND') {
if (host !== 'localhost' || --localhostTries === 0)
host = hosts[++hostIdx];
if (host)
tryConnect();
else {
console.log('1..0 # Skipped: no IPv6 localhost support');
server.close();
}
return;
}
throw err;
});
}