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

Supporting async when filtering. #42

Closed
magni-mar opened this issue Jul 3, 2023 · 9 comments
Closed

Supporting async when filtering. #42

magni-mar opened this issue Jul 3, 2023 · 9 comments

Comments

@magni-mar
Copy link

    recv(
        filter fil,
        std::set<control_packet_type> types,
        CompletionToken&& token
    ) {

I am trying to filter received packages by their type and was wondering why this function doesn't support async as the normal recv function without filtering does support async.

    recv(
        CompletionToken&& token
    ) {
@redboltz
Copy link
Owner

redboltz commented Jul 3, 2023

both recv() is async. I'm not sure what are you asking. Could you elaborate your question?

@redboltz
Copy link
Owner

redboltz commented Jul 3, 2023

Here is a little usage document https://github.com/redboltz/async_mqtt#control-packet-type-filter

@jbbjarnason
Copy link

@magni-mar is meaning the usage of recv with awaitables. When the asio::use_awaitable is passed in as completion token to the filtered recv call he gets a compile error. It seems to be that the filtered recv call is calling the token explicitly instead of using async_compose.

@redboltz
Copy link
Owner

redboltz commented Jul 3, 2023

@jbbjarnason , thank you for the comment. Now, I understand the issue is compiling error, and the error seems to be caused by direct token() call.
Now, I just wrote the test code that reproduces the compile error.
I will fix it soon.

redboltz added a commit that referenced this issue Jul 3, 2023
Non void type CompletionToken caused compile error when endpoint::recv()
with filter is used.
The error was caused by return type mistatch.
To fix the error, filtering process is moved to recv_impl.
@redboltz
Copy link
Owner

redboltz commented Jul 3, 2023

I belive that I fixed the issue. Coud you try #44 ?

@magni-mar
Copy link
Author

Unfortunately this doesn't work. I am calling the function like this:

co_await  mqtt_client_->recv(async_mqtt::filter::match, {async_mqtt::control_packet_type::connack}, asio::use_awaitable);

and these are the compiler errors:

====================[ Build | mqtt-broadcaster | ci-clang-release ]=============
/usr/bin/cmake --build /home/magni-the-developer/Documents/framework/build/ci-clang-release --target mqtt-broadcaster -j 30
[1/2] Building CXX object exes/mqtt-broadcaster/CMakeFiles/mqtt-broadcaster.dir/src/main.cpp.o
FAILED: exes/mqtt-broadcaster/CMakeFiles/mqtt-broadcaster.dir/src/main.cpp.o 
/usr/bin/clang++-16 -DASYNC_MQTT_USE_LOG -DONLY_C_LOCALE=0 -DUNITS_DOWNCAST_MODE=1 -I/home/magni-the-developer/Documents/framework/exes/mqtt-broadcaster/inc -I/home/magni-the-developer/Documents/framework/libs/progbase/inc/public -I/home/magni-the-developer/Documents/framework/libs/logger/inc/public -I/home/magni-the-developer/Documents/framework/libs/stx/inc/public -I/home/magni-the-developer/Documents/framework/libs/ipc/inc/public -I/home/magni-the-developer/Documents/framework/libs/dbus_util/inc/public -I/home/magni-the-developer/Documents/framework/libs/configure_options/inc/public -I/home/magni-the-developer/Documents/framework/libs/operation_mode/inc/public -I/home/magni-the-developer/Documents/framework/libs/confman/inc/public -isystem /home/magni-the-developer/Documents/framework/vcpkg-sysroot-clang/x64-linux-clang/include -isystem /home/magni-the-developer/Documents/framework/vcpkg-sysroot-clang/x64-linux-clang/lib/pkgconfig/../../include -isystem /home/magni-the-developer/Documents/framework/vcpkg-sysroot-clang/x64-linux-clang/lib/pkgconfig/../../include/libmount -isystem /home/magni-the-developer/Documents/framework/vcpkg-sysroot-clang/x64-linux-clang/lib/pkgconfig/../../include/blkid -stdlib=libc++ -O3 -DNDEBUG -std=gnu++2b -fcolor-diagnostics -fuse-ld=lld -flto=thin -fvisibility=hidden -fvisibility-inlines-hidden -Weverything -Werror -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-pre-c++14-compat -Wno-pre-c++17-compat -Wno-pre-c++20-compat-pedantic -Wno-c++20-compat -Wno-unused-parameter -Wno-padded -Wno-unused-command-line-argument -Wno-missing-braces -MD -MT exes/mqtt-broadcaster/CMakeFiles/mqtt-broadcaster.dir/src/main.cpp.o -MF exes/mqtt-broadcaster/CMakeFiles/mqtt-broadcaster.dir/src/main.cpp.o.d -o exes/mqtt-broadcaster/CMakeFiles/mqtt-broadcaster.dir/src/main.cpp.o -c /home/magni-the-developer/Documents/framework/exes/mqtt-broadcaster/src/main.cpp
In file included from /home/magni-the-developer/Documents/framework/exes/mqtt-broadcaster/src/main.cpp:1:
In file included from /home/magni-the-developer/Documents/framework/vcpkg-sysroot-clang/x64-linux-clang/include/async_mqtt/all.hpp:13:
/home/magni-the-developer/Documents/framework/vcpkg-sysroot-clang/x64-linux-clang/include/async_mqtt/endpoint.hpp:442:25: error: type 'boost::asio::use_awaitable_t<>' does not provide a call operator
                        token(force_move(pv));
                        ^~~~~
/home/magni-the-developer/Documents/framework/exes/mqtt-broadcaster/inc/mqtt_broadcaster.hpp:123:33: note: in instantiation of function template specialization 'async_mqtt::basic_endpoint<async_mqtt::role::client, 2, boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::io_context::basic_executor_type<std::allocator<void>, 0>>>::recv<const boost::asio::use_awaitable_t<> &>' requested here
        co_await  mqtt_client_->recv(async_mqtt::filter::match, {async_mqtt::control_packet_type::connack}, asio::use_awaitable);
                                ^
/home/magni-the-developer/Documents/framework/exes/mqtt-broadcaster/inc/mqtt_broadcaster.hpp:49:44: note: in instantiation of member function 'mqtt_broadcaster<tfc::ipc_ruler::ipc_manager_client &, sdbusplus::bus::match::match, async_mqtt::basic_endpoint<async_mqtt::role::client, 2, boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::io_context::basic_executor_type<std::allocator<void>, 0>>>>::connect_to_broker' requested here
    asio::co_spawn(mqtt_client_->strand(), connect_to_broker(), asio::detached);
                                           ^
/home/magni-the-developer/Documents/framework/exes/mqtt-broadcaster/src/main.cpp:32:7: note: in instantiation of member function 'mqtt_broadcaster<tfc::ipc_ruler::ipc_manager_client &, sdbusplus::bus::match::match, async_mqtt::basic_endpoint<async_mqtt::role::client, 2, boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::io_context::basic_executor_type<std::allocator<void>, 0>>>>::mqtt_broadcaster' requested here
      application(ctx, mqtt_host, mqtt_port, mqtt_username, mqtt_password, ipc_client, mqtt_client);
      ^
In file included from /home/magni-the-developer/Documents/framework/exes/mqtt-broadcaster/src/main.cpp:1:
In file included from /home/magni-the-developer/Documents/framework/vcpkg-sysroot-clang/x64-linux-clang/include/async_mqtt/all.hpp:13:
/home/magni-the-developer/Documents/framework/vcpkg-sysroot-clang/x64-linux-clang/include/async_mqtt/endpoint.hpp:442:25: error: type 'boost::asio::use_awaitable_t<>' does not provide a call operator
                        token(force_move(pv));
                        ^~~~~
/home/magni-the-developer/Documents/framework/vcpkg-sysroot-clang/x64-linux-clang/include/async_mqtt/endpoint.hpp:403:16: note: in instantiation of function template specialization 'async_mqtt::basic_endpoint<async_mqtt::role::client, 2, boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::io_context::basic_executor_type<std::allocator<void>, 0>>>::recv<boost::asio::use_awaitable_t<>>' requested here
        return recv(filter::match, force_move(types), std::forward<CompletionToken>(token));
               ^
/home/magni-the-developer/Documents/framework/vcpkg-sysroot-clang/x64-linux-clang/include/async_mqtt/endpoint.hpp:439:25: note: in instantiation of function template specialization 'async_mqtt::basic_endpoint<async_mqtt::role::client, 2, boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::io_context::basic_executor_type<std::allocator<void>, 0>>>::recv<boost::asio::use_awaitable_t<>>' requested here
                        recv(force_move(types), force_move(token));
                        ^
/home/magni-the-developer/Documents/framework/exes/mqtt-broadcaster/inc/mqtt_broadcaster.hpp:123:33: note: in instantiation of function template specialization 'async_mqtt::basic_endpoint<async_mqtt::role::client, 2, boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::io_context::basic_executor_type<std::allocator<void>, 0>>>::recv<const boost::asio::use_awaitable_t<> &>' requested here
        co_await  mqtt_client_->recv(async_mqtt::filter::match, {async_mqtt::control_packet_type::connack}, asio::use_awaitable);
                                ^
/home/magni-the-developer/Documents/framework/exes/mqtt-broadcaster/inc/mqtt_broadcaster.hpp:49:44: note: in instantiation of member function 'mqtt_broadcaster<tfc::ipc_ruler::ipc_manager_client &, sdbusplus::bus::match::match, async_mqtt::basic_endpoint<async_mqtt::role::client, 2, boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::io_context::basic_executor_type<std::allocator<void>, 0>>>>::connect_to_broker' requested here
    asio::co_spawn(mqtt_client_->strand(), connect_to_broker(), asio::detached);
                                           ^
/home/magni-the-developer/Documents/framework/exes/mqtt-broadcaster/src/main.cpp:32:7: note: in instantiation of member function 'mqtt_broadcaster<tfc::ipc_ruler::ipc_manager_client &, sdbusplus::bus::match::match, async_mqtt::basic_endpoint<async_mqtt::role::client, 2, boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::io_context::basic_executor_type<std::allocator<void>, 0>>>>::mqtt_broadcaster' requested here
      application(ctx, mqtt_host, mqtt_port, mqtt_username, mqtt_password, ipc_client, mqtt_client);
      ^
2 errors generated.
ninja: build stopped: subcommand failed.

@redboltz
Copy link
Owner

redboltz commented Jul 3, 2023

Could you check your commit hash? It should be c2614a0

@magni-mar
Copy link
Author

My mistake, I copy/pasted the code to the wrong file location just for testing. This fix works.

Thank you for your quick response.

@redboltz
Copy link
Owner

redboltz commented Jul 3, 2023

Ok, I will merge it.

redboltz added a commit that referenced this issue Jul 3, 2023
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

3 participants