+
+/** @brief get the amount remaining from the communication */
+double simgrid::simix::Comm::remains()
+{
+ switch (state) {
+
+ case SIMIX_RUNNING:
+ return surf_comm->getRemains();
+ break;
+
+ case SIMIX_WAITING:
+ case SIMIX_READY:
+ return 0; /*FIXME: check what should be returned */
+ break;
+
+ default:
+ return 0; /*FIXME: is this correct? */
+ break;
+ }
+}
+
+/** @brief This is part of the cleanup process, probably an internal command */
+void simgrid::simix::Comm::cleanupSurf()
+{
+ if (surf_comm){
+ surf_comm->unref();
+ surf_comm = NULL;
+ }
+
+ if (src_timeout){
+ src_timeout->unref();
+ src_timeout = NULL;
+ }
+
+ if (dst_timeout){
+ dst_timeout->unref();
+ dst_timeout = NULL;
+ }
+}
+
+void simgrid::simix::Comm::post()
+{
+ /* Update synchro state */
+ if (src_timeout && src_timeout->getState() == simgrid::surf::Action::State::done)
+ state = SIMIX_SRC_TIMEOUT;
+ else if (dst_timeout && dst_timeout->getState() == simgrid::surf::Action::State::done)
+ state = SIMIX_DST_TIMEOUT;
+ else if (src_timeout && src_timeout->getState() == simgrid::surf::Action::State::failed)
+ state = SIMIX_SRC_HOST_FAILURE;
+ else if (dst_timeout && dst_timeout->getState() == simgrid::surf::Action::State::failed)
+ state = SIMIX_DST_HOST_FAILURE;
+ else if (surf_comm && surf_comm->getState() == simgrid::surf::Action::State::failed) {
+ state = SIMIX_LINK_FAILURE;
+ } else
+ state = SIMIX_DONE;
+
+ XBT_DEBUG("SIMIX_post_comm: comm %p, state %d, src_proc %p, dst_proc %p, detached: %d",
+ this, (int)state, src_proc, dst_proc, detached);
+
+ /* destroy the surf actions associated with the Simix communication */
+ cleanupSurf();
+
+ /* if there are simcalls associated with the synchro, then answer them */
+ if (xbt_fifo_size(simcalls))
+ SIMIX_comm_finish(this);
+}