deprecated_async_ops.hpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. //
  2. // deprecated_async_ops.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef ARCHETYPES_DEPRECATED_ASYNC_OPS_HPP
  11. #define ARCHETYPES_DEPRECATED_ASYNC_OPS_HPP
  12. #include <boost/asio/async_result.hpp>
  13. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  14. #include <boost/asio/handler_type.hpp>
  15. #include <boost/asio/error.hpp>
  16. #include <boost/asio/io_context.hpp>
  17. #if defined(BOOST_ASIO_HAS_BOOST_BIND)
  18. # include <boost/bind.hpp>
  19. #else // defined(BOOST_ASIO_HAS_BOOST_BIND)
  20. # include <functional>
  21. #endif // defined(BOOST_ASIO_HAS_BOOST_BIND)
  22. namespace archetypes {
  23. #if defined(BOOST_ASIO_HAS_BOOST_BIND)
  24. namespace bindns = boost;
  25. #else // defined(BOOST_ASIO_HAS_BOOST_BIND)
  26. namespace bindns = std;
  27. #endif // defined(BOOST_ASIO_HAS_BOOST_BIND)
  28. template <typename CompletionToken>
  29. typename boost::asio::async_result<
  30. typename boost::asio::handler_type<CompletionToken,
  31. void()>::type>::type
  32. deprecated_async_op_0(boost::asio::io_context& ctx,
  33. BOOST_ASIO_MOVE_ARG(CompletionToken) token)
  34. {
  35. typedef typename boost::asio::handler_type<CompletionToken,
  36. void()>::type handler_type;
  37. handler_type handler(BOOST_ASIO_MOVE_CAST(CompletionToken)(token));
  38. boost::asio::async_result<handler_type> result(handler);
  39. ctx.post(bindns::bind(BOOST_ASIO_MOVE_CAST(handler_type)(handler)));
  40. return result.get();
  41. }
  42. template <typename CompletionToken>
  43. typename boost::asio::async_result<
  44. typename boost::asio::handler_type<CompletionToken,
  45. void(boost::system::error_code)>::type>::type
  46. deprecated_async_op_ec_0(boost::asio::io_context& ctx,
  47. bool ok, BOOST_ASIO_MOVE_ARG(CompletionToken) token)
  48. {
  49. typedef typename boost::asio::handler_type<CompletionToken,
  50. void(boost::system::error_code)>::type handler_type;
  51. handler_type handler(BOOST_ASIO_MOVE_CAST(CompletionToken)(token));
  52. boost::asio::async_result<handler_type> result(handler);
  53. if (ok)
  54. {
  55. ctx.post(bindns::bind(BOOST_ASIO_MOVE_CAST(handler_type)(handler),
  56. boost::system::error_code()));
  57. }
  58. else
  59. {
  60. ctx.post(bindns::bind(BOOST_ASIO_MOVE_CAST(handler_type)(handler),
  61. boost::system::error_code(boost::asio::error::operation_aborted)));
  62. }
  63. return result.get();
  64. }
  65. template <typename CompletionToken>
  66. typename boost::asio::async_result<
  67. typename boost::asio::handler_type<CompletionToken,
  68. void(std::exception_ptr)>::type>::type
  69. deprecated_async_op_ex_0(boost::asio::io_context& ctx,
  70. bool ok, BOOST_ASIO_MOVE_ARG(CompletionToken) token)
  71. {
  72. typedef typename boost::asio::handler_type<CompletionToken,
  73. void(std::exception_ptr)>::type handler_type;
  74. handler_type handler(BOOST_ASIO_MOVE_CAST(CompletionToken)(token));
  75. boost::asio::async_result<handler_type> result(handler);
  76. if (ok)
  77. {
  78. ctx.post(bindns::bind(BOOST_ASIO_MOVE_CAST(handler_type)(handler),
  79. std::exception_ptr()));
  80. }
  81. else
  82. {
  83. ctx.post(bindns::bind(BOOST_ASIO_MOVE_CAST(handler_type)(handler),
  84. std::make_exception_ptr(std::runtime_error("blah"))));
  85. }
  86. return result.get();
  87. }
  88. template <typename CompletionToken>
  89. typename boost::asio::async_result<
  90. typename boost::asio::handler_type<CompletionToken,
  91. void(int)>::type>::type
  92. deprecated_async_op_1(boost::asio::io_context& ctx,
  93. BOOST_ASIO_MOVE_ARG(CompletionToken) token)
  94. {
  95. typedef typename boost::asio::handler_type<CompletionToken,
  96. void(int)>::type handler_type;
  97. handler_type handler(BOOST_ASIO_MOVE_CAST(CompletionToken)(token));
  98. boost::asio::async_result<handler_type> result(handler);
  99. ctx.post(bindns::bind(BOOST_ASIO_MOVE_CAST(handler_type)(handler), 42));
  100. return result.get();
  101. }
  102. template <typename CompletionToken>
  103. typename boost::asio::async_result<
  104. typename boost::asio::handler_type<CompletionToken,
  105. void(boost::system::error_code, int)>::type>::type
  106. deprecated_async_op_ec_1(boost::asio::io_context& ctx,
  107. bool ok, BOOST_ASIO_MOVE_ARG(CompletionToken) token)
  108. {
  109. typedef typename boost::asio::handler_type<CompletionToken,
  110. void(boost::system::error_code, int)>::type handler_type;
  111. handler_type handler(BOOST_ASIO_MOVE_CAST(CompletionToken)(token));
  112. boost::asio::async_result<handler_type> result(handler);
  113. if (ok)
  114. {
  115. ctx.post(bindns::bind(BOOST_ASIO_MOVE_CAST(handler_type)(handler),
  116. boost::system::error_code(), 42));
  117. }
  118. else
  119. {
  120. ctx.post(bindns::bind(BOOST_ASIO_MOVE_CAST(handler_type)(handler),
  121. boost::system::error_code(boost::asio::error::operation_aborted), 0));
  122. }
  123. return result.get();
  124. }
  125. template <typename CompletionToken>
  126. typename boost::asio::async_result<
  127. typename boost::asio::handler_type<CompletionToken,
  128. void(std::exception_ptr, int)>::type>::type
  129. deprecated_async_op_ex_1(boost::asio::io_context& ctx,
  130. bool ok, BOOST_ASIO_MOVE_ARG(CompletionToken) token)
  131. {
  132. typedef typename boost::asio::handler_type<CompletionToken,
  133. void(std::exception_ptr, int)>::type handler_type;
  134. handler_type handler(BOOST_ASIO_MOVE_CAST(CompletionToken)(token));
  135. boost::asio::async_result<handler_type> result(handler);
  136. if (ok)
  137. {
  138. ctx.post(bindns::bind(BOOST_ASIO_MOVE_CAST(handler_type)(handler),
  139. std::exception_ptr(), 42));
  140. }
  141. else
  142. {
  143. ctx.post(bindns::bind(BOOST_ASIO_MOVE_CAST(handler_type)(handler),
  144. std::make_exception_ptr(std::runtime_error("blah")), 0));
  145. }
  146. return result.get();
  147. }
  148. template <typename CompletionToken>
  149. typename boost::asio::async_result<
  150. typename boost::asio::handler_type<CompletionToken,
  151. void(int, double)>::type>::type
  152. deprecated_async_op_2(boost::asio::io_context& ctx,
  153. BOOST_ASIO_MOVE_ARG(CompletionToken) token)
  154. {
  155. typedef typename boost::asio::handler_type<CompletionToken,
  156. void(int, double)>::type handler_type;
  157. handler_type handler(BOOST_ASIO_MOVE_CAST(CompletionToken)(token));
  158. boost::asio::async_result<handler_type> result(handler);
  159. ctx.post(bindns::bind(BOOST_ASIO_MOVE_CAST(handler_type)(handler),
  160. 42, 2.0));
  161. return result.get();
  162. }
  163. template <typename CompletionToken>
  164. typename boost::asio::async_result<
  165. typename boost::asio::handler_type<CompletionToken,
  166. void(boost::system::error_code, int, double)>::type>::type
  167. deprecated_async_op_ec_2(boost::asio::io_context& ctx,
  168. bool ok, BOOST_ASIO_MOVE_ARG(CompletionToken) token)
  169. {
  170. typedef typename boost::asio::handler_type<CompletionToken,
  171. void(boost::system::error_code, int, double)>::type handler_type;
  172. handler_type handler(BOOST_ASIO_MOVE_CAST(CompletionToken)(token));
  173. boost::asio::async_result<handler_type> result(handler);
  174. if (ok)
  175. {
  176. ctx.post(bindns::bind(BOOST_ASIO_MOVE_CAST(handler_type)(handler),
  177. boost::system::error_code(), 42, 2.0));
  178. }
  179. else
  180. {
  181. ctx.post(bindns::bind(BOOST_ASIO_MOVE_CAST(handler_type)(handler),
  182. boost::system::error_code(boost::asio::error::operation_aborted),
  183. 0, 0.0));
  184. }
  185. return result.get();
  186. }
  187. template <typename CompletionToken>
  188. typename boost::asio::async_result<
  189. typename boost::asio::handler_type<CompletionToken,
  190. void(std::exception_ptr, int, double)>::type>::type
  191. deprecated_async_op_ex_2(boost::asio::io_context& ctx,
  192. bool ok, BOOST_ASIO_MOVE_ARG(CompletionToken) token)
  193. {
  194. typedef typename boost::asio::handler_type<CompletionToken,
  195. void(std::exception_ptr, int, double)>::type handler_type;
  196. handler_type handler(BOOST_ASIO_MOVE_CAST(CompletionToken)(token));
  197. boost::asio::async_result<handler_type> result(handler);
  198. if (ok)
  199. {
  200. ctx.post(bindns::bind(BOOST_ASIO_MOVE_CAST(handler_type)(handler),
  201. std::exception_ptr(), 42, 2.0));
  202. }
  203. else
  204. {
  205. ctx.post(bindns::bind(BOOST_ASIO_MOVE_CAST(handler_type)(handler),
  206. std::make_exception_ptr(std::runtime_error("blah")), 0, 0.0));
  207. }
  208. return result.get();
  209. }
  210. template <typename CompletionToken>
  211. typename boost::asio::async_result<
  212. typename boost::asio::handler_type<CompletionToken,
  213. void(int, double, char)>::type>::type
  214. deprecated_async_op_3(boost::asio::io_context& ctx,
  215. BOOST_ASIO_MOVE_ARG(CompletionToken) token)
  216. {
  217. typedef typename boost::asio::handler_type<CompletionToken,
  218. void(int, double, char)>::type handler_type;
  219. handler_type handler(BOOST_ASIO_MOVE_CAST(CompletionToken)(token));
  220. boost::asio::async_result<handler_type> result(handler);
  221. ctx.post(bindns::bind(BOOST_ASIO_MOVE_CAST(handler_type)(handler),
  222. 42, 2.0, 'a'));
  223. return result.get();
  224. }
  225. template <typename CompletionToken>
  226. typename boost::asio::async_result<
  227. typename boost::asio::handler_type<CompletionToken,
  228. void(boost::system::error_code, int, double, char)>::type>::type
  229. deprecated_async_op_ec_3(boost::asio::io_context& ctx,
  230. bool ok, BOOST_ASIO_MOVE_ARG(CompletionToken) token)
  231. {
  232. typedef typename boost::asio::handler_type<CompletionToken,
  233. void(boost::system::error_code, int, double, char)>::type handler_type;
  234. handler_type handler(BOOST_ASIO_MOVE_CAST(CompletionToken)(token));
  235. boost::asio::async_result<handler_type> result(handler);
  236. if (ok)
  237. {
  238. ctx.post(bindns::bind(BOOST_ASIO_MOVE_CAST(handler_type)(handler),
  239. boost::system::error_code(), 42, 2.0, 'a'));
  240. }
  241. else
  242. {
  243. ctx.post(bindns::bind(BOOST_ASIO_MOVE_CAST(handler_type)(handler),
  244. boost::system::error_code(boost::asio::error::operation_aborted),
  245. 0, 0.0, 'z'));
  246. }
  247. return result.get();
  248. }
  249. template <typename CompletionToken>
  250. typename boost::asio::async_result<
  251. typename boost::asio::handler_type<CompletionToken,
  252. void(std::exception_ptr, int, double, char)>::type>::type
  253. deprecated_async_op_ex_3(boost::asio::io_context& ctx,
  254. bool ok, BOOST_ASIO_MOVE_ARG(CompletionToken) token)
  255. {
  256. typedef typename boost::asio::handler_type<CompletionToken,
  257. void(std::exception_ptr, int, double, char)>::type handler_type;
  258. handler_type handler(BOOST_ASIO_MOVE_CAST(CompletionToken)(token));
  259. boost::asio::async_result<handler_type> result(handler);
  260. if (ok)
  261. {
  262. ctx.post(bindns::bind(BOOST_ASIO_MOVE_CAST(handler_type)(handler),
  263. std::exception_ptr(), 42, 2.0, 'a'));
  264. }
  265. else
  266. {
  267. ctx.post(bindns::bind(BOOST_ASIO_MOVE_CAST(handler_type)(handler),
  268. std::make_exception_ptr(std::runtime_error("blah")),
  269. 0, 0.0, 'z'));
  270. }
  271. return result.get();
  272. }
  273. } // namespace archetypes
  274. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  275. #endif // ARCHETYPES_DEPRECATED_ASYNC_OPS_HPP