#ifndef ASYNC_MQTT5_CHANNEL_TRAITS_HPP #define ASYNC_MQTT5_CHANNEL_TRAITS_HPP #include #include namespace async_mqtt5::detail { namespace asio = boost::asio; using error_code = boost::system::error_code; template class bounded_deque { std::deque _buffer; static constexpr size_t MAX_SIZE = 65535; public: bounded_deque() = default; bounded_deque(size_t n) : _buffer(n) {} size_t size() const { return _buffer.size(); } template void push_back(E&& e) { if (_buffer.size() == MAX_SIZE) _buffer.pop_front(); _buffer.push_back(std::forward(e)); } void pop_front() { _buffer.pop_front(); } void clear() { _buffer.clear(); } const auto& front() const noexcept { return _buffer.front(); } auto& front() noexcept { return _buffer.front(); } }; template struct channel_traits { template struct rebind { using other = channel_traits; }; }; template struct channel_traits { static_assert(sizeof...(Args) > 0); template struct rebind { using other = channel_traits; }; template struct container { using type = bounded_deque; }; using receive_cancelled_signature = R(error_code, Args...); template static void invoke_receive_cancelled(F f) { std::forward(f)( asio::error::operation_aborted, typename std::decay_t()... ); } using receive_closed_signature = R(error_code, Args...); template static void invoke_receive_closed(F f) { std::forward(f)( asio::error::operation_aborted, typename std::decay_t()... ); } }; } // namespace async_mqtt5::detail #endif // !ASYNC_MQTT5_CHANNEL_TRAITS_HPP