-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);
+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);
+ unsigned 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;
+ }
+ }