summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2009-03-24 15:35:46 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2009-03-24 15:35:46 -0400
commitf1a5c194580729f1db702d9eb28d3af414ea0a7e (patch)
treed793977e8a9a16b88dc9decb0fef10c82be4fa78 /lib
parentebe66ec08034dc1bc36d8b1eb7d66103de98390f (diff)
Variable timeouts and client keep-alive
Diffstat (limited to 'lib')
-rw-r--r--lib/js/urweb.js24
1 files changed, 19 insertions, 5 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js
index be1aea08..6d405347 100644
--- a/lib/js/urweb.js
+++ b/lib/js/urweb.js
@@ -141,6 +141,7 @@ function cr(n) {
var client_id = 0;
var client_pass = 0;
var url_prefix = "/";
+var timeout = 60;
function getXHR(uri)
{
@@ -234,8 +235,18 @@ function newChannel() {
function listener() {
var uri = path_join(url_prefix, ".msgs");
var xhr = getXHR();
- var orsc = function() {
+ var tid, orsc, onTimeout;
+
+ var connect = function () {
+ xhr.onreadystatechange = orsc;
+ tid = window.setTimeout(onTimeout, timeout * 500);
+ requestUri(xhr, uri);
+ }
+
+ orsc = function() {
if (xhr.readyState == 4) {
+ window.clearTimeout(tid);
+
var isok = false;
try {
@@ -271,8 +282,7 @@ function listener() {
}
}
- xhr.onreadystatechange = orsc;
- requestUri(xhr, uri);
+ connect();
}
else {
try {
@@ -282,8 +292,12 @@ function listener() {
}
};
- xhr.onreadystatechange = orsc;
- requestUri(xhr, uri);
+ onTimeout = function() {
+ xhr.abort();
+ connect();
+ };
+
+ connect();
}
function rv(chn, parse, k) {