Skip to content
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

Client sample out of main scope #975

Open
codesian opened this issue May 3, 2023 · 1 comment
Open

Client sample out of main scope #975

codesian opened this issue May 3, 2023 · 1 comment

Comments

@codesian
Copy link

codesian commented May 3, 2023

Hi, a begginer here.

There is an example about client use out of main scope? How to store on a class member, something more generic than shot and close on main?

Thanks!

@redboltz
Copy link
Owner

redboltz commented May 3, 2023

See bench.cpp

mqtt_cpp/example/bench.cpp

Lines 1054 to 1070 in 2776579

using client_t = decltype(
MQTT_NS::make_async_client(
std::declval<as::io_context&>(),
host,
port,
version
)
);
struct client_info : client_info_base {
client_info(client_t c, std::size_t index, std::size_t payload_size, std::size_t times, std::size_t idle_count)
:client_info_base(index, payload_size, times, idle_count),
c{MQTT_NS::force_move(c)}
{
}
client_t c;
};

It is a little tricky because mqtt_cpp supports various underlying layer without virtual function mechanism to support templates.
So we need to use decltype() to get the type information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants