identt
AsioCompat.hpp
Go to the documentation of this file.
1 
33 #ifndef _IDENTT_HTTP_ASIO_COMPAT_HPP_
34 #define _IDENTT_HTTP_ASIO_COMPAT_HPP_
35 
36 #include <memory>
37 
38 #include <boost/asio.hpp>
39 #include <boost/asio/steady_timer.hpp>
40 
41 namespace identt {
42 namespace http {
43 
44 namespace asio = boost::asio;
45 namespace error = asio::error;
46 using error_code = boost::system::error_code;
47 namespace errc = boost::system::errc;
48 using system_error = boost::system::system_error;
49 namespace make_error_code = boost::system::errc;
50 
51 } // namespace http
52 } // namespace identt
53 
54 namespace identt {
55 namespace http {
56 #if(BOOST_ASIO_VERSION >= 101300)
57 using io_context = asio::io_context;
58 using io_whatever = asio::io_context;
59 using resolver_results = asio::ip::tcp::resolver::results_type;
60 using async_connect_endpoint = asio::ip::tcp::endpoint;
61 
62 inline void restart(io_context &context) noexcept
63 {
64  context.restart();
65 }
66 inline asio::ip::address make_address(const std::string &str) noexcept
67 {
68  return asio::ip::make_address(str);
69 }
70 template <typename socket_type>
71 asio::executor get_socket_executor(socket_type &socket)
72 {
73  return socket.get_executor();
74 }
75 template <typename handler_type>
76 void async_resolve(asio::ip::tcp::resolver &resolver, const std::pair<std::string, std::string> &host_port, handler_type &&handler)
77 {
78  resolver.async_resolve(host_port.first, host_port.second, std::forward<handler_type>(handler));
79 }
80 #else
81 using io_context = asio::io_service;
82 using io_whatever = asio::io_service;
83 using resolver_results = asio::ip::tcp::resolver::iterator;
84 using async_connect_endpoint = asio::ip::tcp::resolver::iterator;
85 
86 inline void restart(io_context &context) noexcept
87 {
88  context.reset();
89 }
90 inline asio::ip::address make_address(const std::string &str) noexcept
91 {
92  return asio::ip::address::from_string(str);
93 }
94 template <typename socket_type>
95 io_context &get_socket_executor(socket_type &socket)
96 {
97  return socket.get_io_service();
98 }
99 template <typename handler_type>
100 void async_resolve(asio::ip::tcp::resolver &resolver, const std::pair<std::string, std::string> &host_port, handler_type &&handler)
101 {
102  resolver.async_resolve(asio::ip::tcp::resolver::query(host_port.first, host_port.second), std::forward<handler_type>(handler));
103 }
104 #endif
105 } // namespace http
106 } // namespace identt
107 
108 #endif // _IDENTT_HTTP_ASIO_COMPAT_HPP_
Definition: CryptoBase.hpp:49