Skip to content
Browse files

[fix] oparpc: now inform client that the synchrone server call failed

  • Loading branch information...
1 parent 01fd9d1 commit 24b904f80cda0809c0ac8644940599d3fb5669ae Hugo Heuzard committed
Showing with 71 additions and 30 deletions.
  1. +5 −3 opa/opa_InsertRemote.ml
  2. +41 −19 opabsl/jsbsl/bslSession.js
  3. +25 −8 stdlib/core/rpc/core/oparpc.opa
View
8 opa/opa_InsertRemote.ml
@@ -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 =
View
60 opabsl/jsbsl/bslSession.js
@@ -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);
}
@@ -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);}
View
33 stdlib/core/rpc/core/oparpc.opa
@@ -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
@@ -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 =
@@ -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%%
@@ -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.
Something went wrong with that request. Please try again.