2022-05-15 21:54:06 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const net = require('net');
|
|
|
|
|
2023-02-25 19:53:11 +01:00
|
|
|
function barrier(count, cb) {
|
|
|
|
return function() {
|
|
|
|
if (--count === 0)
|
|
|
|
cb();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-05-15 21:54:06 +08:00
|
|
|
const server = net.createServer();
|
|
|
|
server.listen(0, common.mustCall(function() {
|
|
|
|
const port = server.address().port;
|
|
|
|
const conn = net.createConnection(port);
|
2023-02-25 19:53:11 +01:00
|
|
|
const connok = barrier(2, () => conn.resetAndDestroy());
|
2022-05-15 21:54:06 +08:00
|
|
|
conn.on('close', common.mustCall());
|
|
|
|
server.on('connection', (socket) => {
|
2023-02-25 19:53:11 +01:00
|
|
|
connok();
|
2022-05-15 21:54:06 +08:00
|
|
|
socket.on('error', common.expectsError({
|
|
|
|
code: 'ECONNRESET',
|
|
|
|
message: 'read ECONNRESET',
|
|
|
|
name: 'Error'
|
|
|
|
}));
|
|
|
|
server.close();
|
|
|
|
});
|
2023-02-25 19:53:11 +01:00
|
|
|
conn.on('connect', connok);
|
2022-05-15 21:54:06 +08:00
|
|
|
}));
|