+ bool restart;
+ msg = NULL;
+
+ do {
+ if (ctrl_comm && comm_test_n_destroy(ctrl_comm)) {
+ msg = (message* )MSG_task_get_data(ctrl_task);
+ from = MSG_task_get_source(ctrl_task);
+ MSG_task_destroy(ctrl_task);
+ ctrl_task = NULL;
+ ctrl_comm =
+ (!ctrl_close_is_last || msg->get_type() != message::CTRL_CLOSE)
+ ? MSG_task_irecv(&ctrl_task, get_ctrl_mbox())
+ : NULL;
+
+ } else if (data_comm && comm_test_n_destroy(data_comm)) {
+ msg = (message* )MSG_task_get_data(data_task);
+ from = MSG_task_get_source(data_task);
+ MSG_task_destroy(data_task);
+ data_task = NULL;
+ data_comm =
+ (!data_close_is_last || msg->get_type() != message::DATA_CLOSE)
+ ? MSG_task_irecv(&data_task, get_data_mbox())
+ : NULL;
+ }
+
+ restart = wait && !msg && (ctrl_comm || data_comm);
+ if (restart) {
+ xbt_dynar_t comms = xbt_dynar_new(sizeof(msg_comm_t), NULL);
+ if (ctrl_comm)
+ xbt_dynar_push(comms, &ctrl_comm);
+ if (data_comm)
+ xbt_dynar_push(comms, &data_comm);
+ MSG_comm_waitany(comms);
+ xbt_dynar_free(&comms);
+ }
+ } while (restart);
+
+ if (msg)
+ DEBUG2("received %s from %s",
+ msg->to_string().c_str(), MSG_host_get_name(from));
+
+ return msg != NULL;