0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

(evcom) Add fix for pausing against big buffers.

discussion:
http://groups.google.com/group/nodejs/browse_thread/thread/11a920da4d0ed21d
This commit is contained in:
Ryan 2009-08-10 12:14:41 +02:00
parent 0638a3a3ab
commit 738d20f6f0
3 changed files with 79 additions and 6 deletions

6
deps/evcom/evcom.c vendored
View File

@ -853,9 +853,9 @@ on_io_event(EV_P_ ev_io *watcher, int revents)
while (have_read_event || have_write_event) {
/* RECV LOOP - TRY TO CLEAR THE BUFFER */
if (stream->read_action == NULL) {
if (stream->read_action == NULL || !ev_is_active(&stream->read_watcher)) {
have_read_event = FALSE;
} else {
} else {
r = stream->read_action(stream);
if (r == AGAIN) {
@ -866,7 +866,7 @@ on_io_event(EV_P_ ev_io *watcher, int revents)
}
/* SEND LOOP - TRY TO CLEAR THE BUFFER */
if (stream->write_action == NULL) {
if (stream->write_action == NULL || !ev_is_active(&stream->write_watcher)) {
have_write_event = FALSE;
} else {
r = stream->write_action(stream);

View File

@ -0,0 +1,57 @@
include("mjsunit.js");
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);
server = node.tcp.createServer(function (connection) {
connection.addListener("connect", function () {
connection.send(body);
connection.fullClose();
});
});
server.listen(PORT);
chars_recved = 0;
npauses = 0;
function onLoad () {
var paused = false;
client = node.tcp.createConnection(PORT);
client.setEncoding("ascii");
client.addListener("receive", function (d) {
chars_recved += d.length;
puts("got " + chars_recved);
if (!paused) {
client.readPause();
npauses += 1;
paused = true;
puts("pause");
x = chars_recved;
setTimeout(function () {
assertEquals(chars_recved, x);
client.readResume();
puts("resume");
paused = false;
}, 100);
}
});
client.addListener("eof", function () {
server.close();
client.close();
});
}
function onExit () {
assertEquals(N, chars_recved);
assertTrue(npauses > 2);
}

View File

@ -31,15 +31,31 @@ function onLoad () {
setTimeout(function () {
chars_recved = recv.length;
puts("chars_recved: " + chars_recved);
puts("pause at: " + chars_recved);
assertTrue(chars_recved > 1);
client.readPause();
setTimeout(function () {
puts("chars_recved: " + chars_recved);
puts("resume at: " + chars_recved);
assertEquals(chars_recved, recv.length);
client.readResume();
setTimeout(function () {
chars_recved = recv.length;
puts("pause at: " + chars_recved);
client.readPause();
setTimeout(function () {
puts("resume at: " + chars_recved);
assertEquals(chars_recved, recv.length);
client.readResume();
}, 500);
}, 500);
}, 500);
}, 100);
}, 500);
client.addListener("eof", function () {
server.close();