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() {
|
2012-02-11 18:05:30 +01:00
|
|
|
assert.fail('flushed: ' + flushed +
|
|
|
|
', 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);
|
|
|
|
});
|