+ xbt_assert(std::isfinite(timeout), "timeout is not finite!");
+ xbt_assert(mbox, "No rendez-vous point defined for recv");
+
+ if (MC_is_active() || MC_record_replay_is_active()) {
+ /* the model-checker wants two separate simcalls, and wants comm to be nullptr during the simcall */
+ simgrid::kernel::activity::ActivityImplPtr comm = nullptr;
+
+ simgrid::kernel::actor::CommIrecvSimcall observer{receiver,
+ mbox->get_impl(),
+ static_cast<unsigned char*>(dst_buff),
+ dst_buff_size,
+ match_fun,
+ copy_data_fun,
+ data,
+ rate};
+ comm = simgrid::kernel::actor::simcall_answered(
+ [&observer] { return simgrid::kernel::activity::CommImpl::irecv(&observer); }, &observer);
+
+ if (simgrid::kernel::actor::ActivityWaitSimcall wait_observer{receiver, comm.get(), timeout};
+ simgrid::kernel::actor::simcall_blocking(
+ [&wait_observer] {
+ wait_observer.get_activity()->wait_for(wait_observer.get_issuer(), wait_observer.get_timeout());
+ },
+ &wait_observer)) {
+ throw simgrid::TimeoutException(XBT_THROW_POINT, "Timeouted");
+ }
+ comm = nullptr;
+ } else {
+ simgrid::kernel::actor::CommIrecvSimcall observer(receiver, mbox->get_impl(), static_cast<unsigned char*>(dst_buff),
+ dst_buff_size, match_fun, copy_data_fun, data, rate);
+ simgrid::kernel::actor::simcall_blocking([&observer, timeout] {
+ simgrid::kernel::activity::ActivityImplPtr comm = simgrid::kernel::activity::CommImpl::irecv(&observer);
+ comm->wait_for(observer.get_issuer(), timeout);
+ });
+ }
+}
+
+CommPtr Comm::sendto_init()
+{
+ CommPtr res(new Comm());
+ res->pimpl_ = kernel::activity::CommImplPtr(new kernel::activity::CommImpl());
+ boost::static_pointer_cast<kernel::activity::CommImpl>(res->pimpl_)->detach();
+ res->sender_ = kernel::actor::ActorImpl::self();
+ return res;
+}
+
+CommPtr Comm::sendto_init(Host* from, Host* to)
+{
+ auto res = Comm::sendto_init()->set_source(from)->set_destination(to);
+ res->set_state(State::STARTING);
+ return res;
+}
+
+CommPtr Comm::sendto_async(Host* from, Host* to, uint64_t simulated_size_in_bytes)
+{
+ return Comm::sendto_init()->set_payload_size(simulated_size_in_bytes)->set_source(from)->set_destination(to);
+}
+
+void Comm::sendto(Host* from, Host* to, uint64_t simulated_size_in_bytes)
+{
+ sendto_async(from, to, simulated_size_in_bytes)->wait();
+}
+
+CommPtr Comm::set_source(Host* from)
+{
+ xbt_assert(state_ == State::INITED || state_ == State::STARTING,
+ "Cannot change the source of a Comm once it's started (state: %s)", to_c_str(state_));
+ boost::static_pointer_cast<kernel::activity::CommImpl>(pimpl_)->set_source(from);
+ // Setting 'source' may allow to start the activity, let's try
+ if (state_ == State::STARTING && remains_ <= 0)
+ XBT_DEBUG("This communication has a payload size of 0 byte. It cannot start yet");
+ else
+ start();
+
+ return this;
+}
+Host* Comm::get_source() const
+{
+ return pimpl_ ? boost::static_pointer_cast<kernel::activity::CommImpl>(pimpl_)->get_source() : nullptr;
+}
+
+CommPtr Comm::set_destination(Host* to)
+{
+ xbt_assert(state_ == State::INITED || state_ == State::STARTING,
+ "Cannot change the destination of a Comm once it's started (state: %s)", to_c_str(state_));
+ boost::static_pointer_cast<kernel::activity::CommImpl>(pimpl_)->set_destination(to);
+ // Setting 'destination' may allow to start the activity, let's try
+ if (state_ == State::STARTING && remains_ <= 0)
+ XBT_DEBUG("This communication has a payload size of 0 byte. It cannot start yet");
+ else
+ start();
+
+ return this;
+}
+
+Host* Comm::get_destination() const
+{
+ return pimpl_ ? boost::static_pointer_cast<kernel::activity::CommImpl>(pimpl_)->get_destination() : nullptr;