Skip to content

Commit

Permalink
[feature] runtime, client, ping: Added max attemps limit to pang request
Browse files Browse the repository at this point in the history
  • Loading branch information
BourgerieQuentin committed May 24, 2012
1 parent a4f0864 commit 698c35e
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions opabsl/jsbsl/bslSession.js
Expand Up @@ -93,6 +93,8 @@ var LowLevelPingLoop = {};


var unserialize_uu = function(_){error("Unregistered unserialization function")} var unserialize_uu = function(_){error("Unregistered unserialization function")}


var max_pang_attempt = 3;

/* DEBUG FUNCTIONS*/ /* DEBUG FUNCTIONS*/
#<Ifstatic:PING_DEBUG> #<Ifstatic:PING_DEBUG>
function ping_debug (msg) { function ping_debug (msg) {
Expand Down Expand Up @@ -590,7 +592,10 @@ var LowLevelPingLoop = {};


} }



function log_error(){
if(window.console && window.console.error) window.console.error.apply(null, arguments);
else jlog.apply(null, arguments);
}
/* ************************************************** */ /* ************************************************** */
/* RPC support (server -> client) ******************* */ /* RPC support (server -> client) ******************* */
/** Contains skeletons. */ /** Contains skeletons. */
Expand All @@ -603,7 +608,7 @@ var LowLevelPingLoop = {};
// hook for try catch there, and return a special case, maybe e.g. rpc_return_exc // hook for try catch there, and return a special case, maybe e.g. rpc_return_exc
var data = funct(argument); var data = funct(argument);
if ('none' in data) { if ('none' in data) {
if(window.console && window.console.error) window.console.error("RPC comet call ", id, " failed, no data in ", argument); log_error("RPC comet call ", id, " failed, no data in ", argument);
} else if (id != null) { } else if (id != null) {
internal_ajax({ internal_ajax({
type : 'POST', type : 'POST',
Expand Down Expand Up @@ -740,6 +745,7 @@ var LowLevelPingLoop = {};
uri : url, uri : url,
body : is_json ? JSON.stringify(req) : req body : is_json ? JSON.stringify(req) : req
}; };
var attempt = 0;
while(panged[id] === null){ while(panged[id] === null){
response = response =
internal_ajax({ internal_ajax({
Expand All @@ -749,7 +755,21 @@ var LowLevelPingLoop = {};
data : JSON.stringify(request) data : JSON.stringify(request)
}); });
result = success_ping_response(response.responseText, -1); result = success_ping_response(response.responseText, -1);
if (result != undefined) panged[result.id]=result.body; if (result != undefined) {
if(panged[result.id] === undefined) {
log_error("Receive the pang("+result.id+") result too late", result);
} else {
panged[result.id]=result.body;
}
} else {
if(attempt >= max_pang_attempt) {
delete(panged[id]);
panged.waiting_pang--;
if(panged.waiting_pang == 0) internal_loop(false);
throw new Error("Maximum pang attempt reached");
}
attempt++;
}
request = ++cpt; request = ++cpt;
} }
result = panged[id]; result = panged[id];
Expand Down Expand Up @@ -899,6 +919,10 @@ var LowLevelPingLoop = {};
*/ */
LowLevelPingLoop.ajax = internal_ajax; LowLevelPingLoop.ajax = internal_ajax;


LowLevelPingLoop.set_max_pang_attempt = function(i){
max_pang_attempt = i;
}

/** /**
* Make an internal synchronous request using the pang system. Can * Make an internal synchronous request using the pang system. Can
* froze the client GUI. But the client can always interact with * froze the client GUI. But the client can always interact with
Expand Down Expand Up @@ -1106,6 +1130,13 @@ var LowLevelPingLoop = {};
LowLevelPingLoop.async_call(url, request); LowLevelPingLoop.async_call(url, request);
} }
##register set_max_pang_attempt: int -> void
##args(i)
{
LowLevelPingLoop.set_max_pang_attempt(i);
return js_void;
}
##endmodule ##endmodule
/* Hack for non cps client ****************************** */ /* Hack for non cps client ****************************** */
Expand Down

0 comments on commit 698c35e

Please sign in to comment.