#include "gras/Msg/msg_private.h"
xbt_set_t _gras_rpctype_set = NULL;
+xbt_dynar_t _gras_rpc_cancelled = NULL;
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras_msg_rpc,gras_msg,"RPC mecanism");
unsigned long int ID= *(unsigned long int*)ctx;
int res = msg->ID == ID &&
(msg->kind == e_gras_msg_kind_rpcanswer || msg->kind == e_gras_msg_kind_rpcerror);
+ int cursor;
+ gras_msg_cb_ctx_t rpc_ctx;
+
DEBUG5("Filter a message of ID %lu, type '%s' and kind '%s'. Waiting for ID=%lu. %s",
msg->ID,msg->type->name,e_gras_msg_kind_names[msg->kind],ID,
res?"take it": "reject");
+
+ if (res && !_gras_rpc_cancelled)
+ return res;
+
+ /* Check whether it is an old answer to a message we already canceled */
+ xbt_dynar_foreach(_gras_rpc_cancelled,cursor,rpc_ctx) {
+ if (msg->ID == rpc_ctx->ID && msg->kind==e_gras_msg_kind_rpcanswer) {
+ VERB1("Got an answer to the already canceled (timeouted?) RPC %ld. Ignore it (leaking the payload!).",msg->ID);
+ xbt_dynar_cursor_rm (_gras_rpc_cancelled, &cursor);
+ return 1;
+ }
+ }
+
return res;
}
void *request) {
gras_msg_cb_ctx_t ctx = xbt_new0(s_gras_msg_cb_ctx_t,1);
+ if (msgtype->ctn_type) {
+ xbt_assert1(request,
+ "RPC type '%s' convey a payload you must provide",
+ msgtype->name);
+ } else {
+ xbt_assert1(!request,
+ "No payload was declared for RPC type '%s'",
+ msgtype->name);
+ }
+
ctx->ID = last_msg_ID++;
ctx->expeditor = server;
ctx->msgtype=msgtype;
ctx->timeout=timeOut;
- VERB5("Send to %s:%d a RPC of type '%s' (ID=%lu) (exception%s caught)",
+ VERB4("Send to %s:%d a RPC of type '%s' (ID=%lu)",
gras_socket_peer_name(server),
gras_socket_peer_port(server),
- msgtype->name,ctx->ID,
- (__xbt_ex_ctx()->ctx_caught?"":" not"));
+ msgtype->name,ctx->ID);
gras_msg_send_ext(server, e_gras_msg_kind_rpccall, ctx->ID, msgtype, request);
/** @brief Wait teh answer of a RPC call previously launched asynchronously */
void gras_msg_rpc_async_wait(gras_msg_cb_ctx_t ctx,
void *answer) {
+ xbt_ex_t e;
s_gras_msg_t received;
- gras_msg_wait_ext(ctx->timeout,
- ctx->msgtype, NULL, msgfilter_rpcID, &ctx->ID,
- &received);
+ if (ctx->msgtype->answer_type) {
+ xbt_assert1(answer,
+ "Answers to RPC '%s' convey a payload you must accept",
+ ctx->msgtype->name);
+ } else {
+ xbt_assert1(!answer,
+ "No payload was declared for answers to RPC '%s'",
+ ctx->msgtype->name);
+ }
+
+ TRY {
+ /* The filter returns 1 when we eat an old RPC answer to something canceled */
+ do {
+ gras_msg_wait_ext(ctx->timeout,
+ ctx->msgtype, NULL, msgfilter_rpcID, &ctx->ID,
+ &received);
+ } while (received.ID != ctx->ID);
+
+ } CATCH(e) {
+ if (!_gras_rpc_cancelled)
+ _gras_rpc_cancelled = xbt_dynar_new(sizeof(ctx),NULL);
+ xbt_dynar_push(_gras_rpc_cancelled,&ctx);
+ INFO5("canceled RPC %ld pushed onto the stack (%s from %s:%d) Reason: %s",
+ ctx->ID,ctx->msgtype->name,
+ gras_socket_peer_name(ctx->expeditor),gras_socket_peer_port(ctx->expeditor),
+ e.msg);
+ RETHROW;
+ }
+
free(ctx);
if (received.kind == e_gras_msg_kind_rpcerror) {
xbt_ex_t e;
*/
void gras_msg_rpcreturn(double timeOut,gras_msg_cb_ctx_t ctx,void *answer) {
+ DEBUG5("Return to RPC '%s' from %s:%d (tOut=%f, payl=%p)",
+ ctx->msgtype->name,
+ gras_socket_peer_name(ctx->expeditor),gras_socket_peer_port(ctx->expeditor),
+ timeOut,answer);
gras_msg_send_ext(ctx->expeditor, e_gras_msg_kind_rpcanswer,
ctx->ID, ctx->msgtype, answer);
}