X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fxhr.js;h=d023eb39e6b20789951147b6f1bb59622167ada6;hb=26c51203ae8342cf59e9e3946b0cbe89ed7bde95;hp=30819dc22a4be902c5175ce383723ea4bdb9c46a;hpb=f18bac8374119fa1f3c826e82cfc74ce2ce52dd7;p=brisk.git
diff --git a/web/xhr.js b/web/xhr.js
index 30819dc..d023eb3 100644
--- a/web/xhr.js
+++ b/web/xhr.js
@@ -1,7 +1,10 @@
/*
* brisk - xhr.js
*
- * Copyright (C) 2006 matteo.nastasi@milug.org
+ * Copyright (C) 2006-2011 Matteo Nastasi
+ * mailto: nastasi@alternativeoutput.it
+ * matteo.nastasi@milug.org
+ * web: http://www.alternativeoutput.it
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,46 +22,100 @@
*/
var xhr_rd_cookiepath = "/brisk/";
-var xhr_rd = false;
+var xhr_rd = null;
var xhr_rd_stopped = true;
var xhr_rd_oldctx = "";
-var xhr_rd_newctx;
-
+var xhr_rd_newctx = "";
+var xhr_rd_delay = 0;
+var xhr_rd_delayed = null;
var xhr_rd_cur_n = -1;
var xhr_rd_old_n = -1;
var xhr_rd_checkedlen = 0;
+var xhr_rd_watchdog = null;
var the_end = false;
var ct = 0;
var watchdog = 0;
+function hbit(symb)
+{
+ if ($("heartbit").innerHTML.length >= 120) {
+ $("heartbit").innerHTML = $("heartbit").innerHTML.substring(10);
+ $("heartbit").innerHTML += symb;
+ }
+ else {
+ $("heartbit").innerHTML += symb;
+ }
+ // $("heartbit").innerHTML = $("heartbit").innerHTML.substring(20,20); // DA METTERE APPOSTO!!!!
+
+}
+
function xhr_rd_cb(xhr_rd)
{
var ret;
+ // console.log(xhr_rd.readyState);
+
if (xhr_rd.readyState == 4) {
+ if (typeof xhr_rd_watchdog != 'undefined' && xhr_rd_watchdog != null) {
+ hbit('C');
+ clearTimeout(xhr_rd_watchdog);
+ xhr_rd_watchdog = null;
+ }
+
+ // console.log("SS: "+safestatus(xhr_rd));
+
try {
if ((ret = safestatus(xhr_rd)) == 200) {
+ xhr_rd_delay = 0;
+ // console.log("del a null "+xhr_rd_delayed);
} else if (ret != -1) {
- alert('There was a problem with the request.' + ret);
+ xhr_rd_delay = 5000;
+ hbit('X');
+ // alert('There was a problem with the request.' + ret);
}
} catch(b) {};
+ xhr_rd_delayed = null;
xhr_rd_stopped = true;
}
};
+function xhr_rd_abort(xhr)
+{
+ hbit('A');
+ if (xhr != null)
+ xhr.abort();
+ // alert("de che");
+}
+
function xhr_rd_start(sess,stat,subst,step)
{
- if (the_end)
+ if (the_end) {
+ //x alert("the_end1");
+ if (typeof xhr_rd_watchdog != 'undefined' && xhr_rd_watchdog != null) {
+ hbit('C');
+ clearTimeout(xhr_rd_watchdog);
+ xhr_rd_watchdog = null;
+ }
return;
- createCookie("sess",sess,1,xhr_rd_cookiepath);
+ }
+ createCookie("sess", sess, 24*365, xhr_rd_cookiepath);
+
+ // NOTE: *ctx = "" to prevent konqueror stream commands duplication.
+ xhr_rd_oldctx = "";
+ xhr_rd_newctx = "";
/* NOTE document.uniqueID exists only under IE */
- // alert("di qui3");
+ // if (g_is_spawn == 1)
+ // alert("di qui3: "+(g_is_spawn == 1 ? "&table_idx="+g_table_idx : ""));
xhr_rd.open('GET', 'index_rd.php?sess='+sess+"&stat="+stat+"&subst="+subst+"&step="+step+"&onlyone="+(document.uniqueID ? "TRUE" : "FALSE")+"&myfrom="+myfrom, true);
// try {
xhr_rd.onreadystatechange = function() { xhr_rd_cb(xhr_rd); }
xhr_rd.send(null);
+ //
+ // TODO: qui avvio del timer per riavviare xhr
+ //
+ xhr_rd_watchdog = setTimeout(xhr_rd_abort, 60000, xhr_rd);
xhr_rd_cur_n++;
xhr_rd_stopped = false;
// } catch (e) {}
@@ -79,17 +136,13 @@ function xhr_rd_poll(sess)
xhr_rd.abort();
}
*/
-
var zug = "XHR_RD_POLL sess = "+sess+" stat = "+stat+" subst = "+subst+" step = "+gst.st+" step_loc = "+gst.st_loc+" step_loc_new = "+gst.st_loc_new+" STOP: "+xhr_rd_stopped;
if (zug != $("sandbox").innerHTML)
$("sandbox").innerHTML = zug;
-
- /* heartbeat log */
- $("sandbox2").innerHTML += "_";
- if ($("sandbox2").innerHTML.length == 20)
- $("sandbox2").innerHTML = "_";
+ /* heartbit log */
+ hbit("_");
do {
again = 0;
@@ -104,41 +157,63 @@ function xhr_rd_poll(sess)
singlecomm = gst.comms.shift();
// alert("EXE"+gugu);
// $("xhrdeltalog").innerHTML = "EVALL: "+singlecomm.replace("<", "<", "g"); +"
";
+ hbit("+");
+
eval(singlecomm);
again = 1;
}
else {
xhrrestart = 1;
try {
- xhr_rd_newctx = xhr_rd.responseText;
+ if (xhr_rd == null)
+ throw "restart";
+ if (xhr_rd.responseText != null)
+ xhr_rd_newctx = xhr_rd.responseText;
}
catch (e) {
if (xhr_rd_stopped == true) {
xhr_rd_stopped = false;
// XX $("xhrstart").innerHTML += "XHRSTART: da catch
";
- xhr_rd_start(sess, stat, subst, gst.st);
+ if (xhr_rd_delay > 0) {
+ if (xhr_rd_delayed == null) {
+ // console.log("XXX DI QUI "+xhr_rd_delay);
+ xhr_rd_delayed = setTimeout(xhr_rd_start, xhr_rd_delay, sess, stat, subst, gst.st);
+ // console.log("XXX DI QUI post"+xhr_rd_delayed);
+ }
+ }
+ else {
+ // console.log("yyy DI QUI "+xhr_rd_delay);
+ xhr_rd_start(sess, stat, subst, gst.st);
+ }
}
-
+
// $("sandbox").innerHTML += "return 1
";
if (the_end != true) {
watchdog = 0;
setTimeout(xhr_rd_poll, tout, sess);
- $("sandbox2").innerHTML += "-";
- if ($("sandbox2").innerHTML.length == 20)
- $("sandbox2").innerHTML = "-";
+
+ // hbit(".");
+
}
- return;
- }
-
-
- // no new char from the last loop, break
- if (xhr_rd_old_n == xhr_rd_cur_n &&
- xhr_rd_newctx.length == xhr_rd_checkedlen) {
- watchdog++;
- break;
- }
- else {
+ else {
+ //x alert("the_end2");
+ if (typeof xhr_rd_watchdog != 'undefined' && xhr_rd_watchdog != null) {
+ clearTimeout(xhr_rd_watchdog);
+ xhr_rd_watchdog = null;
+ }
+ }
+ return;
+ }
+
+
+ // no new char from the last loop, break
+ if (xhr_rd_old_n == xhr_rd_cur_n &&
+ xhr_rd_newctx.length == xhr_rd_checkedlen) {
+ watchdog++;
+ break;
+ }
+ else {
watchdog = 0;
// $("sandbox").innerHTML += "BIG IF
";
var comm_match;
@@ -150,6 +225,8 @@ function xhr_rd_poll(sess)
var delta = 0;
var match_lines = /^_*$/;
+ hbit("/\\");
+
// check for the same command group
if (xhr_rd_old_n != xhr_rd_cur_n) {
xhr_rd_old_n = xhr_rd_cur_n;
@@ -206,16 +283,32 @@ function xhr_rd_poll(sess)
// $("sandbox").innerHTML += "LITTLE IF
";
// alert("di qui");
// XX $("xhrstart").innerHTML += "XHRSTART: da end poll
";
- xhr_rd_start(sess, stat, subst, gst.st);
- // $("sandbox").innerHTML += "return 2
";
+
+ if (xhr_rd_delay > 0) {
+ if (xhr_rd_delayed == null) {
+ // console.log("XXX DI QUO "+xhr_rd_delay);
+ xhr_rd_delayed = setTimeout(xhr_rd_start, xhr_rd_delay, sess, stat, subst, gst.st);
+ // console.log("XXX DI QUO post"+xhr_rd_delayed);
+ }
+ }
+ else {
+ // console.log("yyy DI QUO "+xhr_rd_delay);
+ xhr_rd_start(sess, stat, subst, gst.st);
+ }
+
}
-
- // $("sandbox").innerHTML += "return 3
";
+
if (the_end != true) {
setTimeout(xhr_rd_poll, tout, sess);
- $("sandbox2").innerHTML += "-";
- if ($("sandbox2").innerHTML.length == 20)
- $("sandbox2").innerHTML = "-";
+ }
+ else {
+ //x alert("the_end3");
+ if (typeof(xhr_rd_watchdog) != 'undefined') {
+ if (xhr_rd_watchdog != null) {
+ clearTimeout(xhr_rd_watchdog);
+ xhr_rd_watchdog = null;
+ }
+ }
}
return;
};