mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
Idle timeout changes
- setTimeout should active the timeout too. (test-net-set-timeout tests this.) - 'timeout' event is not automatically followed by an 'error' event. That is the user is now responsible for destroying the stream if there is an idle timeout.
This commit is contained in:
1 parent
f7ff548dd0
commit
d2cff34fa3
4 files changed
+57
-15
No files matched your search
@@ -5,8 +5,6 @@ starttime = null;
|
||||
timeouttime = null;
|
||||
timeout = 1000;
|
||||
|
||||
gotError = false
|
||||
|
||||
var echo_server = net.createServer(function (socket) {
|
||||
socket.setTimeout(timeout);
|
||||
|
||||
@@ -14,11 +12,11 @@ var echo_server = net.createServer(function (socket) {
|
||||
puts("server timeout");
|
||||
timeouttime = new Date;
|
||||
p(timeouttime);
|
||||
socket.destroy();
|
||||
});
|
||||
|
||||
socket.addListener("error", function (e) {
|
||||
assert.ok(e instanceof Error);
|
||||
gotError = true;
|
||||
throw new Error("Server side socket should not get error. We disconnect willingly.");
|
||||
})
|
||||
|
||||
socket.addListener("data", function (d) {
|
||||
@@ -59,8 +57,7 @@ client.addListener("data", function (chunk) {
|
||||
});
|
||||
|
||||
client.addListener("timeout", function () {
|
||||
puts("client timeout - this shouldn't happen");
|
||||
assert.ok(false);
|
||||
throw new Error("client timeout - this shouldn't happen");
|
||||
});
|
||||
|
||||
client.addListener("end", function () {
|
||||
@@ -84,6 +81,4 @@ process.addListener("exit", function () {
|
||||
|
||||
// Allow for 800 milliseconds more
|
||||
assert.ok(diff < timeout + 800);
|
||||
|
||||
assert.ok(gotError);
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
require("../common");
|
||||
var sys = require('sys'),
|
||||
http = require('http');
|
||||
|
||||
server = http.createServer(function (req, res) {
|
||||
sys.puts('got request. setting 1 second timeout');
|
||||
req.connection.setTimeout(500);
|
||||
|
||||
req.connection.addListener('timeout', function(){
|
||||
sys.debug("TIMEOUT");
|
||||
|
||||
var body="timeout\n";
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'text/plain',
|
||||
'Content-Length': body.length,
|
||||
'Connection':'close'
|
||||
});
|
||||
res.end(body);
|
||||
req.connection.end();
|
||||
server.close();
|
||||
});
|
||||
});
|
||||
server.listen(8000);
|
||||
|
||||
|
||||
server.addListener('listening', function () {
|
||||
sys.puts('Server running at http://127.0.0.1:8000/');
|
||||
|
||||
errorTimer =setTimeout(function () {
|
||||
throw new Error('Timeout was not sucessful');
|
||||
}, 2000);
|
||||
|
||||
http.cat('http://localhost:8000/', 'utf8', function (err, content) {
|
||||
clearTimeout(errorTimer);
|
||||
if (err) throw err;
|
||||
sys.puts('HTTP REQUEST COMPLETE (this is good)');
|
||||
sys.puts(content);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user