|
22 | 22 | #include <boost/asio/buffer.hpp> |
23 | 23 | #include <boost/system/error_code.hpp> |
24 | 24 |
|
| 25 | +#if BOOST_VERSION >= 106600 |
| 26 | +#include <boost/asio/bind_executor.hpp> |
| 27 | +#endif |
| 28 | + |
25 | 29 | #include <type_traits> |
26 | 30 | #include <utility> |
27 | 31 |
|
@@ -685,6 +689,85 @@ class socket : |
685 | 689 | return stm; |
686 | 690 | } |
687 | 691 | }; |
| 692 | + |
| 693 | +#if BOOST_VERSION >= 107000 |
| 694 | +/** |
| 695 | + * \brief Support async methods using completion tokens |
| 696 | + */ |
| 697 | + |
| 698 | +template<typename ConstBufferSequence> |
| 699 | +struct async_send_initiation { |
| 700 | + azmq::socket &socket; |
| 701 | + ConstBufferSequence const &buffers; |
| 702 | + |
| 703 | + template<typename CompletionHandler> |
| 704 | + void operator()(CompletionHandler &&completion_handler) { |
| 705 | + auto executor = boost::asio::get_associated_executor( |
| 706 | + completion_handler, socket.get_executor()); |
| 707 | + socket.async_send(buffers, boost::asio::bind_executor(executor, |
| 708 | + std::bind(std::forward<CompletionHandler>(completion_handler), std::placeholders::_1, std::placeholders::_2))); |
| 709 | + } |
| 710 | +}; |
| 711 | + |
| 712 | +template<typename MutableBufferSequence> |
| 713 | +struct async_receive_initiation { |
| 714 | + azmq::socket &socket; |
| 715 | + MutableBufferSequence const &buffers; |
| 716 | + |
| 717 | + template<typename CompletionHandler> |
| 718 | + void operator()(CompletionHandler &&completion_handler) { |
| 719 | + auto executor = boost::asio::get_associated_executor( |
| 720 | + completion_handler, socket.get_executor()); |
| 721 | + socket.async_receive(buffers, boost::asio::bind_executor(executor, |
| 722 | + std::bind(std::forward<CompletionHandler>(completion_handler), std::placeholders::_1, std::placeholders::_2))); |
| 723 | + } |
| 724 | +}; |
| 725 | + |
| 726 | +template<typename MutableBufferSequence> |
| 727 | +struct async_receive_more_initiation { |
| 728 | + azmq::socket &socket; |
| 729 | + MutableBufferSequence const &buffers; |
| 730 | + |
| 731 | + template<typename CompletionHandler> |
| 732 | + void operator()(CompletionHandler &&completion_handler) { |
| 733 | + auto executor = boost::asio::get_associated_executor( |
| 734 | + completion_handler, socket.get_executor()); |
| 735 | + socket.async_receive_more(buffers, boost::asio::bind_executor(executor, |
| 736 | + std::bind(std::forward<CompletionHandler>(completion_handler), std::placeholders::_1, std::placeholders::_2))); |
| 737 | + } |
| 738 | +}; |
| 739 | + |
| 740 | +template<class CompletionToken, class ConstBufferSequence> |
| 741 | +auto async_send(azmq::socket &socket, ConstBufferSequence const &buffers, |
| 742 | + CompletionToken &&token) |
| 743 | +-> BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, |
| 744 | + void(boost::system::error_code, size_t)) { |
| 745 | + |
| 746 | + return boost::asio::async_initiate<CompletionToken, void(boost::system::error_code, size_t)>( |
| 747 | + async_send_initiation<ConstBufferSequence>{socket, buffers}, token); |
| 748 | +} |
| 749 | + |
| 750 | +template<class CompletionToken, class MutableBufferSequence> |
| 751 | +auto async_receive(azmq::socket &socket, MutableBufferSequence const &buffers, |
| 752 | + CompletionToken &&token) |
| 753 | +-> BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, |
| 754 | + void(boost::system::error_code, size_t)) { |
| 755 | + |
| 756 | + return boost::asio::async_initiate<CompletionToken, void(boost::system::error_code, size_t)>( |
| 757 | + async_receive_initiation<MutableBufferSequence>{socket, buffers}, token); |
| 758 | +} |
| 759 | + |
| 760 | +template<class CompletionToken, class MutableBufferSequence> |
| 761 | +auto async_receive_more(azmq::socket &socket, MutableBufferSequence &buffers, |
| 762 | + CompletionToken &&token) |
| 763 | +-> BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, |
| 764 | + void(boost::system::error_code, size_t)) { |
| 765 | + |
| 766 | + return boost::asio::async_initiate<CompletionToken, void(boost::system::error_code, size_t)>( |
| 767 | + async_receive_more_initiation<MutableBufferSequence>{socket, buffers}, token); |
| 768 | +} |
| 769 | +#endif |
| 770 | + |
688 | 771 | AZMQ_V1_INLINE_NAMESPACE_END |
689 | 772 |
|
690 | 773 | namespace detail { |
@@ -833,4 +916,3 @@ void attach(socket & s, Range r, bool serverish = true) { |
833 | 916 | AZMQ_V1_INLINE_NAMESPACE_END |
834 | 917 | } // namespace azmq |
835 | 918 | #endif // AZMQ_SOCKET_HPP_ |
836 | | - |
|
0 commit comments