- SIMIX_unregister_action_to_condition(comm->act, comm->cond);
-
- /* Check for errors */
- if (SIMIX_host_get_state(comm->dst_host) == 0){
- THROW1(host_error, 0, "Destination host %s failed", comm->dst_host->name);
- } else if (SIMIX_host_get_state(comm->src_host) == 0){
- THROW1(host_error, 0, "Source host %s failed", comm->src_host->name);
- } else if (SIMIX_action_get_state(comm->act) == SURF_ACTION_FAILED){
- THROW0(network_error, 0, "Link failure");
+ /* Check for timeouts */
+ if ((src_timeout = ((comm->src_timeout) && (SIMIX_action_get_state(comm->src_timeout) == SURF_ACTION_DONE))) ||
+ (dst_timeout = ((comm->dst_timeout) && (SIMIX_action_get_state(comm->dst_timeout) == SURF_ACTION_DONE))) ) {
+ /* Somebody did a timeout! */
+ if (src_timeout) DEBUG1("Communication timeout from the src! %p", comm);
+ if (dst_timeout) DEBUG1("Communication timeout from the dst! %p", comm);
+
+ if(comm->act && SIMIX_action_get_state(comm->act) == SURF_ACTION_RUNNING)
+ SIMIX_communication_cancel(comm);
+ else if (comm->rdv)
+ SIMIX_rdv_remove(comm->rdv, comm);
+
+ /* Make sure that everyone sleeping on that semaphore is awake, and that nobody will ever block on it */
+ SIMIX_sem_release_forever(comm->sem);
+ SIMIX_communication_destroy(comm);
+
+ THROW1(timeout_error, 0, "Communication timeouted because of %s",src_timeout?"the source":"the destination");
+ }
+
+ DEBUG1("Communication %p complete!", comm);
+ SIMIX_communication_cleanup(comm);
+}
+
+/**
+ * \brief Cancels a communication
+ * \brief comm The communication to cancel
+ */
+XBT_INLINE void SIMIX_communication_cancel(smx_comm_t comm)
+{
+ if (comm->act)
+ SIMIX_action_cancel(comm->act);
+}
+
+/**
+ * \brief get the amount remaining from the communication
+ * \param comm The communication
+ */
+XBT_INLINE double SIMIX_communication_get_remains(smx_comm_t comm)
+{
+ DEBUG1("calling SIMIX_action_get_remains(%p)", comm->act);
+ return SIMIX_action_get_remains(comm->act);
+}
+
+/**
+ * \brief verify if communication is latency bounded
+ * \param comm The communication
+ */
+XBT_INLINE int SIMIX_communication_is_latency_bounded(smx_comm_t comm)
+{
+ //try to find comm on the list of finished flows
+ uintptr_t key = 0;
+ uintptr_t data = 0;
+ xbt_dict_cursor_t cursor;
+ xbt_dict_foreach(latency_limited_dict,cursor,key,data) {
+ DEBUG2("comparing key=%p with comm=%p", (void*)key, (void*)comm);
+ if((void*)comm == (void*)key){
+ DEBUG2("key %p found, return value latency limited value %d", (void*)key, (int)data);
+ return (int)data;
+ }