+
+void SIMIX_comm_finish(smx_action_t action)
+{
+ unsigned int destroy_count = 0;
+ smx_req_t req;
+
+ while ((req = xbt_fifo_shift(action->request_list))) {
+
+ /* If a waitany request 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 request's actions dynar and
+ return it as the result of the call */
+ if (req->call == REQ_COMM_WAITANY) {
+ SIMIX_waitany_req_remove_from_actions(req);
+ if (!MC_IS_ENABLED)
+ req->comm_waitany.result = xbt_dynar_search(req->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", 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:
+ TRY {
+ THROWF(timeout_error, 0, "Communication timeouted because of sender");
+ }
+ CATCH(req->issuer->running_ctx->exception) {
+ req->issuer->doexception = 1;
+ }
+ break;
+
+ case SIMIX_DST_TIMEOUT:
+ TRY {
+ THROWF(timeout_error, 0, "Communication timeouted because of receiver");
+ }
+ CATCH(req->issuer->running_ctx->exception) {
+ req->issuer->doexception = 1;
+ }
+ break;
+
+ case SIMIX_SRC_HOST_FAILURE:
+ TRY {
+ if (req->issuer == action->comm.src_proc)
+ THROWF(host_error, 0, "Host failed");
+ else
+ THROWF(network_error, 0, "Remote peer failed");
+ }
+ CATCH(req->issuer->running_ctx->exception) {
+ req->issuer->doexception = 1;
+ }
+ break;
+
+ case SIMIX_DST_HOST_FAILURE:
+ TRY {
+ if (req->issuer == action->comm.dst_proc)
+ THROWF(host_error, 0, "Host failed");
+ else
+ THROWF(network_error, 0, "Remote peer failed");
+ }
+ CATCH(req->issuer->running_ctx->exception) {
+ req->issuer->doexception = 1;
+ }
+ break;
+
+ case SIMIX_LINK_FAILURE:
+ TRY {
+ XBT_DEBUG("Link failure in action %p between '%s' and '%s': posting an exception to the issuer: %s (%p)",
+ action, action->comm.src_proc->smx_host->name, action->comm.dst_proc->smx_host->name,
+ req->issuer->name, req->issuer);
+ THROWF(network_error, 0, "Link failure");
+ }
+ CATCH(req->issuer->running_ctx->exception) {
+ req->issuer->doexception = 1;
+ }
+ break;
+
+ default:
+ THROW_IMPOSSIBLE;
+ }
+
+ /* if there is an exception during a waitany or a testany, indicate the position of the failed communication */
+ if (req->issuer->doexception) {
+ if (req->call == REQ_COMM_WAITANY) {
+ req->issuer->running_ctx->exception.value = xbt_dynar_search(req->comm_waitany.comms, &action);
+ }
+ else if (req->call == REQ_COMM_TESTANY) {
+ req->issuer->running_ctx->exception.value = xbt_dynar_search(req->comm_testany.comms, &action);
+ }
+ }
+
+ req->issuer->waiting_action = NULL;
+ SIMIX_request_answer(req);
+ destroy_count++;