+/** @Returns whether the (asynchronous) communication is done yet or not */
+XBT_INLINE int SIMIX_network_test(smx_comm_t comm)
+{
+ /*If running in model-checking mode then intercept the communication action*/
+#ifdef HAVE_MC
+ if (_surf_do_model_check)
+ MC_trans_intercept_test(comm);
+#endif
+
+ /* Copy data if the communication is done */
+ if(comm->sem && !SIMIX_sem_would_block(comm->sem)){
+ /* Copy network data */
+ SIMIX_network_copy_data(comm);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/** @brief wait for the completion of any communication of a set
+ *
+ * @Returns the rank in the dynar of communication which finished; destroy it after identifying which one it is
+ */
+unsigned int SIMIX_network_waitany(xbt_dynar_t comms)
+{
+ xbt_dynar_t sems = xbt_dynar_new(sizeof(smx_sem_t),NULL);
+ unsigned int cursor, found_comm=-1;
+ smx_comm_t comm,comm_finished=NULL;
+
+ /*If running in model-checking mode then intercept the communication action*/
+#ifdef HAVE_MC
+ if (_surf_do_model_check)
+ MC_trans_intercept_waitany(comms);
+#endif
+ xbt_dynar_foreach(comms,cursor,comm)
+ xbt_dynar_push(sems,&(comm->sem));
+
+ DEBUG1("Waiting for the completion of communication set %p", comms);
+
+ found_comm = SIMIX_sem_acquire_any(sems);
+ xbt_dynar_free_container(&sems);
+ xbt_assert0(found_comm!=-1,"Cannot find which communication finished");
+ xbt_dynar_get_cpy(comms,found_comm,&comm_finished);
+
+ DEBUG2("Communication %p of communication set %p finished", comm_finished, comms);
+
+ /* let the regular code deal with the communication end (errors checking and cleanup).
+ * A bit of useless work will be done, but that's good for source factorization */
+ SIMIX_sem_release_forever(comm_finished->sem);
+ SIMIX_communication_wait_for_completion(comm_finished, -1);
+ return found_comm;
+}