inline void handle_remote_spawn( actor<stackless>& self, aid_t aid, message msg, link_type type, boost::chrono::system_clock::time_point begin_tp, sid_t sid, seconds_t tmo, duration_t curr_tmo, spawn_handler_t const& hdr ) { boost::uint16_t err = 0; sid_t ret_sid = sid_nil; msg >> err >> ret_sid; do { if (err != 0 || (aid && sid == ret_sid)) { break; } if (tmo != infin) { duration_t pass_time = boost::chrono::system_clock::now() - begin_tp; curr_tmo -= pass_time; } begin_tp = boost::chrono::system_clock::now(); match mach(curr_tmo); mach.match_list_.push_back(detail::msg_spawn_ret); self.recv( boost::bind( &handle_remote_spawn, _1, _2, _3, type, begin_tp, sid, tmo, curr_tmo, hdr ), mach ); return; } while (false); detail::spawn_error error = (detail::spawn_error)err; if (error != detail::spawn_ok) { aid = aid_t(); } if (aid) { if (type == linked) { self.link(aid); } else if (type == monitored) { self.monitor(aid); } } hdr(self, aid); }
///------------------------------------------------------------------------------ void mailbox::push(request_t req, message const& msg) { scope scp(boost::bind(&recv_queue_t::pop_back, &recv_que_)); recv_t rcv(req); add_match_msg(rcv, aid_t(), msg); std::pair<wait_reply_list_t::iterator, bool> pr = wait_reply_list_.insert(std::make_pair(req.get_aid(), dummy_)); pr.first->second.push_back(req); scp.reset(); }
static void test_common() { try { context ctx; threaded_actor base = spawn(ctx); aid_t base_id = base.get_aid(); aid_t aid1 = spawn(base, boost::bind(&match_recver_ut::my_actor, _arg1, base_id), monitored); spawn(base, boost::bind(&match_recver_ut::my_actor, _arg1, aid_t()), monitored); message msg; pattern patt; patt.add_match("timeout"); patt.timeout_ = millisecs(1); aid_t sender = base.recv(msg, patt); GCE_VERIFY(sender == aid_nil); int i = -1; base->recv("catch", guard(aid1), i); GCE_VERIFY(i == 0); std::cout << "catch " << i << std::endl; base->match("catch").guard(aid1).recv(i); GCE_VERIFY(i == 1); std::cout << "catch " << i << std::endl; resp_t res = base->request(aid1, "resp", i); errcode_t ec; base->match(res).guard(ec).raw(msg).respond(i); GCE_VERIFY(ec); GCE_VERIFY(msg.get_type() == exit); base->match("not_catch").guard(aid1, ec).recv(i); GCE_VERIFY(ec); } catch (std::exception& ex) { std::cerr << ex.what() << std::endl; } }