Skip to content

Commit

Permalink
[fix] oparpc: now inform client that the synchrone server call failed
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Heuzard committed Sep 21, 2011
1 parent 01fd9d1 commit 24b904f
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 30 deletions.
8 changes: 5 additions & 3 deletions opa/opa_InsertRemote.ml
Expand Up @@ -654,9 +654,11 @@ let generate_skeleton explicit_map ~annotmap ~stdlib_gamma ~gamma ~side expr =
in

(* Call to serialize function *)
let annotmap, call_ser =
let annotmap, ser = OpaSerialize.serialize ~side annotmap stdlib_gamma in
full_apply gamma annotmap ser [expr_tres] [fun_call] in
let annotmap, call_ser = match side with
| `server -> TypedExpr.opa_tuple_2 (annotmap,gamma) (expr_tres,fun_call)
| `client ->
let annotmap, ser = OpaSerialize.serialize ~side annotmap stdlib_gamma in
full_apply gamma annotmap ser [expr_tres] [fun_call] in

(* Call to extract_values *)
let annotmap, call_ext_val =
Expand Down
60 changes: 41 additions & 19 deletions opabsl/jsbsl/bslSession.js
Expand Up @@ -120,21 +120,43 @@ var LowLevelPingLoop = {};
return random();
}

var linked_with_server = true;

function break_ping_loop() {
linked_with_server = false;
jlog("Error: the connexion with the server seems to be lost. Please reload");
throw("Error: the connexion with the server seems to be lost. Please reload");
}

function internal_ajax(settings){
settings.url = internal_url + settings.url;
if(to_register.length != 0){
var body = settings.data;
if (body == undefined) body="";
var data = {
to_register:to_register,
uri:settings.url,
body:body
};
settings.data = JSON.stringify(data);
settings.url = internal_url + "/chan/register";
to_register = new Array();
if(linked_with_server){
settings.url = internal_url + settings.url;
if(to_register.length != 0){
var body = settings.data;
if (body == undefined) body="";
var data = {
to_register:to_register,
uri:settings.url,
body:body
};
settings.data = JSON.stringify(data);
settings.url = internal_url + "/chan/register";
to_register = new Array();
var success
if(settings.success){
success = settings.success
settings.success = function () {}
} else {
success = function () {}
}
settings.statusCode = { 205: break_ping_loop,
200: success};
}
return jQuery.ajax(settings);
}
else {
break_ping_loop();
}
return jQuery.ajax(settings);
}


Expand Down Expand Up @@ -681,12 +703,12 @@ var LowLevelPingLoop = {};
// jlog("Don't launch ping loop :"+ nb +" vs "+cpt);
} else {
internal_ajax({
type : 'POST',
url : "/ping",
data : JSON.stringify(cpt),
success : function(r){success_ping_response(r, nb)},
error : error_ping_response
});
type : 'POST',
url : "/ping",
data : JSON.stringify(cpt),
success : function(r){success_ping_response(r, nb)},
error : error_ping_response
});
}
};
if(force==true){f();}else{setTimeout(f, 0);}
Expand Down
33 changes: 25 additions & 8 deletions stdlib/core/rpc/core/oparpc.opa
Expand Up @@ -230,9 +230,15 @@ type OpaRPC.interface = {{
send_to_server(fun_name, request, ty) =
mr = %%BslSession.PingRegister.pang_request%% : string, string -> string
url = "/rpc_call/" ^ fun_name
OpaSerialize.unserialize(mr(url, OpaRPC.serialize(request)), ty)
? /* TODOK1 - One day we can manage request error??*/
error("OPARPC : Request on {url} has failed")
ty_success = [{label="success" ~ty}]
ty_failure = [{label="failure" ty={TyRecord_row = []}}]
ty = {TySum_col=[ty_failure,ty_success]}
match OpaSerialize.unserialize(mr(url, OpaRPC.serialize(request)), ty) with
| {some={~success}} -> success
| {some={failure}} -> error("OPARPC : Request on {url} has failed")
| {none} ->
/* TODOK1 - One day we can manage request error??*/
error("OPARPC : Request on {url} has failed")
async_send_to_server(fun_name, request, _) =
mr = %% BslSession.PingRegister.ping_async_call %%: string, string -> void
Expand Down Expand Up @@ -365,7 +371,7 @@ type OpaRPC.timeout = {
error("Invalid distant call to function ({fun_name}) at {__POSITION__}: there seems to be no client connected")
end
)
OpaSerialize.unserialize(serialized_return, ty) ? error("OPARPC : Request on client url {fun_name} has failed")
OpaSerialize.unserialize(serialized_return, ty) ? error("OPARPC : Request on client url {fun_name} has failed.")
@private dummy_cont = Continuation.make((_:string) -> @fail("Dummy cont should't be called"))
async_send_to_client(fun_name : string, request : OpaRPC.request, _) : 'a =
Expand All @@ -389,6 +395,12 @@ type OpaRPC.timeout = {
{volatile}, winfo.http_request.request, status,
"text/plain", msg)
)
reply_error(winfo, msg) =
winfo.cont(
WebCoreExport.default_make_response(
{volatile}, winfo.http_request.request, {internal_server_error},
"text/plain", msg)
)
register = %%BslRPC.Dispatcher.register%%
Expand All @@ -410,15 +422,20 @@ type OpaRPC.timeout = {
error("RPC error")
| {some = skeleton} ->
@catch(_ ->
ty = {TyRecord_row=[{label="failure" ty={TyRecord_row = []}}]}
serial = OpaSerialize.serialize_with_type(ty,{failure})
reply(winfo, serial, {success}),
match skeleton(get_requested_post_content(winfo.http_request.request)) with
| {none} ->
_ = reply(winfo, "Bad formatted rpc request", {forbidden})
do Log.error("OpaRPC", "Call to the rpc \"{name}\" failed")
error("RPC error")

| {some = result} ->
reply(winfo, result, {success})
end
| {some = (ty,result)} ->
ty = {TyRecord_row=[{label="success" ~ty}]}
serial = OpaSerialize.serialize_with_type(ty,{success=result})
reply(winfo, serial, {success})
end)
end
}}
}}

0 comments on commit 24b904f

Please sign in to comment.