Mercurial > urweb
comparison lib/js/urweb.js @ 673:a8effb6159c2
Variable timeouts and client keep-alive
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Tue, 24 Mar 2009 15:35:46 -0400 |
parents | df6eb58de040 |
children | 44f23712020d |
comparison
equal
deleted
inserted
replaced
672:df6eb58de040 | 673:a8effb6159c2 |
---|---|
139 | 139 |
140 | 140 |
141 var client_id = 0; | 141 var client_id = 0; |
142 var client_pass = 0; | 142 var client_pass = 0; |
143 var url_prefix = "/"; | 143 var url_prefix = "/"; |
144 var timeout = 60; | |
144 | 145 |
145 function getXHR(uri) | 146 function getXHR(uri) |
146 { | 147 { |
147 try { | 148 try { |
148 return new XMLHttpRequest(); | 149 return new XMLHttpRequest(); |
232 } | 233 } |
233 | 234 |
234 function listener() { | 235 function listener() { |
235 var uri = path_join(url_prefix, ".msgs"); | 236 var uri = path_join(url_prefix, ".msgs"); |
236 var xhr = getXHR(); | 237 var xhr = getXHR(); |
237 var orsc = function() { | 238 var tid, orsc, onTimeout; |
239 | |
240 var connect = function () { | |
241 xhr.onreadystatechange = orsc; | |
242 tid = window.setTimeout(onTimeout, timeout * 500); | |
243 requestUri(xhr, uri); | |
244 } | |
245 | |
246 orsc = function() { | |
238 if (xhr.readyState == 4) { | 247 if (xhr.readyState == 4) { |
248 window.clearTimeout(tid); | |
249 | |
239 var isok = false; | 250 var isok = false; |
240 | 251 |
241 try { | 252 try { |
242 if (xhr.status == 200) | 253 if (xhr.status == 200) |
243 isok = true; | 254 isok = true; |
269 } else { | 280 } else { |
270 listener(msg); | 281 listener(msg); |
271 } | 282 } |
272 } | 283 } |
273 | 284 |
274 xhr.onreadystatechange = orsc; | 285 connect(); |
275 requestUri(xhr, uri); | |
276 } | 286 } |
277 else { | 287 else { |
278 try { | 288 try { |
279 whine("Error querying remote server for messages! " + xhr.status); | 289 whine("Error querying remote server for messages! " + xhr.status); |
280 } catch (e) { } | 290 } catch (e) { } |
281 } | 291 } |
282 } | 292 } |
283 }; | 293 }; |
284 | 294 |
285 xhr.onreadystatechange = orsc; | 295 onTimeout = function() { |
286 requestUri(xhr, uri); | 296 xhr.abort(); |
297 connect(); | |
298 }; | |
299 | |
300 connect(); | |
287 } | 301 } |
288 | 302 |
289 function rv(chn, parse, k) { | 303 function rv(chn, parse, k) { |
290 if (chn < 0) | 304 if (chn < 0) |
291 whine("Out-of-bounds channel receive"); | 305 whine("Out-of-bounds channel receive"); |