mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
985 B
47 lines
985 B
13 years ago
|
var common = require('../common');
|
||
|
var assert = require('assert');
|
||
|
var net = require('net');
|
||
|
|
||
13 years ago
|
var SIZE = 2E5;
|
||
13 years ago
|
var N = 10;
|
||
13 years ago
|
var flushed = 0;
|
||
13 years ago
|
var received = 0;
|
||
|
var buf = new Buffer(SIZE);
|
||
|
buf.fill(0x61); // 'a'
|
||
|
|
||
|
var server = net.createServer(function(socket) {
|
||
|
socket.setNoDelay();
|
||
13 years ago
|
socket.setTimeout(1000);
|
||
13 years ago
|
socket.on('timeout', function() {
|
||
13 years ago
|
assert.fail('flushed: ' + flushed +
|
||
|
', received: ' + received + '/' + SIZE * N);
|
||
13 years ago
|
});
|
||
|
|
||
|
for (var i = 0; i < N; ++i) {
|
||
13 years ago
|
socket.write(buf, function() {
|
||
|
++flushed;
|
||
|
if (flushed === N) {
|
||
|
socket.setTimeout(0);
|
||
|
}
|
||
|
});
|
||
13 years ago
|
}
|
||
|
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();
|
||
13 years ago
|
}, 20);
|
||
13 years ago
|
});
|
||
|
conn.on('end', function() {
|
||
|
server.close();
|
||
|
});
|
||
|
});
|
||
|
|
||
|
process.on('exit', function() {
|
||
|
assert.equal(received, SIZE * N);
|
||
|
});
|