2009-10-31 19:02:30 +01:00
|
|
|
process.mixin(require("./common"));
|
|
|
|
tcp = require("tcp");
|
2009-08-10 12:14:41 +02:00
|
|
|
PORT = 20444;
|
|
|
|
N = 30*1024; // 500kb
|
|
|
|
|
|
|
|
puts("build big string");
|
|
|
|
var body = "";
|
|
|
|
for (var i = 0; i < N; i++) {
|
|
|
|
body += "C";
|
|
|
|
}
|
|
|
|
|
|
|
|
puts("start server on port " + PORT);
|
|
|
|
|
2009-09-28 16:08:09 +02:00
|
|
|
server = tcp.createServer(function (connection) {
|
2009-08-10 12:14:41 +02:00
|
|
|
connection.addListener("connect", function () {
|
2010-02-16 22:15:30 +01:00
|
|
|
connection.write(body);
|
2009-08-19 17:28:41 +02:00
|
|
|
connection.close();
|
2009-08-10 12:14:41 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
server.listen(PORT);
|
|
|
|
|
|
|
|
|
|
|
|
chars_recved = 0;
|
|
|
|
npauses = 0;
|
|
|
|
|
|
|
|
|
2009-08-26 18:22:00 +02:00
|
|
|
var paused = false;
|
2009-09-28 16:08:09 +02:00
|
|
|
client = tcp.createConnection(PORT);
|
2009-08-26 18:22:00 +02:00
|
|
|
client.setEncoding("ascii");
|
2010-02-12 09:25:15 +01:00
|
|
|
client.addListener("data", function (d) {
|
2009-08-26 18:22:00 +02:00
|
|
|
chars_recved += d.length;
|
|
|
|
puts("got " + chars_recved);
|
|
|
|
if (!paused) {
|
|
|
|
client.readPause();
|
|
|
|
npauses += 1;
|
|
|
|
paused = true;
|
|
|
|
puts("pause");
|
|
|
|
x = chars_recved;
|
|
|
|
setTimeout(function () {
|
2009-11-28 18:26:59 +01:00
|
|
|
assert.equal(chars_recved, x);
|
2009-08-26 18:22:00 +02:00
|
|
|
client.readResume();
|
|
|
|
puts("resume");
|
|
|
|
paused = false;
|
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
});
|
2009-08-10 12:14:41 +02:00
|
|
|
|
2010-02-12 09:25:15 +01:00
|
|
|
client.addListener("end", function () {
|
2009-08-26 18:22:00 +02:00
|
|
|
server.close();
|
|
|
|
client.close();
|
|
|
|
});
|
2009-08-10 12:14:41 +02:00
|
|
|
|
2009-08-26 18:51:04 +02:00
|
|
|
process.addListener("exit", function () {
|
2009-11-28 18:26:59 +01:00
|
|
|
assert.equal(N, chars_recved);
|
|
|
|
assert.equal(true, npauses > 2);
|
2009-08-26 18:51:04 +02:00
|
|
|
});
|