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

Support for BOOST_ASIO_NO_DEPRECATED #409

Closed
ropieur opened this issue Sep 10, 2019 · 18 comments
Closed

Support for BOOST_ASIO_NO_DEPRECATED #409

ropieur opened this issue Sep 10, 2019 · 18 comments

Comments

@ropieur
Copy link

ropieur commented Sep 10, 2019

Impossible for me to elude the #define BOOST_ASIO_NO_DEPRECATED.
Is there any plan to upgrade the code in a near future?

@redboltz
Copy link
Owner

I just recognized the issue now.

The minimum boost requirement is 1.66.0 on the master branch.
Does BOOST_ASIO_NO_DEPRECATED work on 1.66.0?

If it does, I will update step by step. But priority is not so high because I have other higher priority issues.

@redboltz
Copy link
Owner

@ropieur , do you know where BOOST_ASIO_NO_DEPRECATED is documented? I want to know features that will be deprecated.

@ropieur
Copy link
Author

ropieur commented Sep 10, 2019

You should look at here

@ropieur
Copy link
Author

ropieur commented Sep 10, 2019

I found a bug in const_buffer_util.hpp
BOOST_VERION should be BOOST_VERSION (with an S)

@ropieur
Copy link
Author

ropieur commented Sep 10, 2019

  • Replace all io_service by io_context
  • In mqtt/null_strand.hpp: ios_.post( becomes boost::asio::post(ios_,
  • In mqtt/client.hpp line 911, lamdba should take Iterator (or auto) instead of as::ip::tcp::resolver::iterator
  • in tcp_endpoint.hpp and ws_endpoint.hpp:
    include <boost/asio/bind_executor.hpp>
    replace strand_.wrap( by boost::asio::bind_executor(strand_,
    replace strand_.post( by boost::asio::post(strand_,
  • and in type_erased_socket.hpp, (as mentioned in closed ticket Problems with BOOST_TYPE_ERASURE_MEMBER #345, but still don't know why)
    skip #if BOOST_VERSION >= 106700

@redboltz
Copy link
Owner

@ropieur , thank you very much! Your comment would save my time a lot.
I think that I can support BOOST_ASIO_NO_DEPRECATED earlier than I thought at first thanks to your comment.

I will fix BOOST_VERSION bug separately and immediately.

@redboltz
Copy link
Owner

#413 fixes BOOST_VERSION problem.

@redboltz
Copy link
Owner

@jonesmz , I will create a PR that support BOOST_ASIO_NO_DEPRECATED after the series of enum class pull requests are merged to avoid conflict.

@jonesmz
Copy link
Contributor

jonesmz commented Sep 11, 2019

Alright, sounds good to me.

@redboltz
Copy link
Owner

#268 is related issue.

I think that the following step is good:

  1. Support BOOST_ASIO_NO_DEPRECATED.
  2. Introduce MQTT_NS wrapper that wraps Boost.Asio and NetworkTS, and add MQTT_STD_NETWORK macro.

@redboltz
Copy link
Owner

@jonesmz , I think that the series of enum class pull requests have been merged. Is that right?

I will start implementing BOOST_ASIO_NO_DEPRECATED support.

@jonesmz
Copy link
Contributor

jonesmz commented Sep 11, 2019

Yes. Go ahead.

@redboltz
Copy link
Owner

I got compile error as follows:

[ 50%] Building CXX object test/CMakeFiles/pubsub_no_strand.dir/pubsub_no_strand.cpp.o
In file included from /home/kondo/work/mqtt_cpp/test/pubsub_no_strand.cpp:8:
In file included from /home/kondo/work/mqtt_cpp/test/test_settings.hpp:16:
In file included from /home/kondo/work/mqtt_cpp/include/mqtt/client.hpp:26:
/home/kondo/work/mqtt_cpp/include/mqtt/tcp_endpoint.hpp:72:13: error: no matching function for call to 'bind_executor'
            as::bind_executor(
            ^~~~~~~~~~~~~~~~~
/home/kondo/work/mqtt_cpp/include/mqtt/type_erased_socket.hpp:25:43: note: in instantiation of function template specialization

candidate templates

/usr/include/boost/asio/bind_executor.hpp:498:1: note: candidate template ignored: requirement
      'is_executor<mqtt::null_strand>::value' was not satisfied [with Executor = mqtt::null_strand, T = std::function<void
      (const boost::system::error_code &, unsigned long)>]
bind_executor(const Executor& ex, BOOST_ASIO_MOVE_ARG(T) t,
^
/usr/include/boost/asio/bind_executor.hpp:509:1: note: candidate template ignored: requirement 'is_convertible<mqtt::null_strand
      &, boost::asio::execution_context &>::value' was not satisfied [with ExecutionContext = mqtt::null_strand, T =
      std::function<void (const boost::system::error_code &, unsigned long)>]
bind_executor(ExecutionContext& ctx, BOOST_ASIO_MOVE_ARG(T) t,

It seems that null strand needs to meet executor concept.
https://github.com/redboltz/mqtt_cpp/blob/master/include/mqtt/null_strand.hpp#L20

I'm looking for a good way to do that but it's complicated. If someone know the way, please tell me.

Note: null_strand is do nothing strand. It is used to remove strand if dispatch in endpoint code.

@redboltz
Copy link
Owner

redboltz commented Sep 11, 2019

The error is reported ad modified tcp_endpoint.hpp.

The essence of the code is as follows:

template <typename Socket, typename Strand>
class tcp_endpoint {
public:
   ...

    template <typename MutableBufferSequence, typename ReadHandler>
    void async_read(
        MutableBufferSequence && buffers,
        ReadHandler&& handler) {
        as::async_read(
            tcp_,
            std::forward<MutableBufferSequence>(buffers),
            as::bind_executor( // ****** here 
                strand_,
                std::forward<ReadHandler>(handler)
            )
        );
    }

@redboltz
Copy link
Owner

I solved the error.
I'm not sure it is the best way. At least, it successfully compiled and all tests passed.

namespace MQTT_NS {

namespace as = boost::asio;

struct null_strand {
    null_strand(as::io_context& ioc) noexcept : ioc_(ioc) {}
    template <typename Func, typename Allocator>
    void post(Func&& f, Allocator) const {
        as::post(
            ioc_,
            [f = std::forward<Func>(f)] () mutable {
                std::forward<Func>(f)();
            }
        );
    }
    template <typename Func, typename Allocator>
    void defer(Func&& f, Allocator) const {
        as::defer(
            ioc_,
            [f = std::forward<Func>(f)] () mutable {
                std::forward<Func>(f)();
            }
        );
    }
    template <typename Func, typename Allocator>
    void dispatch(Func&& f, Allocator) const {
        std::forward<Func>(f)();
    }
    void on_work_started() const noexcept {}
    void on_work_finished() const noexcept {}
    as::io_context& context() noexcept{ return ioc_; }
    as::io_context const& context() const noexcept { return ioc_; }
private:
    as::io_context& ioc_;
};

inline bool operator==(null_strand const& lhs, null_strand const& rhs) {
    return std::addressof(lhs) == std::addressof(rhs);
}

inline bool operator!=(null_strand const& lhs, null_strand const& rhs) {
    return !(lhs == rhs);
}

} // namespace MQTT_NS

namespace boost {
namespace asio {

template<>
struct is_executor<MQTT_NS::null_strand> : std::true_type {
};

} // namespace asio
} // namespace boost

@redboltz
Copy link
Owner

I sent the PR to fix the issue as #419. Could you check this?

@ropieur
Copy link
Author

ropieur commented Sep 11, 2019

@redboltz,
Just checked impl_409 branch. Everything is ok, except for #345.

@redboltz
Copy link
Owner

I reopen #345. I close the issue.

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