Permalink
Browse files

fixed bug in timed_sync_send

  • Loading branch information...
Neverlord committed Feb 5, 2013
1 parent f543c4a commit e1f51dc005bb949ba4903664740be99856aaca40
Showing with 25 additions and 18 deletions.
  1. +21 −15 cppa/detail/receive_policy.hpp
  2. +4 −3 src/event_based_actor.cpp
@@ -37,6 +37,7 @@
#include <type_traits>
#include "cppa/behavior.hpp"
+#include "cppa/to_string.hpp"
#include "cppa/message_id.hpp"
#include "cppa/exit_reason.hpp"
#include "cppa/partial_function.hpp"
@@ -133,8 +134,8 @@ class receive_policy {
template<class Client, class FunOrBehavior>
inline void receive_wo_timeout(Client *client, FunOrBehavior& fun) {
- if (invoke_from_cache(client, fun) == false) {
- while (invoke(client, client->receive_node(), fun) == false) { }
+ if (!invoke_from_cache(client, fun)) {
+ while (!invoke(client, client->receive_node(), fun)) { }
}
}
@@ -145,10 +146,10 @@ class receive_policy {
template<class Client>
void receive(Client* client, behavior& bhvr) {
- if (bhvr.timeout().valid() == false) {
+ if (!bhvr.timeout().valid()) {
receive_wo_timeout(client, bhvr);
}
- else if (invoke_from_cache(client, bhvr) == false) {
+ else if (!invoke_from_cache(client, bhvr)) {
if (bhvr.timeout().is_zero()) {
pointer e = nullptr;
while ((e = client->try_receive_node()) != nullptr) {
@@ -174,19 +175,24 @@ class receive_policy {
}
template<class Client>
- void receive(Client* client, behavior& bhvr, message_id_t awaited_response) {
- CPPA_REQUIRE(bhvr.timeout().valid());
- CPPA_REQUIRE(bhvr.timeout().is_zero() == false);
- if (invoke_from_cache(client, bhvr, awaited_response) == false) {
- auto timeout = client->init_timeout(bhvr.timeout());
- pointer e = nullptr;
- while ((e = client->try_receive_node(timeout)) != nullptr) {
- CPPA_REQUIRE(e->marked == false);
- if (invoke(client, e, bhvr, awaited_response)) {
- return; // done
+ void receive(Client* client, behavior& bhvr, message_id_t mid) {
+ CPPA_REQUIRE(mid.is_response());
+ if (!invoke_from_cache(client, bhvr, mid)) {
+ if (bhvr.timeout().valid()) {
+ CPPA_REQUIRE(bhvr.timeout().is_zero() == false);
+ auto timeout = client->init_timeout(bhvr.timeout());
+ pointer e = nullptr;
+ while ((e = client->try_receive_node(timeout)) != nullptr) {
+ CPPA_REQUIRE(e->marked == false);
+ if (invoke(client, e, bhvr, mid)) {
+ return; // done
+ }
}
+ handle_timeout(client, bhvr);
+ }
+ else {
+ while (!invoke(client, client->receive_node(), bhvr, mid)) { }
}
- handle_timeout(client, bhvr);
}
}
@@ -141,9 +141,10 @@ void event_based_actor::do_become(behavior&& bhvr, bool discard_old) {
}
void event_based_actor::become_waiting_for(behavior&& bhvr, message_id_t mf) {
- CPPA_REQUIRE(bhvr.timeout().valid());
- reset_timeout();
- request_timeout(bhvr.timeout());
+ if (bhvr.timeout().valid()) {
+ reset_timeout();
+ request_timeout(bhvr.timeout());
+ }
m_bhvr_stack.push_back(std::move(bhvr), mf);
}

0 comments on commit e1f51dc

Please sign in to comment.