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.
57 lines
1.1 KiB
57 lines
1.1 KiB
15 years ago
|
process.mixin(require("../common"));
|
||
15 years ago
|
tcp = require("tcp");
|
||
16 years ago
|
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);
|
||
|
|
||
15 years ago
|
server = tcp.createServer(function (connection) {
|
||
16 years ago
|
connection.addListener("connect", function () {
|
||
15 years ago
|
connection.write(body);
|
||
16 years ago
|
connection.close();
|
||
16 years ago
|
});
|
||
|
});
|
||
|
server.listen(PORT);
|
||
|
|
||
|
|
||
|
chars_recved = 0;
|
||
|
npauses = 0;
|
||
|
|
||
|
|
||
16 years ago
|
var paused = false;
|
||
15 years ago
|
client = tcp.createConnection(PORT);
|
||
16 years ago
|
client.setEncoding("ascii");
|
||
15 years ago
|
client.addListener("data", function (d) {
|
||
16 years ago
|
chars_recved += d.length;
|
||
|
puts("got " + chars_recved);
|
||
|
if (!paused) {
|
||
15 years ago
|
client.pause();
|
||
16 years ago
|
npauses += 1;
|
||
|
paused = true;
|
||
|
puts("pause");
|
||
|
x = chars_recved;
|
||
|
setTimeout(function () {
|
||
15 years ago
|
assert.equal(chars_recved, x);
|
||
15 years ago
|
client.resume();
|
||
16 years ago
|
puts("resume");
|
||
|
paused = false;
|
||
|
}, 100);
|
||
|
}
|
||
|
});
|
||
16 years ago
|
|
||
15 years ago
|
client.addListener("end", function () {
|
||
16 years ago
|
server.close();
|
||
|
client.close();
|
||
|
});
|
||
16 years ago
|
|
||
16 years ago
|
process.addListener("exit", function () {
|
||
15 years ago
|
assert.equal(N, chars_recved);
|
||
|
assert.equal(true, npauses > 2);
|
||
16 years ago
|
});
|