diff options
author | 2009-03-24 15:35:46 -0400 | |
---|---|---|
committer | 2009-03-24 15:35:46 -0400 | |
commit | f1a5c194580729f1db702d9eb28d3af414ea0a7e (patch) | |
tree | d793977e8a9a16b88dc9decb0fef10c82be4fa78 /lib/js/urweb.js | |
parent | ebe66ec08034dc1bc36d8b1eb7d66103de98390f (diff) |
Variable timeouts and client keep-alive
Diffstat (limited to 'lib/js/urweb.js')
-rw-r--r-- | lib/js/urweb.js | 24 |
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) { |