`function () { }`
-Emitted if the stream times out from inactivity. The
-`'close'` event will be emitted immediately following this event.
+Emitted if the stream times out from inactivity. This is only to notify that
+the stream has been idle. The user must manually close the connection.
+
+See also: `stream.setTimeout()`
+
### Event: 'drain'
### stream.setTimeout(timeout)
Sets the stream to timeout after `timeout` milliseconds of inactivity on
-the stream. By default all `net.Stream` objects have a timeout of 60
-seconds (60000 ms).
+the stream. By default `net.Stream` do not have a timeout.
+
+When an idle timeout is triggered the stream will receive a `'timeout'`
+event but the connection will not be severed. The user must manually `end()`
+or `destroy()` the stream.
-If `timeout` is 0, then the idle timeout is disabled.
+If `timeout` is 0, then the existing idle timeout is disabled.
### stream.setNoDelay(noDelay=true)
remove(first);
assert(first != peek(list));
first.emit('timeout');
- first.destroy(new Error('idle timeout'));
}
}
debug(msecs + ' list empty');
};
Stream.prototype.setTimeout = function (msecs) {
- timeout.enroll(this, msecs);
+ if (msecs > 0) {
+ timeout.enroll(this, msecs);
+ if (this.fd) { timeout.active(this); }
+ }
};
timeouttime = null;
timeout = 1000;
-gotError = false
-
var echo_server = net.createServer(function (socket) {
socket.setTimeout(timeout);
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) {
});
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 () {
// Allow for 800 milliseconds more
assert.ok(diff < timeout + 800);
-
- assert.ok(gotError);
});
--- /dev/null
+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);
+ });
+});