2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2012-02-03 12:09:30 +01:00
|
|
|
var common = require('../common');
|
|
|
|
var assert = require('assert');
|
|
|
|
var net = require('net');
|
|
|
|
|
2012-02-11 18:05:30 +01:00
|
|
|
var SIZE = 2E5;
|
2012-02-03 12:09:30 +01:00
|
|
|
var N = 10;
|
2012-02-11 18:05:30 +01:00
|
|
|
var flushed = 0;
|
2012-02-03 12:09:30 +01:00
|
|
|
var received = 0;
|
|
|
|
var buf = new Buffer(SIZE);
|
|
|
|
buf.fill(0x61); // 'a'
|
|
|
|
|
|
|
|
var server = net.createServer(function(socket) {
|
|
|
|
socket.setNoDelay();
|
2012-06-12 01:40:04 +02:00
|
|
|
socket.setTimeout(1000);
|
2012-02-03 12:09:30 +01:00
|
|
|
socket.on('timeout', function() {
|
2015-10-15 06:22:55 +02:00
|
|
|
assert.fail(null, null, 'flushed: ' + flushed +
|
2012-02-11 18:05:30 +01:00
|
|
|
', received: ' + received + '/' + SIZE * N);
|
2012-02-03 12:09:30 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
for (var i = 0; i < N; ++i) {
|
2012-02-11 18:05:30 +01:00
|
|
|
socket.write(buf, function() {
|
|
|
|
++flushed;
|
|
|
|
if (flushed === N) {
|
|
|
|
socket.setTimeout(0);
|
|
|
|
}
|
|
|
|
});
|
2012-02-03 12:09:30 +01:00
|
|
|
}
|
|
|
|
socket.end();
|
|
|
|
|
|
|
|
}).listen(common.PORT, function() {
|
|
|
|
var conn = net.connect(common.PORT);
|
|
|
|
conn.on('data', function(buf) {
|
|
|
|
received += buf.length;
|
|
|
|
conn.pause();
|
|
|
|
setTimeout(function() {
|
|
|
|
conn.resume();
|
2012-02-11 18:05:30 +01:00
|
|
|
}, 20);
|
2012-02-03 12:09:30 +01:00
|
|
|
});
|
|
|
|
conn.on('end', function() {
|
|
|
|
server.close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
process.on('exit', function() {
|
|
|
|
assert.equal(received, SIZE * N);
|
|
|
|
});
|