- // It's not started yet. Do it in one simcall
- if (p_srcBuff != NULL) {
- simcall_comm_send(p_sender->getInferior(), p_mailbox->getInferior(), p_remains, p_rate,
- p_srcBuff, p_srcBuffSize,
- p_matchFunction, p_copyDataFunction,
- p_userData, timeout);
- } else { // Receiver
- simcall_comm_recv(p_receiver->getInferior(), p_mailbox->getInferior(), p_dstBuff, &p_dstBuffSize,
- p_matchFunction, p_copyDataFunction,
- p_userData, timeout, p_rate);
+/** @brief Block the calling actor until the communication is finished, or until timeout
+ *
+ * On timeout, an exception is thrown.
+ *
+ * @param timeout the amount of seconds to wait for the comm termination.
+ * Negative values denote infinite wait times. 0 as a timeout returns immediately. */
+Activity* Comm::wait(double timeout)
+{
+ switch (state_) {
+ case State::finished:
+ return this;
+
+ case State::inited: // It's not started yet. Do it in one simcall
+ if (src_buff_ != nullptr) {
+ simcall_comm_send(sender_, mailbox_->get_impl(), remains_, rate_, src_buff_, src_buff_size_, match_fun_,
+ copy_data_function_, user_data_, timeout);
+ } else { // Receiver
+ simcall_comm_recv(receiver_, mailbox_->get_impl(), dst_buff_, &dst_buff_size_, match_fun_, copy_data_function_,
+ user_data_, timeout, rate_);
+ }
+ state_ = State::finished;
+ return this;
+
+ case State::started:
+ simcall_comm_wait(pimpl_, timeout);
+ state_ = State::finished;
+ return this;
+
+ default:
+ THROW_IMPOSSIBLE;