2009-08-09 18:49:51 +02:00
|
|
|
include("mjsunit.js");
|
|
|
|
PORT = 20443;
|
2009-08-24 16:51:37 +02:00
|
|
|
N = 200;
|
2009-08-09 18:49:51 +02:00
|
|
|
|
|
|
|
server = node.tcp.createServer(function (connection) {
|
|
|
|
function send (j) {
|
|
|
|
if (j >= N) {
|
2009-08-19 17:28:41 +02:00
|
|
|
connection.close();
|
2009-08-09 18:49:51 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
setTimeout(function () {
|
|
|
|
connection.send("C");
|
|
|
|
send(j+1);
|
|
|
|
}, 10);
|
|
|
|
}
|
|
|
|
send(0);
|
|
|
|
});
|
|
|
|
server.listen(PORT);
|
|
|
|
|
|
|
|
|
|
|
|
recv = "";
|
|
|
|
chars_recved = 0;
|
|
|
|
|
2009-08-26 18:22:00 +02:00
|
|
|
client = node.tcp.createConnection(PORT);
|
|
|
|
client.setEncoding("ascii");
|
|
|
|
client.addListener("receive", function (d) {
|
|
|
|
print(d);
|
|
|
|
recv += d;
|
|
|
|
});
|
2009-08-09 18:49:51 +02:00
|
|
|
|
2009-08-26 18:22:00 +02:00
|
|
|
setTimeout(function () {
|
|
|
|
chars_recved = recv.length;
|
|
|
|
puts("pause at: " + chars_recved);
|
|
|
|
assertTrue(chars_recved > 1);
|
|
|
|
client.readPause();
|
2009-08-09 18:49:51 +02:00
|
|
|
setTimeout(function () {
|
2009-08-26 18:22:00 +02:00
|
|
|
puts("resume at: " + chars_recved);
|
|
|
|
assertEquals(chars_recved, recv.length);
|
|
|
|
client.readResume();
|
|
|
|
|
2009-08-09 18:49:51 +02:00
|
|
|
setTimeout(function () {
|
2009-08-26 18:22:00 +02:00
|
|
|
chars_recved = recv.length;
|
|
|
|
puts("pause at: " + chars_recved);
|
|
|
|
client.readPause();
|
2009-08-10 12:14:41 +02:00
|
|
|
|
|
|
|
setTimeout(function () {
|
2009-08-26 18:22:00 +02:00
|
|
|
puts("resume at: " + chars_recved);
|
|
|
|
assertEquals(chars_recved, recv.length);
|
|
|
|
client.readResume();
|
2009-08-10 12:14:41 +02:00
|
|
|
|
|
|
|
}, 500);
|
|
|
|
|
2009-08-09 18:49:51 +02:00
|
|
|
}, 500);
|
2009-08-10 12:14:41 +02:00
|
|
|
|
|
|
|
}, 500);
|
2009-08-09 18:49:51 +02:00
|
|
|
|
2009-08-26 18:22:00 +02:00
|
|
|
}, 500);
|
|
|
|
|
|
|
|
client.addListener("eof", function () {
|
|
|
|
server.close();
|
|
|
|
client.close();
|
|
|
|
});
|
2009-08-09 18:49:51 +02:00
|
|
|
|
2009-08-26 18:51:04 +02:00
|
|
|
process.addListener("exit", function () {
|
2009-08-09 18:49:51 +02:00
|
|
|
assertEquals(N, recv.length);
|
2009-08-26 18:51:04 +02:00
|
|
|
});
|