Copyright Matus Chochlik. Distributed under the Boost Software License, Version 1.0. See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
#include <thread>
namespace msgbus {
class pong : public actor<2> {
public:
using base = actor<2>;
pong(
connection_setup& conn_setup,
: base(
this,
this->allow_subscriptions();
conn_setup.setup_connectors(
*this,
}
auto ping(const message_context&, stored_message& msg_in) -> bool {
if(++_sent % _lmod == 0) {
bus().log_info(
"sent ${count} pongs").arg(
EAGINE_ID(count), _sent);
}
_timeout.reset();
return true;
}
auto shutdown(const message_context&, stored_message&) -> bool {
_done = true;
bus().log_info(
"received shutdown message");
return true;
}
void update() {
if(!_sent && _ready_timeout) {
_ready_timeout.reset();
} else {
std::this_thread::yield();
}
}
auto is_done() const noexcept {
return _done || _timeout;
}
private:
std::size_t _lmod{1};
std::size_t _sent{0};
timeout _timeout{std::chrono::minutes(1)};
timeout _ready_timeout{std::chrono::seconds(1)};
bool _done{false};
};
}
auto main(main_ctx& ctx) -> int {
msgbus::router_address
address{ctx};
msgbus::connection_setup conn_setup(ctx);
msgbus::pong pong(ctx, conn_setup,
address);
while(!pong.is_done()) {
pong.process_all();
pong.update();
}
return 0;
}
}
const main_ctx_object_parent_info & main_ctx_parent
Alias for main_ctx_object_parent_info parameter type.
Definition: main_ctx_fwd.hpp:24
basic_string_span< const char > string_view
Alias for const string views.
Definition: string_span.hpp:116
#define EAGINE_ID(NAME)
Macro for constructing instances of eagine::identifier.
Definition: identifier.hpp:353
#define EAGINE_MSG_MAP(CLASS_ID, METHOD_ID, CLASS, METHOD)
Constructs an instance of static message handler map.
Definition: handler_map.hpp:72
Common code is placed in this namespace.
Definition: eagine.hpp:21
#define EAGINE_MSG_ID(API, NAME)
Macro for instantiating objects of static_message_id.
Definition: message_id.hpp:148
@ local_interprocess
Inter-process connection for local communication.
auto bus() noexcept -> endpoint &
Returns a reference to the associated endpoint.
Definition: actor.hpp:45
@ remote_interprocess
Inter-process connection for remote communucation.
basic_address< false > address
Type alias for non-const memory address values.
Definition: address.hpp:203
static constexpr auto running_on_valgrind() noexcept -> tribool
Indicates if the current process runs on top of valgrind.
Definition: valgrind.hpp:30