2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-07-14 11:26:35 -04:00
|
|
|
const common = require('../common');
|
2016-12-30 18:38:06 -05:00
|
|
|
const assert = require('assert');
|
|
|
|
const net = require('net');
|
2012-02-03 20:09:30 +09:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const SIZE = 2E5;
|
|
|
|
const N = 10;
|
|
|
|
let flushed = 0;
|
|
|
|
let received = 0;
|
|
|
|
const buf = Buffer.alloc(SIZE, 'a');
|
2012-02-03 20:09:30 +09:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const server = net.createServer(function(socket) {
|
2012-02-03 20:09:30 +09:00
|
|
|
socket.setNoDelay();
|
2016-07-05 20:35:08 -07:00
|
|
|
socket.setTimeout(9999);
|
2012-02-03 20:09:30 +09:00
|
|
|
socket.on('timeout', function() {
|
2016-07-14 11:26:35 -04:00
|
|
|
common.fail(`flushed: ${flushed}, received: ${received}/${SIZE * N}`);
|
2012-02-03 20:09:30 +09:00
|
|
|
});
|
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
for (let i = 0; i < N; ++i) {
|
2012-02-12 02:05:30 +09:00
|
|
|
socket.write(buf, function() {
|
|
|
|
++flushed;
|
|
|
|
if (flushed === N) {
|
|
|
|
socket.setTimeout(0);
|
|
|
|
}
|
|
|
|
});
|
2012-02-03 20:09:30 +09:00
|
|
|
}
|
|
|
|
socket.end();
|
|
|
|
|
2016-07-15 15:43:24 -04:00
|
|
|
}).listen(0, common.mustCall(function() {
|
2017-01-08 13:19:00 +00:00
|
|
|
const conn = net.connect(this.address().port);
|
2012-02-03 20:09:30 +09:00
|
|
|
conn.on('data', function(buf) {
|
|
|
|
received += buf.length;
|
|
|
|
conn.pause();
|
|
|
|
setTimeout(function() {
|
|
|
|
conn.resume();
|
2012-02-12 02:05:30 +09:00
|
|
|
}, 20);
|
2012-02-03 20:09:30 +09:00
|
|
|
});
|
2016-07-15 15:43:24 -04:00
|
|
|
conn.on('end', common.mustCall(function() {
|
2012-02-03 20:09:30 +09:00
|
|
|
server.close();
|
2016-07-15 15:43:24 -04:00
|
|
|
assert.strictEqual(received, SIZE * N);
|
|
|
|
}));
|
|
|
|
}));
|