+ unsigned int destroy_count = 0;
+ smx_simcall_t simcall;
+
+ while ((simcall = xbt_fifo_shift(action->simcalls))) {
+
+ /* If a waitany simcall is waiting for this action to finish, then remove
+ it from the other actions in the waitany list. Afterwards, get the
+ position of the actual action in the waitany dynar and
+ return it as the result of the simcall */
+ if (simcall->call == SIMCALL_COMM_WAITANY) {
+ SIMIX_waitany_remove_simcall_from_actions(simcall);
+ if (!MC_IS_ENABLED)
+ simcall->comm_waitany.result = xbt_dynar_search(simcall->comm_waitany.comms, &action);
+ }
+
+ /* If the action is still in a rendez-vous point then remove from it */
+ if (action->comm.rdv)
+ SIMIX_rdv_remove(action->comm.rdv, action);
+
+ XBT_DEBUG("SIMIX_comm_finish: action state = %d", (int)action->state);
+
+ /* Check out for errors */
+ switch (action->state) {
+
+ case SIMIX_DONE:
+ XBT_DEBUG("Communication %p complete!", action);
+ SIMIX_comm_copy_data(action);
+ break;
+
+ case SIMIX_SRC_TIMEOUT:
+ SMX_EXCEPTION(simcall->issuer, timeout_error, 0,
+ "Communication timeouted because of sender");
+ break;
+
+ case SIMIX_DST_TIMEOUT:
+ SMX_EXCEPTION(simcall->issuer, timeout_error, 0,
+ "Communication timeouted because of receiver");
+ break;
+
+ case SIMIX_SRC_HOST_FAILURE:
+ if (simcall->issuer == action->comm.src_proc)
+ simcall->issuer->context->iwannadie = 1;
+// SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed");
+ else
+ SMX_EXCEPTION(simcall->issuer, network_error, 0, "Remote peer failed");
+ break;
+
+ case SIMIX_DST_HOST_FAILURE:
+ if (simcall->issuer == action->comm.dst_proc)
+ simcall->issuer->context->iwannadie = 1;
+// SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed");
+ else
+ SMX_EXCEPTION(simcall->issuer, network_error, 0, "Remote peer failed");
+ break;
+
+ case SIMIX_LINK_FAILURE:
+ XBT_DEBUG("Link failure in action %p between '%s' and '%s': posting an exception to the issuer: %s (%p) detached:%d",
+ action,
+ action->comm.src_proc ? action->comm.src_proc->smx_host->name : NULL,
+ action->comm.dst_proc ? action->comm.dst_proc->smx_host->name : NULL,
+ simcall->issuer->name, simcall->issuer, action->comm.detached);
+ if (action->comm.src_proc == simcall->issuer) {
+ XBT_DEBUG("I'm source");
+ } else if (action->comm.dst_proc == simcall->issuer) {
+ XBT_DEBUG("I'm dest");
+ } else {
+ XBT_DEBUG("I'm neither source nor dest");
+ }
+ SMX_EXCEPTION(simcall->issuer, network_error, 0, "Link failure");
+ break;
+
+ case SIMIX_CANCELED:
+ if (simcall->issuer == action->comm.dst_proc)
+ SMX_EXCEPTION(simcall->issuer, cancel_error, 0,
+ "Communication canceled by the sender");
+ else
+ SMX_EXCEPTION(simcall->issuer, cancel_error, 0,
+ "Communication canceled by the receiver");
+ break;
+
+ default:
+ xbt_die("Unexpected action state in SIMIX_comm_finish: %d", (int)action->state);
+ }
+
+ /* if there is an exception during a waitany or a testany, indicate the position of the failed communication */
+ if (simcall->issuer->doexception) {
+ if (simcall->call == SIMCALL_COMM_WAITANY) {
+ simcall->issuer->running_ctx->exception.value = xbt_dynar_search(simcall->comm_waitany.comms, &action);
+ }
+ else if (simcall->call == SIMCALL_COMM_TESTANY) {
+ simcall->issuer->running_ctx->exception.value = xbt_dynar_search(simcall->comm_testany.comms, &action);
+ }
+ }
+
+ if (surf_workstation_model->extension.
+ workstation.get_state(simcall->issuer->smx_host->host) != SURF_RESOURCE_ON) {
+ simcall->issuer->context->iwannadie = 1;
+ }
+
+ simcall->issuer->waiting_action = NULL;
+ xbt_fifo_remove(simcall->issuer->comms, action);
+ SIMIX_simcall_answer(simcall);
+ destroy_count++;
+ }
+
+ while (destroy_count-- > 0)
+ SIMIX_comm_destroy(action);