Skip to content

Added defer support. #908

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion include/mqtt/null_strand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ struct null_strand {
}
template <typename Func, typename Allocator>
void dispatch(Func&& f, Allocator) const {
std::forward<Func>(f)();
as::dispatch(
ioc_,
[f = std::forward<Func>(f)] () mutable {
std::move(f)();
}
);
}
void on_work_started() const noexcept {}
void on_work_finished() const noexcept {}
Expand Down
7 changes: 7 additions & 0 deletions include/mqtt/tcp_endpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ class tcp_endpoint : public socket {
);
}

MQTT_ALWAYS_INLINE void defer(std::function<void()> handler) override final {
as::defer(
strand_,
force_move(handler)
);
}

MQTT_ALWAYS_INLINE as::ip::tcp::socket::lowest_layer_type& lowest_layer() override final {
return tcp_.lowest_layer();
}
Expand Down
1 change: 1 addition & 0 deletions include/mqtt/type_erased_socket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class socket {
virtual std::size_t write(std::vector<as::const_buffer>, boost::system::error_code&) = 0;
virtual void post(std::function<void()>) = 0;
virtual void dispatch(std::function<void()>) = 0;
virtual void defer(std::function<void()>) = 0;
virtual as::ip::tcp::socket::lowest_layer_type& lowest_layer() = 0;
virtual any native_handle() = 0;
virtual void clean_shutdown_and_close(boost::system::error_code&) = 0;
Expand Down
7 changes: 7 additions & 0 deletions include/mqtt/ws_endpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ class ws_endpoint : public socket {
);
}

MQTT_ALWAYS_INLINE void defer(std::function<void()> handler) override final {
as::defer(
strand_,
force_move(handler)
);
}

#if BOOST_VERSION >= 107000

MQTT_ALWAYS_INLINE as::ip::tcp::socket::lowest_layer_type& lowest_layer() override final {
Expand Down