async_client.hpp 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780
  1. // Copyright Takatoshi Kondo 2015
  2. //
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #if !defined(MQTT_ASYNC_CLIENT_HPP)
  7. #define MQTT_ASYNC_CLIENT_HPP
  8. #include <mqtt/namespace.hpp>
  9. #include <mqtt/client.hpp>
  10. #include <mqtt/move.hpp>
  11. #include <mqtt/callable_overlay.hpp>
  12. namespace MQTT_NS {
  13. template <typename Socket, std::size_t PacketIdBytes = 2>
  14. class async_client;
  15. template <typename Ioc>
  16. std::shared_ptr<
  17. callable_overlay<
  18. async_client<
  19. tcp_endpoint<
  20. as::ip::tcp::socket,
  21. strand
  22. >
  23. >
  24. >
  25. >
  26. make_async_client(Ioc& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1);
  27. template <typename Ioc>
  28. std::shared_ptr<
  29. callable_overlay<
  30. async_client<
  31. tcp_endpoint<
  32. as::ip::tcp::socket,
  33. strand
  34. >
  35. >
  36. >
  37. >
  38. make_async_client(Ioc& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1);
  39. template <typename Ioc>
  40. std::shared_ptr<
  41. callable_overlay<
  42. async_client<
  43. tcp_endpoint<
  44. as::ip::tcp::socket,
  45. null_strand
  46. >
  47. >
  48. >
  49. >
  50. make_async_client_no_strand(Ioc& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1);
  51. template <typename Ioc>
  52. std::shared_ptr<
  53. callable_overlay<
  54. async_client<
  55. tcp_endpoint<
  56. as::ip::tcp::socket,
  57. null_strand
  58. >
  59. >
  60. >
  61. >
  62. make_async_client_no_strand(Ioc& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1);
  63. #if defined(MQTT_USE_WS)
  64. template <typename Ioc>
  65. std::shared_ptr<
  66. callable_overlay<
  67. async_client<
  68. ws_endpoint<
  69. as::ip::tcp::socket,
  70. strand
  71. >
  72. >
  73. >
  74. >
  75. make_async_client_ws(Ioc& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1);
  76. template <typename Ioc>
  77. std::shared_ptr<
  78. callable_overlay<
  79. async_client<
  80. ws_endpoint<
  81. as::ip::tcp::socket,
  82. strand
  83. >
  84. >
  85. >
  86. >
  87. make_async_client_ws(Ioc& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1);
  88. template <typename Ioc>
  89. std::shared_ptr<
  90. callable_overlay<
  91. async_client<
  92. ws_endpoint<
  93. as::ip::tcp::socket,
  94. null_strand
  95. >
  96. >
  97. >
  98. >
  99. make_async_client_no_strand_ws(Ioc& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1);
  100. template <typename Ioc>
  101. std::shared_ptr<
  102. callable_overlay<
  103. async_client<
  104. ws_endpoint<
  105. as::ip::tcp::socket,
  106. null_strand
  107. >
  108. >
  109. >
  110. >
  111. make_async_client_no_strand_ws(Ioc& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1);
  112. #endif // defined(MQTT_USE_WS)
  113. #if defined(MQTT_USE_TLS)
  114. template <typename Ioc>
  115. std::shared_ptr<
  116. callable_overlay<
  117. async_client<
  118. tcp_endpoint<
  119. tls::stream<as::ip::tcp::socket>,
  120. strand
  121. >
  122. >
  123. >
  124. >
  125. make_tls_async_client(Ioc& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1);
  126. template <typename Ioc>
  127. std::shared_ptr<
  128. callable_overlay<
  129. async_client<
  130. tcp_endpoint<
  131. tls::stream<as::ip::tcp::socket>,
  132. strand
  133. >
  134. >
  135. >
  136. >
  137. make_tls_async_client(Ioc& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1);
  138. template <typename Ioc>
  139. std::shared_ptr<
  140. callable_overlay<
  141. async_client<
  142. tcp_endpoint<
  143. tls::stream<as::ip::tcp::socket>,
  144. null_strand
  145. >
  146. >
  147. >
  148. >
  149. make_tls_async_client_no_strand(Ioc& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1);
  150. template <typename Ioc>
  151. std::shared_ptr<
  152. callable_overlay<
  153. async_client<
  154. tcp_endpoint<
  155. tls::stream<as::ip::tcp::socket>,
  156. null_strand
  157. >
  158. >
  159. >
  160. >
  161. make_tls_async_client_no_strand(Ioc& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1);
  162. #if defined(MQTT_USE_WS)
  163. template <typename Ioc>
  164. std::shared_ptr<
  165. callable_overlay<
  166. async_client<
  167. ws_endpoint<
  168. tls::stream<as::ip::tcp::socket>,
  169. strand
  170. >
  171. >
  172. >
  173. >
  174. make_tls_async_client_ws(Ioc& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1);
  175. template <typename Ioc>
  176. std::shared_ptr<
  177. callable_overlay<
  178. async_client<
  179. ws_endpoint<
  180. tls::stream<as::ip::tcp::socket>,
  181. strand
  182. >
  183. >
  184. >
  185. >
  186. make_tls_async_client_ws(Ioc& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1);
  187. template <typename Ioc>
  188. std::shared_ptr<
  189. callable_overlay<
  190. async_client<
  191. ws_endpoint<
  192. tls::stream<as::ip::tcp::socket>,
  193. null_strand
  194. >
  195. >
  196. >
  197. >
  198. make_tls_async_client_no_strand_ws(Ioc& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1);
  199. template <typename Ioc>
  200. std::shared_ptr<
  201. callable_overlay<
  202. async_client<
  203. ws_endpoint<
  204. tls::stream<as::ip::tcp::socket>,
  205. null_strand
  206. >
  207. >
  208. >
  209. >
  210. make_tls_async_client_no_strand_ws(Ioc& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1);
  211. #endif // defined(MQTT_USE_WS)
  212. #endif // defined(MQTT_USE_TLS)
  213. // 32bit Packet Id (experimental)
  214. template <typename Ioc>
  215. std::shared_ptr<
  216. callable_overlay<
  217. async_client<
  218. tcp_endpoint<
  219. as::ip::tcp::socket,
  220. strand
  221. >,
  222. 4
  223. >
  224. >
  225. >
  226. make_async_client_32(Ioc& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1);
  227. template <typename Ioc>
  228. std::shared_ptr<
  229. callable_overlay<
  230. async_client<
  231. tcp_endpoint<
  232. as::ip::tcp::socket,
  233. strand
  234. >,
  235. 4
  236. >
  237. >
  238. >
  239. make_async_client_32(Ioc& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1);
  240. template <typename Ioc>
  241. std::shared_ptr<
  242. callable_overlay<
  243. async_client<
  244. tcp_endpoint<
  245. as::ip::tcp::socket,
  246. null_strand
  247. >,
  248. 4
  249. >
  250. >
  251. >
  252. make_async_client_no_strand_32(Ioc& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1);
  253. template <typename Ioc>
  254. std::shared_ptr<
  255. callable_overlay<
  256. async_client<
  257. tcp_endpoint<
  258. as::ip::tcp::socket,
  259. null_strand
  260. >,
  261. 4
  262. >
  263. >
  264. >
  265. make_async_client_no_strand_32(Ioc& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1);
  266. #if defined(MQTT_USE_WS)
  267. template <typename Ioc>
  268. std::shared_ptr<
  269. callable_overlay<
  270. async_client<
  271. ws_endpoint<
  272. as::ip::tcp::socket,
  273. strand
  274. >,
  275. 4
  276. >
  277. >
  278. >
  279. make_async_client_ws_32(Ioc& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1);
  280. template <typename Ioc>
  281. std::shared_ptr<
  282. callable_overlay<
  283. async_client<
  284. ws_endpoint<
  285. as::ip::tcp::socket,
  286. strand
  287. >,
  288. 4
  289. >
  290. >
  291. >
  292. make_async_client_ws_32(Ioc& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1);
  293. template <typename Ioc>
  294. std::shared_ptr<
  295. callable_overlay<
  296. async_client<
  297. ws_endpoint<
  298. as::ip::tcp::socket,
  299. null_strand
  300. >,
  301. 4
  302. >
  303. >
  304. >
  305. make_async_client_no_strand_ws_32(Ioc& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1);
  306. template <typename Ioc>
  307. std::shared_ptr<
  308. callable_overlay<
  309. async_client<
  310. ws_endpoint<
  311. as::ip::tcp::socket,
  312. null_strand
  313. >,
  314. 4
  315. >
  316. >
  317. >
  318. make_async_client_no_strand_ws_32(Ioc& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1);
  319. #endif // defined(MQTT_USE_WS)
  320. #if defined(MQTT_USE_TLS)
  321. template <typename Ioc>
  322. std::shared_ptr<
  323. callable_overlay<
  324. async_client<
  325. tcp_endpoint<
  326. tls::stream<as::ip::tcp::socket>,
  327. strand
  328. >,
  329. 4
  330. >
  331. >
  332. >
  333. make_tls_async_client_32(Ioc& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1);
  334. template <typename Ioc>
  335. std::shared_ptr<
  336. callable_overlay<
  337. async_client<
  338. tcp_endpoint<
  339. tls::stream<as::ip::tcp::socket>,
  340. strand
  341. >,
  342. 4
  343. >
  344. >
  345. >
  346. make_tls_async_client_32(Ioc& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1);
  347. template <typename Ioc>
  348. std::shared_ptr<
  349. callable_overlay<
  350. async_client<
  351. tcp_endpoint<
  352. tls::stream<as::ip::tcp::socket>,
  353. null_strand
  354. >,
  355. 4
  356. >
  357. >
  358. >
  359. make_tls_async_client_no_strand_32(Ioc& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1);
  360. template <typename Ioc>
  361. std::shared_ptr<
  362. callable_overlay<
  363. async_client<
  364. tcp_endpoint<
  365. tls::stream<as::ip::tcp::socket>,
  366. null_strand
  367. >,
  368. 4
  369. >
  370. >
  371. >
  372. make_tls_async_client_no_strand_32(Ioc& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1);
  373. #if defined(MQTT_USE_WS)
  374. template <typename Ioc>
  375. std::shared_ptr<
  376. callable_overlay<
  377. async_client<
  378. ws_endpoint<
  379. tls::stream<as::ip::tcp::socket>,
  380. strand
  381. >,
  382. 4
  383. >
  384. >
  385. >
  386. make_tls_async_client_ws_32(Ioc& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1);
  387. template <typename Ioc>
  388. std::shared_ptr<
  389. callable_overlay<
  390. async_client<
  391. ws_endpoint<
  392. tls::stream<as::ip::tcp::socket>,
  393. strand
  394. >,
  395. 4
  396. >
  397. >
  398. >
  399. make_tls_async_client_ws_32(Ioc& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1);
  400. template <typename Ioc>
  401. std::shared_ptr<
  402. callable_overlay<
  403. async_client<
  404. ws_endpoint<
  405. tls::stream<as::ip::tcp::socket>,
  406. null_strand
  407. >,
  408. 4
  409. >
  410. >
  411. >
  412. make_tls_async_client_no_strand_ws_32(Ioc& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1);
  413. template <typename Ioc>
  414. std::shared_ptr<
  415. callable_overlay<
  416. async_client<
  417. ws_endpoint<
  418. tls::stream<as::ip::tcp::socket>,
  419. null_strand
  420. >,
  421. 4
  422. >
  423. >
  424. >
  425. make_tls_async_client_no_strand_ws_32(Ioc& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1);
  426. #endif // defined(MQTT_USE_WS)
  427. #endif // defined(MQTT_USE_TLS)
  428. template <typename Socket, std::size_t PacketIdBytes>
  429. class async_client : public client<Socket, PacketIdBytes> {
  430. using this_type = async_client<Socket, PacketIdBytes>;
  431. using base = client<Socket, PacketIdBytes>;
  432. using constructor_access = typename base::constructor_access;
  433. public:
  434. /**
  435. * Constructor used by factory functions at the end of this file.
  436. */
  437. template<typename ... Args>
  438. explicit async_client(constructor_access, Args && ... args)
  439. : async_client(std::forward<Args>(args)...)
  440. { }
  441. /**
  442. * @brief Create no tls async_client with strand.
  443. * @param ioc io_context object.
  444. * @param host hostname
  445. * @param port port number
  446. * @return async_client object
  447. */
  448. template <typename Ioc>
  449. friend std::shared_ptr<
  450. callable_overlay<
  451. async_client<
  452. tcp_endpoint<
  453. as::ip::tcp::socket,
  454. strand
  455. >
  456. >
  457. >
  458. >
  459. make_async_client(Ioc& ioc, std::string host, std::string port, protocol_version version);
  460. /**
  461. * @brief Create no tls async_client without strand.
  462. * @param ioc io_context object.
  463. * @param host hostname
  464. * @param port port number
  465. * @return async_client object
  466. */
  467. template <typename Ioc>
  468. friend std::shared_ptr<
  469. callable_overlay<
  470. async_client<
  471. tcp_endpoint<
  472. as::ip::tcp::socket,
  473. null_strand
  474. >
  475. >
  476. >
  477. >
  478. make_async_client_no_strand(Ioc& ioc, std::string host, std::string port, protocol_version version);
  479. #if defined(MQTT_USE_WS)
  480. /**
  481. * @brief Create no tls websocket async_client with strand.
  482. * @param ioc io_context object.
  483. * @param host hostname
  484. * @param port port number
  485. * @param path path string
  486. * @return async_client object.
  487. * strand is controlled by ws_endpoint, not endpoint, so async_client has null_strand template argument.
  488. */
  489. template <typename Ioc>
  490. friend std::shared_ptr<
  491. callable_overlay<
  492. async_client<
  493. ws_endpoint<
  494. as::ip::tcp::socket,
  495. strand
  496. >
  497. >
  498. >
  499. >
  500. make_async_client_ws(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version);
  501. /**
  502. * @brief Create no tls websocket async_client without strand.
  503. * @param ioc io_context object.
  504. * @param host hostname
  505. * @param port port number
  506. * @param path path string
  507. * @return async_client object
  508. */
  509. template <typename Ioc>
  510. friend std::shared_ptr<
  511. callable_overlay<
  512. async_client<
  513. ws_endpoint<
  514. as::ip::tcp::socket,
  515. null_strand
  516. >
  517. >
  518. >
  519. >
  520. make_async_client_no_strand_ws(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version);
  521. #endif // defined(MQTT_USE_WS)
  522. #if defined(MQTT_USE_TLS)
  523. /**
  524. * @brief Create tls async_client with strand.
  525. * @param ioc io_context object.
  526. * @param host hostname
  527. * @param port port number
  528. * @return async_client object
  529. */
  530. template <typename Ioc>
  531. friend std::shared_ptr<
  532. callable_overlay<
  533. async_client<
  534. tcp_endpoint<
  535. tls::stream<as::ip::tcp::socket>,
  536. strand
  537. >
  538. >
  539. >
  540. >
  541. make_tls_async_client(Ioc& ioc, std::string host, std::string port, protocol_version version);
  542. /**
  543. * @brief Create tls async_client without strand.
  544. * @param ioc io_context object.
  545. * @param host hostname
  546. * @param port port number
  547. * @return async_client object
  548. */
  549. template <typename Ioc>
  550. friend std::shared_ptr<
  551. callable_overlay<
  552. async_client<
  553. tcp_endpoint<
  554. tls::stream<as::ip::tcp::socket>,
  555. null_strand
  556. >
  557. >
  558. >
  559. >
  560. make_tls_async_client_no_strand(Ioc& ioc, std::string host, std::string port, protocol_version version);
  561. #if defined(MQTT_USE_WS)
  562. /**
  563. * @brief Create no tls websocket async_client with strand.
  564. * @param ioc io_context object.
  565. * @param host hostname
  566. * @param port port number
  567. * @param path path string
  568. * @return async_client object.
  569. * strand is controlled by ws_endpoint, not endpoint, so async_client has null_strand template argument.
  570. */
  571. template <typename Ioc>
  572. friend std::shared_ptr<
  573. callable_overlay<
  574. async_client<
  575. ws_endpoint<
  576. tls::stream<as::ip::tcp::socket>,
  577. strand
  578. >
  579. >
  580. >
  581. >
  582. make_tls_async_client_ws(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version);
  583. /**
  584. * @brief Create no tls websocket async_client without strand.
  585. * @param ioc io_context object.
  586. * @param host hostname
  587. * @param port port number
  588. * @param path path string
  589. * @return async_client object
  590. */
  591. template <typename Ioc>
  592. friend std::shared_ptr<
  593. callable_overlay<
  594. async_client<
  595. ws_endpoint<
  596. tls::stream<as::ip::tcp::socket>,
  597. null_strand
  598. >
  599. >
  600. >
  601. >
  602. make_tls_async_client_no_strand_ws(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version);
  603. #endif // defined(MQTT_USE_WS)
  604. #endif // defined(MQTT_USE_TLS)
  605. /**
  606. * @brief Create no tls async_client with strand.
  607. * @param ioc io_context object.
  608. * @param host hostname
  609. * @param port port number
  610. * @return async_client object
  611. */
  612. template <typename Ioc>
  613. friend std::shared_ptr<
  614. callable_overlay<
  615. async_client<
  616. tcp_endpoint<
  617. as::ip::tcp::socket,
  618. strand
  619. >,
  620. 4
  621. >
  622. >
  623. >
  624. make_async_client_32(Ioc& ioc, std::string host, std::string port, protocol_version version);
  625. /**
  626. * @brief Create no tls async_client without strand.
  627. * @param ioc io_context object.
  628. * @param host hostname
  629. * @param port port number
  630. * @return async_client object
  631. */
  632. template <typename Ioc>
  633. friend std::shared_ptr<
  634. callable_overlay<
  635. async_client<
  636. tcp_endpoint<
  637. as::ip::tcp::socket,
  638. null_strand
  639. >,
  640. 4
  641. >
  642. >
  643. >
  644. make_async_client_no_strand_32(Ioc& ioc, std::string host, std::string port, protocol_version version);
  645. #if defined(MQTT_USE_WS)
  646. /**
  647. * @brief Create no tls websocket async_client with strand.
  648. * @param ioc io_context object.
  649. * @param host hostname
  650. * @param port port number
  651. * @param path path string
  652. * @return async_client object.
  653. * strand is controlled by ws_endpoint, not endpoint, so async_client has null_strand template argument.
  654. */
  655. template <typename Ioc>
  656. friend std::shared_ptr<
  657. callable_overlay<
  658. async_client<
  659. ws_endpoint<
  660. as::ip::tcp::socket,
  661. strand
  662. >,
  663. 4
  664. >
  665. >
  666. >
  667. make_async_client_ws_32(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version);
  668. /**
  669. * @brief Create no tls websocket async_client without strand.
  670. * @param ioc io_context object.
  671. * @param host hostname
  672. * @param port port number
  673. * @param path path string
  674. * @return async_client object
  675. */
  676. template <typename Ioc>
  677. friend std::shared_ptr<
  678. callable_overlay<
  679. async_client<
  680. ws_endpoint<
  681. as::ip::tcp::socket,
  682. null_strand
  683. >,
  684. 4
  685. >
  686. >
  687. >
  688. make_async_client_no_strand_ws_32(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version);
  689. #endif // defined(MQTT_USE_WS)
  690. #if defined(MQTT_USE_TLS)
  691. /**
  692. * @brief Create tls async_client with strand.
  693. * @param ioc io_context object.
  694. * @param host hostname
  695. * @param port port number
  696. * @return async_client object
  697. */
  698. template <typename Ioc>
  699. friend std::shared_ptr<
  700. callable_overlay<
  701. async_client<
  702. tcp_endpoint<
  703. tls::stream<as::ip::tcp::socket>,
  704. strand
  705. >,
  706. 4
  707. >
  708. >
  709. >
  710. make_tls_async_client_32(Ioc& ioc, std::string host, std::string port, protocol_version version);
  711. /**
  712. * @brief Create tls async_client without strand.
  713. * @param ioc io_context object.
  714. * @param host hostname
  715. * @param port port number
  716. * @return async_client object
  717. */
  718. template <typename Ioc>
  719. friend std::shared_ptr<
  720. callable_overlay<
  721. async_client<
  722. tcp_endpoint<
  723. tls::stream<as::ip::tcp::socket>,
  724. null_strand
  725. >,
  726. 4
  727. >
  728. >
  729. >
  730. make_tls_async_client_no_strand_32(Ioc& ioc, std::string host, std::string port, protocol_version version);
  731. #if defined(MQTT_USE_WS)
  732. /**
  733. * @brief Create no tls websocket async_client with strand.
  734. * @param ioc io_context object.
  735. * @param host hostname
  736. * @param port port number
  737. * @param path path string
  738. * @return async_client object.
  739. * strand is controlled by ws_endpoint, not endpoint, so async_client has null_strand template argument.
  740. */
  741. template <typename Ioc>
  742. friend std::shared_ptr<
  743. callable_overlay<
  744. async_client<
  745. ws_endpoint<
  746. tls::stream<as::ip::tcp::socket>,
  747. strand
  748. >,
  749. 4
  750. >
  751. >
  752. >
  753. make_tls_async_client_ws_32(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version);
  754. /**
  755. * @brief Create no tls websocket async_client without strand.
  756. * @param ioc io_context object.
  757. * @param host hostname
  758. * @param port port number
  759. * @param path path string
  760. * @return async_client object
  761. */
  762. template <typename Ioc>
  763. friend std::shared_ptr<
  764. callable_overlay<
  765. async_client<
  766. ws_endpoint<
  767. tls::stream<as::ip::tcp::socket>,
  768. null_strand
  769. >,
  770. 4
  771. >
  772. >
  773. >
  774. make_tls_async_client_no_strand_ws_32(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version);
  775. #endif // defined(MQTT_USE_WS)
  776. #endif // defined(MQTT_USE_TLS)
  777. /**
  778. * @brief Set auto publish response mode.
  779. * @param b set value
  780. * @param async auto publish response send asynchronous
  781. *
  782. * When set auto publish response mode to true, puback, pubrec, pubrel,and pub comp automatically send.<BR>
  783. */
  784. void set_auto_pub_response(bool b = true) {
  785. base::set_auto_pub_response(b);
  786. }
  787. void connect() = delete;
  788. void disconnect() = delete;
  789. void force_disconnect() = delete;
  790. void publish() = delete;
  791. void subscribe() = delete;
  792. void unsubscribe() = delete;
  793. void pingresp() = delete;
  794. void connack() = delete;
  795. void puback() = delete;
  796. void pubrec() = delete;
  797. void pubrel() = delete;
  798. void pubcomp() = delete;
  799. void suback() = delete;
  800. void unsuback() = delete;
  801. protected:
  802. // Ensure that only code that knows the *exact* type of an object
  803. // inheriting from this abstract base class can destruct it.
  804. // This avoids issues of the destructor not triggering destruction
  805. // of derived classes, and any member variables contained in them.
  806. // Note: Not virtual to avoid need for a vtable when possible.
  807. ~async_client() = default;
  808. async_client(
  809. as::io_context& ioc,
  810. std::string host,
  811. std::string port,
  812. #if defined(MQTT_USE_WS)
  813. std::string path = "/",
  814. #endif // defined(MQTT_USE_WS)
  815. protocol_version version = protocol_version::v3_1_1
  816. ):base(ioc,
  817. force_move(host),
  818. force_move(port),
  819. #if defined(MQTT_USE_WS)
  820. force_move(path),
  821. #endif // defined(MQTT_USE_WS)
  822. version,
  823. true
  824. ) {
  825. set_auto_pub_response();
  826. }
  827. };
  828. template <typename Ioc>
  829. inline std::shared_ptr<
  830. callable_overlay<
  831. async_client<
  832. tcp_endpoint<
  833. as::ip::tcp::socket,
  834. strand
  835. >
  836. >
  837. >
  838. >
  839. make_async_client(Ioc& ioc, std::string host, std::string port, protocol_version version) {
  840. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  841. using async_client_t = async_client<
  842. tcp_endpoint<
  843. as::ip::tcp::socket,
  844. strand
  845. >
  846. >;
  847. return std::make_shared<callable_overlay<async_client_t>>(
  848. async_client_t::constructor_access(),
  849. ioc,
  850. force_move(host),
  851. force_move(port),
  852. #if defined(MQTT_USE_WS)
  853. "/",
  854. #endif // defined(MQTT_USE_WS)
  855. version
  856. );
  857. }
  858. template <typename Ioc>
  859. inline std::shared_ptr<
  860. callable_overlay<
  861. async_client<
  862. tcp_endpoint<
  863. as::ip::tcp::socket,
  864. strand
  865. >
  866. >
  867. >
  868. >
  869. make_async_client(Ioc& ioc, std::string host, std::uint16_t port, protocol_version version) {
  870. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  871. return make_async_client(
  872. ioc,
  873. force_move(host),
  874. std::to_string(port),
  875. version
  876. );
  877. }
  878. template <typename Ioc>
  879. inline std::shared_ptr<
  880. callable_overlay<
  881. async_client<
  882. tcp_endpoint<
  883. as::ip::tcp::socket,
  884. null_strand
  885. >
  886. >
  887. >
  888. >
  889. make_async_client_no_strand(Ioc& ioc, std::string host, std::string port, protocol_version version) {
  890. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  891. using async_client_t = async_client<
  892. tcp_endpoint<
  893. as::ip::tcp::socket,
  894. null_strand
  895. >
  896. >;
  897. return std::make_shared<callable_overlay<async_client_t>>(
  898. async_client_t::constructor_access(),
  899. ioc,
  900. force_move(host),
  901. force_move(port),
  902. #if defined(MQTT_USE_WS)
  903. "/",
  904. #endif // defined(MQTT_USE_WS)
  905. version
  906. );
  907. }
  908. template <typename Ioc>
  909. inline std::shared_ptr<
  910. callable_overlay<
  911. async_client<
  912. tcp_endpoint<
  913. as::ip::tcp::socket,
  914. null_strand
  915. >
  916. >
  917. >
  918. >
  919. make_async_client_no_strand(Ioc& ioc, std::string host, std::uint16_t port, protocol_version version) {
  920. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  921. return make_async_client_no_strand(
  922. ioc,
  923. force_move(host),
  924. std::to_string(port),
  925. version
  926. );
  927. }
  928. #if defined(MQTT_USE_WS)
  929. template <typename Ioc>
  930. inline std::shared_ptr<
  931. callable_overlay<
  932. async_client<
  933. ws_endpoint<
  934. as::ip::tcp::socket,
  935. strand
  936. >
  937. >
  938. >
  939. >
  940. make_async_client_ws(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version) {
  941. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  942. using async_client_t = async_client<
  943. ws_endpoint<
  944. as::ip::tcp::socket,
  945. strand
  946. >
  947. >;
  948. return std::make_shared<callable_overlay<async_client_t>>(
  949. async_client_t::constructor_access(),
  950. ioc,
  951. force_move(host),
  952. force_move(port),
  953. force_move(path),
  954. version
  955. );
  956. }
  957. template <typename Ioc>
  958. inline std::shared_ptr<
  959. callable_overlay<
  960. async_client<
  961. ws_endpoint<
  962. as::ip::tcp::socket,
  963. strand
  964. >
  965. >
  966. >
  967. >
  968. make_async_client_ws(Ioc& ioc, std::string host, std::uint16_t port, std::string path, protocol_version version) {
  969. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  970. return make_async_client_ws(
  971. ioc,
  972. force_move(host),
  973. std::to_string(port),
  974. force_move(path),
  975. version
  976. );
  977. }
  978. template <typename Ioc>
  979. inline std::shared_ptr<
  980. callable_overlay<
  981. async_client<
  982. ws_endpoint<
  983. as::ip::tcp::socket,
  984. null_strand
  985. >
  986. >
  987. >
  988. >
  989. make_async_client_no_strand_ws(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version) {
  990. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  991. using async_client_t = async_client<
  992. ws_endpoint<
  993. as::ip::tcp::socket,
  994. null_strand
  995. >
  996. >;
  997. return std::make_shared<callable_overlay<async_client_t>>(
  998. async_client_t::constructor_access(),
  999. ioc,
  1000. force_move(host),
  1001. force_move(port),
  1002. force_move(path),
  1003. version
  1004. );
  1005. }
  1006. template <typename Ioc>
  1007. inline std::shared_ptr<
  1008. callable_overlay<
  1009. async_client<
  1010. ws_endpoint<
  1011. as::ip::tcp::socket,
  1012. null_strand
  1013. >
  1014. >
  1015. >
  1016. >
  1017. make_async_client_no_strand_ws(Ioc& ioc, std::string host, std::uint16_t port, std::string path, protocol_version version) {
  1018. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1019. return make_async_client_no_strand_ws(
  1020. ioc,
  1021. force_move(host),
  1022. std::to_string(port),
  1023. force_move(path),
  1024. version
  1025. );
  1026. }
  1027. #endif // defined(MQTT_USE_WS)
  1028. #if defined(MQTT_USE_TLS)
  1029. template <typename Ioc>
  1030. inline std::shared_ptr<
  1031. callable_overlay<
  1032. async_client<
  1033. tcp_endpoint<
  1034. tls::stream<as::ip::tcp::socket>,
  1035. strand
  1036. >
  1037. >
  1038. >
  1039. >
  1040. make_tls_async_client(Ioc& ioc, std::string host, std::string port, protocol_version version) {
  1041. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1042. using async_client_t = async_client<
  1043. tcp_endpoint<
  1044. tls::stream<as::ip::tcp::socket>,
  1045. strand
  1046. >
  1047. >;
  1048. return std::make_shared<callable_overlay<async_client_t>>(
  1049. async_client_t::constructor_access(),
  1050. ioc,
  1051. force_move(host),
  1052. force_move(port),
  1053. #if defined(MQTT_USE_WS)
  1054. "/",
  1055. #endif // defined(MQTT_USE_WS)
  1056. version
  1057. );
  1058. }
  1059. template <typename Ioc>
  1060. inline std::shared_ptr<
  1061. callable_overlay<
  1062. async_client<
  1063. tcp_endpoint<
  1064. tls::stream<as::ip::tcp::socket>,
  1065. strand
  1066. >
  1067. >
  1068. >
  1069. >
  1070. make_tls_async_client(Ioc& ioc, std::string host, std::uint16_t port, protocol_version version) {
  1071. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1072. return make_tls_async_client(
  1073. ioc,
  1074. force_move(host),
  1075. std::to_string(port),
  1076. version
  1077. );
  1078. }
  1079. template <typename Ioc>
  1080. inline std::shared_ptr<
  1081. callable_overlay<
  1082. async_client<
  1083. tcp_endpoint<
  1084. tls::stream<as::ip::tcp::socket>,
  1085. null_strand
  1086. >
  1087. >
  1088. >
  1089. >
  1090. make_tls_async_client_no_strand(Ioc& ioc, std::string host, std::string port, protocol_version version) {
  1091. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1092. using async_client_t = async_client<
  1093. tcp_endpoint<
  1094. tls::stream<as::ip::tcp::socket>,
  1095. null_strand
  1096. >
  1097. >;
  1098. return std::make_shared<callable_overlay<async_client_t>>(
  1099. async_client_t::constructor_access(),
  1100. ioc,
  1101. force_move(host),
  1102. force_move(port),
  1103. #if defined(MQTT_USE_WS)
  1104. "/",
  1105. #endif // defined(MQTT_USE_WS)
  1106. version
  1107. );
  1108. }
  1109. template <typename Ioc>
  1110. inline std::shared_ptr<
  1111. callable_overlay<
  1112. async_client<
  1113. tcp_endpoint<
  1114. tls::stream<as::ip::tcp::socket>,
  1115. null_strand
  1116. >
  1117. >
  1118. >
  1119. >
  1120. make_tls_async_client_no_strand(Ioc& ioc, std::string host, std::uint16_t port, protocol_version version) {
  1121. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1122. return make_tls_async_client_no_strand(
  1123. ioc,
  1124. force_move(host),
  1125. std::to_string(port),
  1126. version
  1127. );
  1128. }
  1129. #if defined(MQTT_USE_WS)
  1130. template <typename Ioc>
  1131. inline std::shared_ptr<
  1132. callable_overlay<
  1133. async_client<
  1134. ws_endpoint<
  1135. tls::stream<as::ip::tcp::socket>,
  1136. strand
  1137. >
  1138. >
  1139. >
  1140. >
  1141. make_tls_async_client_ws(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version) {
  1142. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1143. using async_client_t = async_client<
  1144. ws_endpoint<
  1145. tls::stream<as::ip::tcp::socket>,
  1146. strand
  1147. >
  1148. >;
  1149. return std::make_shared<callable_overlay<async_client_t>>(
  1150. async_client_t::constructor_access(),
  1151. ioc,
  1152. force_move(host),
  1153. force_move(port),
  1154. force_move(path),
  1155. version
  1156. );
  1157. }
  1158. template <typename Ioc>
  1159. inline std::shared_ptr<
  1160. callable_overlay<
  1161. async_client<
  1162. ws_endpoint<
  1163. tls::stream<as::ip::tcp::socket>,
  1164. strand
  1165. >
  1166. >
  1167. >
  1168. >
  1169. make_tls_async_client_ws(Ioc& ioc, std::string host, std::uint16_t port, std::string path, protocol_version version) {
  1170. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1171. return make_tls_async_client_ws(
  1172. ioc,
  1173. force_move(host),
  1174. std::to_string(port),
  1175. force_move(path),
  1176. version
  1177. );
  1178. }
  1179. template <typename Ioc>
  1180. inline std::shared_ptr<
  1181. callable_overlay<
  1182. async_client<
  1183. ws_endpoint<
  1184. tls::stream<as::ip::tcp::socket>,
  1185. null_strand
  1186. >
  1187. >
  1188. >
  1189. >
  1190. make_tls_async_client_no_strand_ws(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version) {
  1191. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1192. using async_client_t = async_client<
  1193. ws_endpoint<
  1194. tls::stream<as::ip::tcp::socket>,
  1195. null_strand
  1196. >
  1197. >;
  1198. return std::make_shared<callable_overlay<async_client_t>>(
  1199. async_client_t::constructor_access(),
  1200. ioc,
  1201. force_move(host),
  1202. force_move(port),
  1203. force_move(path),
  1204. version
  1205. );
  1206. }
  1207. template <typename Ioc>
  1208. inline std::shared_ptr<
  1209. callable_overlay<
  1210. async_client<
  1211. ws_endpoint<
  1212. tls::stream<as::ip::tcp::socket>,
  1213. null_strand
  1214. >
  1215. >
  1216. >
  1217. >
  1218. make_tls_async_client_no_strand_ws(Ioc& ioc, std::string host, std::uint16_t port, std::string path, protocol_version version) {
  1219. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1220. return make_tls_async_client_no_strand_ws(
  1221. ioc,
  1222. force_move(host),
  1223. std::to_string(port),
  1224. force_move(path),
  1225. version
  1226. );
  1227. }
  1228. #endif // defined(MQTT_USE_WS)
  1229. #endif // defined(MQTT_USE_TLS)
  1230. // 32bit Packet Id (experimental)
  1231. template <typename Ioc>
  1232. inline std::shared_ptr<
  1233. callable_overlay<
  1234. async_client<
  1235. tcp_endpoint<
  1236. as::ip::tcp::socket,
  1237. strand
  1238. >,
  1239. 4
  1240. >
  1241. >
  1242. >
  1243. make_async_client_32(Ioc& ioc, std::string host, std::string port, protocol_version version) {
  1244. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1245. using async_client_t = async_client<
  1246. tcp_endpoint<
  1247. as::ip::tcp::socket,
  1248. strand
  1249. >,
  1250. 4
  1251. >;
  1252. return std::make_shared<callable_overlay<async_client_t>>(
  1253. async_client_t::constructor_access(),
  1254. ioc,
  1255. force_move(host),
  1256. force_move(port),
  1257. #if defined(MQTT_USE_WS)
  1258. "/",
  1259. #endif // defined(MQTT_USE_WS)
  1260. version
  1261. );
  1262. }
  1263. template <typename Ioc>
  1264. inline std::shared_ptr<
  1265. callable_overlay<
  1266. async_client<
  1267. tcp_endpoint<
  1268. as::ip::tcp::socket,
  1269. strand
  1270. >,
  1271. 4
  1272. >
  1273. >
  1274. >
  1275. make_async_client_32(Ioc& ioc, std::string host, std::uint16_t port, protocol_version version) {
  1276. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1277. return make_async_client_32(
  1278. ioc,
  1279. force_move(host),
  1280. std::to_string(port),
  1281. version
  1282. );
  1283. }
  1284. template <typename Ioc>
  1285. inline std::shared_ptr<
  1286. callable_overlay<
  1287. async_client<
  1288. tcp_endpoint<
  1289. as::ip::tcp::socket,
  1290. null_strand
  1291. >,
  1292. 4
  1293. >
  1294. >
  1295. >
  1296. make_async_client_no_strand_32(Ioc& ioc, std::string host, std::string port, protocol_version version) {
  1297. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1298. using async_client_t = async_client<
  1299. tcp_endpoint<
  1300. as::ip::tcp::socket,
  1301. null_strand
  1302. >,
  1303. 4
  1304. >;
  1305. return std::make_shared<callable_overlay<async_client_t>>(
  1306. async_client_t::constructor_access(),
  1307. ioc,
  1308. force_move(host),
  1309. force_move(port),
  1310. #if defined(MQTT_USE_WS)
  1311. "/",
  1312. #endif // defined(MQTT_USE_WS)
  1313. version
  1314. );
  1315. }
  1316. template <typename Ioc>
  1317. inline std::shared_ptr<
  1318. callable_overlay<
  1319. async_client<
  1320. tcp_endpoint<
  1321. as::ip::tcp::socket,
  1322. null_strand
  1323. >,
  1324. 4
  1325. >
  1326. >
  1327. >
  1328. make_async_client_no_strand_32(Ioc& ioc, std::string host, std::uint16_t port, protocol_version version) {
  1329. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1330. return make_async_client_no_strand_32(
  1331. ioc,
  1332. force_move(host),
  1333. std::to_string(port),
  1334. version
  1335. );
  1336. }
  1337. #if defined(MQTT_USE_WS)
  1338. template <typename Ioc>
  1339. inline std::shared_ptr<
  1340. callable_overlay<
  1341. async_client<
  1342. ws_endpoint<
  1343. as::ip::tcp::socket,
  1344. strand
  1345. >,
  1346. 4
  1347. >
  1348. >
  1349. >
  1350. make_async_client_ws_32(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version) {
  1351. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1352. using async_client_t = async_client<
  1353. ws_endpoint<
  1354. as::ip::tcp::socket,
  1355. strand
  1356. >,
  1357. 4
  1358. >;
  1359. return std::make_shared<callable_overlay<async_client_t>>(
  1360. async_client_t::constructor_access(),
  1361. ioc,
  1362. force_move(host),
  1363. force_move(port),
  1364. force_move(path),
  1365. version
  1366. );
  1367. }
  1368. template <typename Ioc>
  1369. inline std::shared_ptr<
  1370. callable_overlay<
  1371. async_client<
  1372. ws_endpoint<
  1373. as::ip::tcp::socket,
  1374. strand
  1375. >,
  1376. 4
  1377. >
  1378. >
  1379. >
  1380. make_async_client_ws_32(Ioc& ioc, std::string host, std::uint16_t port, std::string path, protocol_version version) {
  1381. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1382. return make_async_client_ws_32(
  1383. ioc,
  1384. force_move(host),
  1385. std::to_string(port),
  1386. force_move(path),
  1387. version
  1388. );
  1389. }
  1390. template <typename Ioc>
  1391. inline std::shared_ptr<
  1392. callable_overlay<
  1393. async_client<
  1394. ws_endpoint<
  1395. as::ip::tcp::socket,
  1396. null_strand
  1397. >,
  1398. 4
  1399. >
  1400. >
  1401. >
  1402. make_async_client_no_strand_ws_32(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version) {
  1403. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1404. using async_client_t = async_client<
  1405. ws_endpoint<
  1406. as::ip::tcp::socket,
  1407. null_strand
  1408. >,
  1409. 4
  1410. >;
  1411. return std::make_shared<callable_overlay<async_client_t>>(
  1412. async_client_t::constructor_access(),
  1413. ioc,
  1414. force_move(host),
  1415. force_move(port),
  1416. force_move(path),
  1417. version
  1418. );
  1419. }
  1420. template <typename Ioc>
  1421. inline std::shared_ptr<
  1422. callable_overlay<
  1423. async_client<
  1424. ws_endpoint<
  1425. as::ip::tcp::socket,
  1426. null_strand
  1427. >,
  1428. 4
  1429. >
  1430. >
  1431. >
  1432. make_async_client_no_strand_ws_32(Ioc& ioc, std::string host, std::uint16_t port, std::string path, protocol_version version) {
  1433. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1434. return make_async_client_no_strand_ws_32(
  1435. ioc,
  1436. force_move(host),
  1437. std::to_string(port),
  1438. force_move(path),
  1439. version
  1440. );
  1441. }
  1442. #endif // defined(MQTT_USE_WS)
  1443. #if defined(MQTT_USE_TLS)
  1444. template <typename Ioc>
  1445. inline std::shared_ptr<
  1446. callable_overlay<
  1447. async_client<
  1448. tcp_endpoint<
  1449. tls::stream<as::ip::tcp::socket>,
  1450. strand
  1451. >,
  1452. 4
  1453. >
  1454. >
  1455. >
  1456. make_tls_async_client_32(Ioc& ioc, std::string host, std::string port, protocol_version version) {
  1457. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1458. using async_client_t = async_client<
  1459. tcp_endpoint<
  1460. tls::stream<as::ip::tcp::socket>,
  1461. strand
  1462. >,
  1463. 4
  1464. >;
  1465. return std::make_shared<callable_overlay<async_client_t>>(
  1466. async_client_t::constructor_access(),
  1467. ioc,
  1468. force_move(host),
  1469. force_move(port),
  1470. #if defined(MQTT_USE_WS)
  1471. "/",
  1472. #endif // defined(MQTT_USE_WS)
  1473. version
  1474. );
  1475. }
  1476. template <typename Ioc>
  1477. inline std::shared_ptr<
  1478. callable_overlay<
  1479. async_client<
  1480. tcp_endpoint<
  1481. tls::stream<as::ip::tcp::socket>,
  1482. strand
  1483. >,
  1484. 4
  1485. >
  1486. >
  1487. >
  1488. make_tls_async_client_32(Ioc& ioc, std::string host, std::uint16_t port, protocol_version version) {
  1489. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1490. return make_tls_async_client_32(
  1491. ioc,
  1492. force_move(host),
  1493. std::to_string(port),
  1494. version
  1495. );
  1496. }
  1497. template <typename Ioc>
  1498. inline std::shared_ptr<
  1499. callable_overlay<
  1500. async_client<
  1501. tcp_endpoint<
  1502. tls::stream<as::ip::tcp::socket>,
  1503. null_strand
  1504. >,
  1505. 4
  1506. >
  1507. >
  1508. >
  1509. make_tls_async_client_no_strand_32(Ioc& ioc, std::string host, std::string port, protocol_version version) {
  1510. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1511. using async_client_t = async_client<
  1512. tcp_endpoint<
  1513. tls::stream<as::ip::tcp::socket>,
  1514. null_strand
  1515. >,
  1516. 4
  1517. >;
  1518. return std::make_shared<callable_overlay<async_client_t>>(
  1519. async_client_t::constructor_access(),
  1520. ioc,
  1521. force_move(host),
  1522. force_move(port),
  1523. #if defined(MQTT_USE_WS)
  1524. "/",
  1525. #endif // defined(MQTT_USE_WS)
  1526. version
  1527. );
  1528. }
  1529. template <typename Ioc>
  1530. inline std::shared_ptr<
  1531. callable_overlay<
  1532. async_client<
  1533. tcp_endpoint<
  1534. tls::stream<as::ip::tcp::socket>,
  1535. null_strand
  1536. >,
  1537. 4
  1538. >
  1539. >
  1540. >
  1541. make_tls_async_client_no_strand_32(Ioc& ioc, std::string host, std::uint16_t port, protocol_version version) {
  1542. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1543. return make_tls_async_client_no_strand_32(
  1544. ioc,
  1545. force_move(host),
  1546. std::to_string(port),
  1547. version
  1548. );
  1549. }
  1550. #if defined(MQTT_USE_WS)
  1551. template <typename Ioc>
  1552. inline std::shared_ptr<
  1553. callable_overlay<
  1554. async_client<
  1555. ws_endpoint<
  1556. tls::stream<as::ip::tcp::socket>,
  1557. strand
  1558. >,
  1559. 4
  1560. >
  1561. >
  1562. >
  1563. make_tls_async_client_ws_32(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version) {
  1564. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1565. using async_client_t = async_client<
  1566. ws_endpoint<
  1567. tls::stream<as::ip::tcp::socket>,
  1568. strand
  1569. >,
  1570. 4
  1571. >;
  1572. return std::make_shared<callable_overlay<async_client_t>>(
  1573. async_client_t::constructor_access(),
  1574. ioc,
  1575. force_move(host),
  1576. force_move(port),
  1577. force_move(path),
  1578. version
  1579. );
  1580. }
  1581. template <typename Ioc>
  1582. inline std::shared_ptr<
  1583. callable_overlay<
  1584. async_client<
  1585. ws_endpoint<
  1586. tls::stream<as::ip::tcp::socket>,
  1587. strand
  1588. >,
  1589. 4
  1590. >
  1591. >
  1592. >
  1593. make_tls_async_client_ws_32(Ioc& ioc, std::string host, std::uint16_t port, std::string path, protocol_version version) {
  1594. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1595. return make_tls_async_client_ws_32(
  1596. ioc,
  1597. force_move(host),
  1598. std::to_string(port),
  1599. force_move(path),
  1600. version
  1601. );
  1602. }
  1603. template <typename Ioc>
  1604. inline std::shared_ptr<
  1605. callable_overlay<
  1606. async_client<
  1607. ws_endpoint<
  1608. tls::stream<as::ip::tcp::socket>,
  1609. null_strand
  1610. >,
  1611. 4
  1612. >
  1613. >
  1614. >
  1615. make_tls_async_client_no_strand_ws_32(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version) {
  1616. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1617. using async_client_t = async_client<
  1618. ws_endpoint<
  1619. tls::stream<as::ip::tcp::socket>,
  1620. null_strand
  1621. >,
  1622. 4
  1623. >;
  1624. return std::make_shared<callable_overlay<async_client_t>>(
  1625. async_client_t::constructor_access(),
  1626. ioc,
  1627. force_move(host),
  1628. force_move(port),
  1629. force_move(path),
  1630. version
  1631. );
  1632. }
  1633. template <typename Ioc>
  1634. inline std::shared_ptr<
  1635. callable_overlay<
  1636. async_client<
  1637. ws_endpoint<
  1638. tls::stream<as::ip::tcp::socket>,
  1639. null_strand
  1640. >,
  1641. 4
  1642. >
  1643. >
  1644. >
  1645. make_tls_async_client_no_strand_ws_32(Ioc& ioc, std::string host, std::uint16_t port, std::string path, protocol_version version) {
  1646. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1647. return make_tls_async_client_no_strand_ws_32(
  1648. ioc,
  1649. force_move(host),
  1650. std::to_string(port),
  1651. force_move(path),
  1652. version
  1653. );
  1654. }
  1655. #endif // defined(MQTT_USE_WS)
  1656. #endif // defined(MQTT_USE_TLS)
  1657. } // namespace MQTT_NS
  1658. #endif // MQTT_ASYNC_CLIENT_HPP