2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2017-01-19 11:18:51 -05:00
|
|
|
const common = require('../common');
|
2015-12-18 01:35:23 -05:00
|
|
|
const assert = require('assert');
|
|
|
|
const net = require('net');
|
2014-02-09 14:59:31 +04:00
|
|
|
|
2016-01-25 15:00:06 -08:00
|
|
|
const buf = Buffer.alloc(10 * 1024 * 1024, 0x62);
|
2014-02-09 14:59:31 +04:00
|
|
|
|
2015-12-18 01:35:23 -05:00
|
|
|
const errs = [];
|
2017-01-08 13:19:00 +00:00
|
|
|
let clientSocket;
|
|
|
|
let serverSocket;
|
2015-12-18 01:35:23 -05:00
|
|
|
|
|
|
|
function ready() {
|
|
|
|
if (clientSocket && serverSocket) {
|
|
|
|
clientSocket.destroy();
|
|
|
|
serverSocket.write(buf);
|
|
|
|
}
|
|
|
|
}
|
2014-02-09 14:59:31 +04:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const srv = net.createServer(function onConnection(conn) {
|
2015-05-19 13:00:06 +02:00
|
|
|
conn.on('error', function(err) {
|
2014-02-09 14:59:31 +04:00
|
|
|
errs.push(err);
|
|
|
|
if (errs.length > 1 && errs[0] === errs[1])
|
2017-01-19 11:18:51 -05:00
|
|
|
common.fail('Should not emit the same error twice');
|
2014-02-09 14:59:31 +04:00
|
|
|
});
|
2014-02-10 11:21:09 -08:00
|
|
|
conn.on('close', function() {
|
|
|
|
srv.unref();
|
|
|
|
});
|
2015-12-18 01:35:23 -05:00
|
|
|
serverSocket = conn;
|
|
|
|
ready();
|
2016-05-29 03:06:56 -04:00
|
|
|
}).listen(0, function() {
|
2017-01-08 13:19:00 +00:00
|
|
|
const client = net.connect({ port: this.address().port });
|
2014-02-09 14:59:31 +04:00
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
client.on('connect', function() {
|
2015-12-18 01:35:23 -05:00
|
|
|
clientSocket = client;
|
|
|
|
ready();
|
2014-02-09 14:59:31 +04:00
|
|
|
});
|
2014-02-10 11:21:09 -08:00
|
|
|
});
|
2014-02-09 14:59:31 +04:00
|
|
|
|
|
|
|
process.on('exit', function() {
|
2014-02-10 11:21:09 -08:00
|
|
|
console.log(errs);
|
2017-01-08 15:36:25 +00:00
|
|
|
assert.strictEqual(errs.length, 1);
|
2014-02-09 14:59:31 +04:00
|
|
|
});
|