+static int gras_msg_wait_or_filter(gras_msg_t msg, void *ctx) {
+ xbt_dynar_t dyn=(xbt_dynar_t)ctx;
+ int res = xbt_dynar_member(dyn,msg->type);
+ if (res)
+ VERB1("Got matching message (type=%s)",msg->type->name);
+ else
+ VERB0("Got message not matching our expectations");
+ return res;
+}
+/** \brief Waits for a message to come in over a given socket.
+ *
+ * @param timeout: How long should we wait for this message.
+ * @param msgt_want: a dynar containing all accepted message type
+ * @param[out] ctx: the context of received message (in case it's a RPC call we want to answer to)
+ * @param[out] msgt_got: indice in the dynar of the type of the received message
+ * @param[out] payload: where to write the payload of the incomming message
+ * @return the error code (or no_error).
+ *
+ * Every message of a type not in the accepted list received before the one
+ * waited will be queued and used by subsequent call to this function or
+ * gras_msg_handle().
+ *
+ * If you are interested in the context, pass the address of a s_gras_msg_cb_ctx_t variable.
+ */
+void gras_msg_wait_or(double timeout,
+ xbt_dynar_t msgt_want,
+ gras_msg_cb_ctx_t *ctx,
+ int *msgt_got,
+ void *payload) {
+ s_gras_msg_t msg;
+
+ VERB1("Wait %f seconds for several message types",timeout);
+ gras_msg_wait_ext(timeout,
+ NULL, NULL,
+ &gras_msg_wait_or_filter, (void*)msgt_want,
+ &msg);
+
+ if (msg.type->ctn_type) {
+ xbt_assert1(payload,
+ "Message type '%s' convey a payload you must accept",
+ msg.type->name);
+ } /* don't check the other side since some of the types may have a payload */
+
+ if (payload && msg.type->ctn_type) {
+ memcpy(payload,msg.payl,msg.payl_size);
+ free(msg.payl);
+ }
+
+ if (ctx)
+ *ctx=gras_msg_cb_ctx_new(msg.expe, msg.type, msg.ID,
+ (msg.kind == e_gras_msg_kind_rpccall), 60);
+
+ if (msgt_got)
+ *msgt_got = xbt_dynar_search(msgt_want,msg.type);
+}
+