+ xbt_ex_t e;
+ int finished = 0;
+ TRY {
+ finished = SIMIX_req_comm_test(comm->s_comm);
+ }
+ CATCH(e) {
+ switch (e.category) {
+
+ case host_error:
+ comm->status = MSG_HOST_FAILURE;
+ finished = 1;
+ break;
+
+ case network_error:
+ comm->status = MSG_TRANSFER_FAILURE;
+ finished = 1;
+ break;
+
+ case timeout_error:
+ comm->status = MSG_TIMEOUT;
+ finished = 1;
+ break;
+
+ default:
+ RETHROW;
+ }
+ xbt_ex_free(e);
+ }
+
+ return finished;
+}
+
+/** \ingroup msg_gos_functions
+ * \brief This function checks if a communication is finished.
+ * \param comms a vector of communications
+ * \return the position of the finished communication if any
+ * (but it may have failed, use MSG_comm_get_status() to know its status),
+ * or -1 if none is finished
+ */
+int MSG_comm_testany(xbt_dynar_t comms)
+{
+ xbt_ex_t e;
+ int finished_index = -1;
+
+ /* create the equivalent dynar with SIMIX objects */
+ xbt_dynar_t s_comms = xbt_dynar_new(sizeof(smx_action_t), NULL);
+ msg_comm_t comm;
+ unsigned int cursor;
+ xbt_dynar_foreach(comms, cursor, comm) {
+ xbt_dynar_push(s_comms, &comm->s_comm);
+ }
+
+ MSG_error_t status = MSG_OK;
+ TRY {
+ finished_index = SIMIX_req_comm_testany(s_comms);
+ }
+ CATCH(e) {
+ switch (e.category) {
+
+ case host_error:
+ finished_index = e.value;
+ status = MSG_HOST_FAILURE;
+ break;
+
+ case network_error:
+ finished_index = e.value;
+ status = MSG_TRANSFER_FAILURE;
+ break;
+
+ case timeout_error:
+ finished_index = e.value;
+ status = MSG_TIMEOUT;
+ break;
+
+ default:
+ RETHROW;
+ }
+ xbt_ex_free(e);
+ }
+ xbt_dynar_free(&s_comms);
+
+ if (finished_index != -1) {
+ comm = xbt_dynar_get_as(comms, finished_index, msg_comm_t);
+ /* the communication is finished */
+ comm->status = status;
+ }
+
+ return finished_index;