X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/e4ad10b76792651791deb2fcdb1540c490ef149e..0189615fd0542854c3395490e9c3b635b4b5bba2:/src/gras/Msg/rpc.c diff --git a/src/gras/Msg/rpc.c b/src/gras/Msg/rpc.c index 987db03b9c..8f87b3c35e 100644 --- a/src/gras/Msg/rpc.c +++ b/src/gras/Msg/rpc.c @@ -10,6 +10,7 @@ #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"); @@ -67,20 +68,48 @@ static int msgfilter_rpcID(gras_msg_t msg, void* ctx) { 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; } +/* Mallocator cruft */ +xbt_mallocator_t gras_msg_ctx_mallocator = NULL; +void* gras_msg_ctx_mallocator_new_f(void) { + return xbt_new0(s_gras_msg_cb_ctx_t,1); +} +void gras_msg_ctx_mallocator_free_f(void* ctx) { + xbt_free(ctx); +} +void gras_msg_ctx_mallocator_reset_f(void* ctx) { + memset(ctx, sizeof(s_gras_msg_cb_ctx_t),0); +} + /** @brief Launch a RPC call, but do not block for the answer */ gras_msg_cb_ctx_t gras_msg_rpc_async_call(gras_socket_t server, double timeOut, gras_msgtype_t msgtype, void *request) { - gras_msg_cb_ctx_t ctx = xbt_new0(s_gras_msg_cb_ctx_t,1); + gras_msg_cb_ctx_t ctx = xbt_mallocator_get(gras_msg_ctx_mallocator); if (msgtype->ctn_type) { xbt_assert1(request, @@ -110,6 +139,7 @@ gras_msg_rpc_async_call(gras_socket_t server, /** @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; if (ctx->msgtype->answer_type) { @@ -122,10 +152,26 @@ void gras_msg_rpc_async_wait(gras_msg_cb_ctx_t ctx, ctx->msgtype->name); } - gras_msg_wait_ext(ctx->timeout, - ctx->msgtype, NULL, msgfilter_rpcID, &ctx->ID, - &received); - free(ctx); + 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; + } + + xbt_mallocator_release(gras_msg_ctx_mallocator, ctx); if (received.kind == e_gras_msg_kind_rpcerror) { xbt_ex_t e; memcpy(&e,received.payl,received.payl_size); @@ -160,7 +206,7 @@ void gras_msg_rpccall(gras_socket_t server, gras_msg_cb_ctx_t ctx; - ctx= gras_msg_rpc_async_call(server, timeout,msgtype,request); + ctx = gras_msg_rpc_async_call(server, timeout,msgtype,request); gras_msg_rpc_async_wait(ctx, answer); } @@ -172,6 +218,9 @@ void gras_msg_rpccall(gras_socket_t server, */ void gras_msg_rpcreturn(double timeOut,gras_msg_cb_ctx_t ctx,void *answer) { + xbt_assert0(ctx->answer_due, + "RPC return not allowed here. Either not a RPC message or already returned a result"); + ctx->answer_due = 0; 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),