sync_client.hpp 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779
  1. // Copyright Takatoshi Kondo 2019
  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_SYNC_CLIENT_HPP)
  7. #define MQTT_SYNC_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 sync_client;
  15. template <typename Ioc>
  16. std::shared_ptr<
  17. callable_overlay<
  18. sync_client<
  19. tcp_endpoint<
  20. as::ip::tcp::socket,
  21. strand
  22. >
  23. >
  24. >
  25. >
  26. make_sync_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. sync_client<
  31. tcp_endpoint<
  32. as::ip::tcp::socket,
  33. strand
  34. >
  35. >
  36. >
  37. >
  38. make_sync_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. sync_client<
  43. tcp_endpoint<
  44. as::ip::tcp::socket,
  45. null_strand
  46. >
  47. >
  48. >
  49. >
  50. make_sync_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. sync_client<
  55. tcp_endpoint<
  56. as::ip::tcp::socket,
  57. null_strand
  58. >
  59. >
  60. >
  61. >
  62. make_sync_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. sync_client<
  68. ws_endpoint<
  69. as::ip::tcp::socket,
  70. strand
  71. >
  72. >
  73. >
  74. >
  75. make_sync_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. sync_client<
  80. ws_endpoint<
  81. as::ip::tcp::socket,
  82. strand
  83. >
  84. >
  85. >
  86. >
  87. make_sync_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. sync_client<
  92. ws_endpoint<
  93. as::ip::tcp::socket,
  94. null_strand
  95. >
  96. >
  97. >
  98. >
  99. make_sync_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. sync_client<
  104. ws_endpoint<
  105. as::ip::tcp::socket,
  106. null_strand
  107. >
  108. >
  109. >
  110. >
  111. make_sync_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. sync_client<
  118. tcp_endpoint<
  119. tls::stream<as::ip::tcp::socket>,
  120. strand
  121. >
  122. >
  123. >
  124. >
  125. make_tls_sync_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. sync_client<
  130. tcp_endpoint<
  131. tls::stream<as::ip::tcp::socket>,
  132. strand
  133. >
  134. >
  135. >
  136. >
  137. make_tls_sync_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. sync_client<
  142. tcp_endpoint<
  143. tls::stream<as::ip::tcp::socket>,
  144. null_strand
  145. >
  146. >
  147. >
  148. >
  149. make_tls_sync_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. sync_client<
  154. tcp_endpoint<
  155. tls::stream<as::ip::tcp::socket>,
  156. null_strand
  157. >
  158. >
  159. >
  160. >
  161. make_tls_sync_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. sync_client<
  167. ws_endpoint<
  168. tls::stream<as::ip::tcp::socket>,
  169. strand
  170. >
  171. >
  172. >
  173. >
  174. make_tls_sync_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. sync_client<
  179. ws_endpoint<
  180. tls::stream<as::ip::tcp::socket>,
  181. strand
  182. >
  183. >
  184. >
  185. >
  186. make_tls_sync_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. sync_client<
  191. ws_endpoint<
  192. tls::stream<as::ip::tcp::socket>,
  193. null_strand
  194. >
  195. >
  196. >
  197. >
  198. make_tls_sync_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. sync_client<
  203. ws_endpoint<
  204. tls::stream<as::ip::tcp::socket>,
  205. null_strand
  206. >
  207. >
  208. >
  209. >
  210. make_tls_sync_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. sync_client<
  218. tcp_endpoint<
  219. as::ip::tcp::socket,
  220. strand
  221. >,
  222. 4
  223. >
  224. >
  225. >
  226. make_sync_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. sync_client<
  231. tcp_endpoint<
  232. as::ip::tcp::socket,
  233. strand
  234. >,
  235. 4
  236. >
  237. >
  238. >
  239. make_sync_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. sync_client<
  244. tcp_endpoint<
  245. as::ip::tcp::socket,
  246. null_strand
  247. >,
  248. 4
  249. >
  250. >
  251. >
  252. make_sync_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. sync_client<
  257. tcp_endpoint<
  258. as::ip::tcp::socket,
  259. null_strand
  260. >,
  261. 4
  262. >
  263. >
  264. >
  265. make_sync_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. sync_client<
  271. ws_endpoint<
  272. as::ip::tcp::socket,
  273. strand
  274. >,
  275. 4
  276. >
  277. >
  278. >
  279. make_sync_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. sync_client<
  284. ws_endpoint<
  285. as::ip::tcp::socket,
  286. strand
  287. >,
  288. 4
  289. >
  290. >
  291. >
  292. make_sync_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. sync_client<
  297. ws_endpoint<
  298. as::ip::tcp::socket,
  299. null_strand
  300. >,
  301. 4
  302. >
  303. >
  304. >
  305. make_sync_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. sync_client<
  310. ws_endpoint<
  311. as::ip::tcp::socket,
  312. null_strand
  313. >,
  314. 4
  315. >
  316. >
  317. >
  318. make_sync_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. sync_client<
  325. tcp_endpoint<
  326. tls::stream<as::ip::tcp::socket>,
  327. strand
  328. >,
  329. 4
  330. >
  331. >
  332. >
  333. make_tls_sync_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. sync_client<
  338. tcp_endpoint<
  339. tls::stream<as::ip::tcp::socket>,
  340. strand
  341. >,
  342. 4
  343. >
  344. >
  345. >
  346. make_tls_sync_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. sync_client<
  351. tcp_endpoint<
  352. tls::stream<as::ip::tcp::socket>,
  353. null_strand
  354. >,
  355. 4
  356. >
  357. >
  358. >
  359. make_tls_sync_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. sync_client<
  364. tcp_endpoint<
  365. tls::stream<as::ip::tcp::socket>,
  366. null_strand
  367. >,
  368. 4
  369. >
  370. >
  371. >
  372. make_tls_sync_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. sync_client<
  378. ws_endpoint<
  379. tls::stream<as::ip::tcp::socket>,
  380. strand
  381. >,
  382. 4
  383. >
  384. >
  385. >
  386. make_tls_sync_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. sync_client<
  391. ws_endpoint<
  392. tls::stream<as::ip::tcp::socket>,
  393. strand
  394. >,
  395. 4
  396. >
  397. >
  398. >
  399. make_tls_sync_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. sync_client<
  404. ws_endpoint<
  405. tls::stream<as::ip::tcp::socket>,
  406. null_strand
  407. >,
  408. 4
  409. >
  410. >
  411. >
  412. make_tls_sync_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. sync_client<
  417. ws_endpoint<
  418. tls::stream<as::ip::tcp::socket>,
  419. null_strand
  420. >,
  421. 4
  422. >
  423. >
  424. >
  425. make_tls_sync_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 sync_client : public client<Socket, PacketIdBytes> {
  430. using this_type = sync_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 sync_client(constructor_access, Args && ... args)
  439. : sync_client(std::forward<Args>(args)...)
  440. { }
  441. /**
  442. * @brief Create no tls sync_client with strand.
  443. * @param ioc io_context object.
  444. * @param host hostname
  445. * @param port port number
  446. * @return sync_client object
  447. */
  448. template <typename Ioc>
  449. friend std::shared_ptr<
  450. callable_overlay<
  451. sync_client<
  452. tcp_endpoint<
  453. as::ip::tcp::socket,
  454. strand
  455. >
  456. >
  457. >
  458. >
  459. make_sync_client(Ioc& ioc, std::string host, std::string port, protocol_version version);
  460. /**
  461. * @brief Create no tls sync_client without strand.
  462. * @param ioc io_context object.
  463. * @param host hostname
  464. * @param port port number
  465. * @return sync_client object
  466. */
  467. template <typename Ioc>
  468. friend std::shared_ptr<
  469. callable_overlay<
  470. sync_client<
  471. tcp_endpoint<
  472. as::ip::tcp::socket,
  473. null_strand
  474. >
  475. >
  476. >
  477. >
  478. make_sync_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 sync_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 sync_client object.
  487. * strand is controlled by ws_endpoint, not endpoint, so sync_client has null_strand template argument.
  488. */
  489. template <typename Ioc>
  490. friend std::shared_ptr<
  491. callable_overlay<
  492. sync_client<
  493. ws_endpoint<
  494. as::ip::tcp::socket,
  495. strand
  496. >
  497. >
  498. >
  499. >
  500. make_sync_client_ws(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version);
  501. /**
  502. * @brief Create no tls websocket sync_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 sync_client object
  508. */
  509. template <typename Ioc>
  510. friend std::shared_ptr<
  511. callable_overlay<
  512. sync_client<
  513. ws_endpoint<
  514. as::ip::tcp::socket,
  515. null_strand
  516. >
  517. >
  518. >
  519. >
  520. make_sync_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 sync_client with strand.
  525. * @param ioc io_context object.
  526. * @param host hostname
  527. * @param port port number
  528. * @return sync_client object
  529. */
  530. template <typename Ioc>
  531. friend std::shared_ptr<
  532. callable_overlay<
  533. sync_client<
  534. tcp_endpoint<
  535. tls::stream<as::ip::tcp::socket>,
  536. strand
  537. >
  538. >
  539. >
  540. >
  541. make_tls_sync_client(Ioc& ioc, std::string host, std::string port, protocol_version version);
  542. /**
  543. * @brief Create tls sync_client without strand.
  544. * @param ioc io_context object.
  545. * @param host hostname
  546. * @param port port number
  547. * @return sync_client object
  548. */
  549. template <typename Ioc>
  550. friend std::shared_ptr<
  551. callable_overlay<
  552. sync_client<
  553. tcp_endpoint<
  554. tls::stream<as::ip::tcp::socket>,
  555. null_strand
  556. >
  557. >
  558. >
  559. >
  560. make_tls_sync_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 sync_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 sync_client object.
  569. * strand is controlled by ws_endpoint, not endpoint, so sync_client has null_strand template argument.
  570. */
  571. template <typename Ioc>
  572. friend std::shared_ptr<
  573. callable_overlay<
  574. sync_client<
  575. ws_endpoint<
  576. tls::stream<as::ip::tcp::socket>,
  577. strand
  578. >
  579. >
  580. >
  581. >
  582. make_tls_sync_client_ws(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version);
  583. /**
  584. * @brief Create no tls websocket sync_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 sync_client object
  590. */
  591. template <typename Ioc>
  592. friend std::shared_ptr<
  593. callable_overlay<
  594. sync_client<
  595. ws_endpoint<
  596. tls::stream<as::ip::tcp::socket>,
  597. null_strand
  598. >
  599. >
  600. >
  601. >
  602. make_tls_sync_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 sync_client with strand.
  607. * @param ioc io_context object.
  608. * @param host hostname
  609. * @param port port number
  610. * @return sync_client object
  611. */
  612. template <typename Ioc>
  613. friend std::shared_ptr<
  614. callable_overlay<
  615. sync_client<
  616. tcp_endpoint<
  617. as::ip::tcp::socket,
  618. strand
  619. >,
  620. 4
  621. >
  622. >
  623. >
  624. make_sync_client_32(Ioc& ioc, std::string host, std::string port, protocol_version version);
  625. /**
  626. * @brief Create no tls sync_client without strand.
  627. * @param ioc io_context object.
  628. * @param host hostname
  629. * @param port port number
  630. * @return sync_client object
  631. */
  632. template <typename Ioc>
  633. friend std::shared_ptr<
  634. callable_overlay<
  635. sync_client<
  636. tcp_endpoint<
  637. as::ip::tcp::socket,
  638. null_strand
  639. >,
  640. 4
  641. >
  642. >
  643. >
  644. make_sync_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 sync_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 sync_client object.
  653. * strand is controlled by ws_endpoint, not endpoint, so sync_client has null_strand template argument.
  654. */
  655. template <typename Ioc>
  656. friend std::shared_ptr<
  657. callable_overlay<
  658. sync_client<
  659. ws_endpoint<
  660. as::ip::tcp::socket,
  661. strand
  662. >,
  663. 4
  664. >
  665. >
  666. >
  667. make_sync_client_ws_32(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version);
  668. /**
  669. * @brief Create no tls websocket sync_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 sync_client object
  675. */
  676. template <typename Ioc>
  677. friend std::shared_ptr<
  678. callable_overlay<
  679. sync_client<
  680. ws_endpoint<
  681. as::ip::tcp::socket,
  682. null_strand
  683. >,
  684. 4
  685. >
  686. >
  687. >
  688. make_sync_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 sync_client with strand.
  693. * @param ioc io_context object.
  694. * @param host hostname
  695. * @param port port number
  696. * @return sync_client object
  697. */
  698. template <typename Ioc>
  699. friend std::shared_ptr<
  700. callable_overlay<
  701. sync_client<
  702. tcp_endpoint<
  703. tls::stream<as::ip::tcp::socket>,
  704. strand
  705. >,
  706. 4
  707. >
  708. >
  709. >
  710. make_tls_sync_client_32(Ioc& ioc, std::string host, std::string port, protocol_version version);
  711. /**
  712. * @brief Create tls sync_client without strand.
  713. * @param ioc io_context object.
  714. * @param host hostname
  715. * @param port port number
  716. * @return sync_client object
  717. */
  718. template <typename Ioc>
  719. friend std::shared_ptr<
  720. callable_overlay<
  721. sync_client<
  722. tcp_endpoint<
  723. tls::stream<as::ip::tcp::socket>,
  724. null_strand
  725. >,
  726. 4
  727. >
  728. >
  729. >
  730. make_tls_sync_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 sync_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 sync_client object.
  739. * strand is controlled by ws_endpoint, not endpoint, so sync_client has null_strand template argument.
  740. */
  741. template <typename Ioc>
  742. friend std::shared_ptr<
  743. callable_overlay<
  744. sync_client<
  745. ws_endpoint<
  746. tls::stream<as::ip::tcp::socket>,
  747. strand
  748. >,
  749. 4
  750. >
  751. >
  752. >
  753. make_tls_sync_client_ws_32(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version);
  754. /**
  755. * @brief Create no tls websocket sync_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 sync_client object
  761. */
  762. template <typename Ioc>
  763. friend std::shared_ptr<
  764. callable_overlay<
  765. sync_client<
  766. ws_endpoint<
  767. tls::stream<as::ip::tcp::socket>,
  768. null_strand
  769. >,
  770. 4
  771. >
  772. >
  773. >
  774. make_tls_sync_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 sync auto publish ressponse send synchronous
  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 async_connect() = delete;
  788. void async_disconnect() = delete;
  789. void async_force_disconnect() = delete;
  790. void async_publish() = delete;
  791. void async_subscribe() = delete;
  792. void async_unsubscribe() = delete;
  793. void async_pingresp() = delete;
  794. void async_connack() = delete;
  795. void async_puback() = delete;
  796. void async_pubrec() = delete;
  797. void async_pubrel() = delete;
  798. void async_pubcomp() = delete;
  799. void async_suback() = delete;
  800. void async_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. ~sync_client() = default;
  808. sync_client(
  809. as::io_context& ioc,
  810. std::string host,
  811. std::string port
  812. #if defined(MQTT_USE_WS)
  813. ,
  814. std::string path = "/"
  815. #endif // defined(MQTT_USE_WS)
  816. ,
  817. protocol_version version = protocol_version::v3_1_1
  818. ):base(ioc, force_move(host), force_move(port)
  819. #if defined(MQTT_USE_WS)
  820. , force_move(path)
  821. #endif // defined(MQTT_USE_WS)
  822. ,
  823. version
  824. ) {
  825. set_auto_pub_response();
  826. }
  827. };
  828. template <typename Ioc>
  829. inline std::shared_ptr<
  830. callable_overlay<
  831. sync_client<
  832. tcp_endpoint<
  833. as::ip::tcp::socket,
  834. strand
  835. >
  836. >
  837. >
  838. >
  839. make_sync_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 sync_client_t = sync_client<
  842. tcp_endpoint<
  843. as::ip::tcp::socket,
  844. strand
  845. >
  846. >;
  847. return std::make_shared<callable_overlay<sync_client_t>>(
  848. sync_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. sync_client<
  862. tcp_endpoint<
  863. as::ip::tcp::socket,
  864. strand
  865. >
  866. >
  867. >
  868. >
  869. make_sync_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_sync_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. sync_client<
  882. tcp_endpoint<
  883. as::ip::tcp::socket,
  884. null_strand
  885. >
  886. >
  887. >
  888. >
  889. make_sync_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 sync_client_t = sync_client<
  892. tcp_endpoint<
  893. as::ip::tcp::socket,
  894. null_strand
  895. >>;
  896. return std::make_shared<callable_overlay<sync_client_t>>(
  897. sync_client_t::constructor_access(),
  898. ioc,
  899. force_move(host),
  900. force_move(port),
  901. #if defined(MQTT_USE_WS)
  902. "/",
  903. #endif // defined(MQTT_USE_WS)
  904. version
  905. );
  906. }
  907. template <typename Ioc>
  908. inline std::shared_ptr<
  909. callable_overlay<
  910. sync_client<
  911. tcp_endpoint<
  912. as::ip::tcp::socket,
  913. null_strand
  914. >
  915. >
  916. >
  917. >
  918. make_sync_client_no_strand(Ioc& ioc, std::string host, std::uint16_t port, protocol_version version) {
  919. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  920. return make_sync_client_no_strand(
  921. ioc,
  922. force_move(host),
  923. std::to_string(port),
  924. version
  925. );
  926. }
  927. #if defined(MQTT_USE_WS)
  928. template <typename Ioc>
  929. inline std::shared_ptr<
  930. callable_overlay<
  931. sync_client<
  932. ws_endpoint<
  933. as::ip::tcp::socket,
  934. strand
  935. >
  936. >
  937. >
  938. >
  939. make_sync_client_ws(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version) {
  940. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  941. using sync_client_t = sync_client<
  942. ws_endpoint<
  943. as::ip::tcp::socket,
  944. strand
  945. >
  946. >;
  947. return std::make_shared<callable_overlay<sync_client_t>>(
  948. sync_client_t::constructor_access(),
  949. ioc,
  950. force_move(host),
  951. force_move(port),
  952. force_move(path),
  953. version
  954. );
  955. }
  956. template <typename Ioc>
  957. inline std::shared_ptr<
  958. callable_overlay<
  959. sync_client<
  960. ws_endpoint<
  961. as::ip::tcp::socket,
  962. strand
  963. >
  964. >
  965. >
  966. >
  967. make_sync_client_ws(Ioc& ioc, std::string host, std::uint16_t port, std::string path, protocol_version version) {
  968. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  969. return make_sync_client_ws(
  970. ioc,
  971. force_move(host),
  972. std::to_string(port),
  973. force_move(path),
  974. version
  975. );
  976. }
  977. template <typename Ioc>
  978. inline std::shared_ptr<
  979. callable_overlay<
  980. sync_client<
  981. ws_endpoint<
  982. as::ip::tcp::socket,
  983. null_strand
  984. >
  985. >
  986. >
  987. >
  988. make_sync_client_no_strand_ws(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version) {
  989. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  990. using sync_client_t = sync_client<
  991. ws_endpoint<
  992. as::ip::tcp::socket,
  993. null_strand
  994. >
  995. >;
  996. return std::make_shared<callable_overlay<sync_client_t>>(
  997. sync_client_t::constructor_access(),
  998. ioc,
  999. force_move(host),
  1000. force_move(port),
  1001. force_move(path),
  1002. version
  1003. );
  1004. }
  1005. template <typename Ioc>
  1006. inline std::shared_ptr<
  1007. callable_overlay<
  1008. sync_client<
  1009. ws_endpoint<
  1010. as::ip::tcp::socket,
  1011. null_strand
  1012. >
  1013. >
  1014. >
  1015. >
  1016. make_sync_client_no_strand_ws(Ioc& ioc, std::string host, std::uint16_t port, std::string path, protocol_version version) {
  1017. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1018. return make_sync_client_no_strand_ws(
  1019. ioc,
  1020. force_move(host),
  1021. std::to_string(port),
  1022. force_move(path),
  1023. version
  1024. );
  1025. }
  1026. #endif // defined(MQTT_USE_WS)
  1027. #if defined(MQTT_USE_TLS)
  1028. template <typename Ioc>
  1029. inline std::shared_ptr<
  1030. callable_overlay<
  1031. sync_client<
  1032. tcp_endpoint<
  1033. tls::stream<as::ip::tcp::socket>,
  1034. strand
  1035. >
  1036. >
  1037. >
  1038. >
  1039. make_tls_sync_client(Ioc& ioc, std::string host, std::string port, protocol_version version) {
  1040. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1041. using sync_client_t = sync_client<
  1042. tcp_endpoint<
  1043. tls::stream<as::ip::tcp::socket>,
  1044. strand
  1045. >
  1046. >;
  1047. return std::make_shared<callable_overlay<sync_client_t>>(
  1048. sync_client_t::constructor_access(),
  1049. ioc,
  1050. force_move(host),
  1051. force_move(port),
  1052. #if defined(MQTT_USE_WS)
  1053. "/",
  1054. #endif // defined(MQTT_USE_WS)
  1055. version
  1056. );
  1057. }
  1058. template <typename Ioc>
  1059. inline std::shared_ptr<
  1060. callable_overlay<
  1061. sync_client<
  1062. tcp_endpoint<
  1063. tls::stream<as::ip::tcp::socket>,
  1064. strand
  1065. >
  1066. >
  1067. >
  1068. >
  1069. make_tls_sync_client(Ioc& ioc, std::string host, std::uint16_t port, protocol_version version) {
  1070. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1071. return make_tls_sync_client(
  1072. ioc,
  1073. force_move(host),
  1074. std::to_string(port),
  1075. version
  1076. );
  1077. }
  1078. template <typename Ioc>
  1079. inline std::shared_ptr<
  1080. callable_overlay<
  1081. sync_client<
  1082. tcp_endpoint<
  1083. tls::stream<as::ip::tcp::socket>,
  1084. null_strand
  1085. >
  1086. >
  1087. >
  1088. >
  1089. make_tls_sync_client_no_strand(Ioc& ioc, std::string host, std::string port, protocol_version version) {
  1090. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1091. using sync_client_t = sync_client<
  1092. tcp_endpoint<
  1093. tls::stream<as::ip::tcp::socket>,
  1094. null_strand
  1095. >
  1096. >;
  1097. return std::make_shared<callable_overlay<sync_client_t>>(
  1098. sync_client_t::constructor_access(),
  1099. ioc,
  1100. force_move(host),
  1101. force_move(port),
  1102. #if defined(MQTT_USE_WS)
  1103. "/",
  1104. #endif // defined(MQTT_USE_WS)
  1105. version
  1106. );
  1107. }
  1108. template <typename Ioc>
  1109. inline std::shared_ptr<
  1110. callable_overlay<
  1111. sync_client<
  1112. tcp_endpoint<
  1113. tls::stream<as::ip::tcp::socket>,
  1114. null_strand
  1115. >
  1116. >
  1117. >
  1118. >
  1119. make_tls_sync_client_no_strand(Ioc& ioc, std::string host, std::uint16_t port, protocol_version version) {
  1120. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1121. return make_tls_sync_client_no_strand(
  1122. ioc,
  1123. force_move(host),
  1124. std::to_string(port),
  1125. version
  1126. );
  1127. }
  1128. #if defined(MQTT_USE_WS)
  1129. template <typename Ioc>
  1130. inline std::shared_ptr<
  1131. callable_overlay<
  1132. sync_client<
  1133. ws_endpoint<
  1134. tls::stream<as::ip::tcp::socket>,
  1135. strand
  1136. >
  1137. >
  1138. >
  1139. >
  1140. make_tls_sync_client_ws(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version) {
  1141. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1142. using sync_client_t = sync_client<
  1143. ws_endpoint<
  1144. tls::stream<as::ip::tcp::socket>,
  1145. strand
  1146. >
  1147. >;
  1148. return std::make_shared<callable_overlay<sync_client_t>>(
  1149. sync_client_t::constructor_access(),
  1150. ioc,
  1151. force_move(host),
  1152. force_move(port),
  1153. force_move(path),
  1154. version
  1155. );
  1156. }
  1157. template <typename Ioc>
  1158. inline std::shared_ptr<
  1159. callable_overlay<
  1160. sync_client<
  1161. ws_endpoint<
  1162. tls::stream<as::ip::tcp::socket>,
  1163. strand
  1164. >
  1165. >
  1166. >
  1167. >
  1168. make_tls_sync_client_ws(Ioc& ioc, std::string host, std::uint16_t port, std::string path, protocol_version version) {
  1169. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1170. return make_tls_sync_client_ws(
  1171. ioc,
  1172. force_move(host),
  1173. std::to_string(port),
  1174. force_move(path),
  1175. version
  1176. );
  1177. }
  1178. template <typename Ioc>
  1179. inline std::shared_ptr<
  1180. callable_overlay<
  1181. sync_client<
  1182. ws_endpoint<
  1183. tls::stream<as::ip::tcp::socket>,
  1184. null_strand
  1185. >
  1186. >
  1187. >
  1188. >
  1189. make_tls_sync_client_no_strand_ws(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version) {
  1190. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1191. using sync_client_t = sync_client<
  1192. ws_endpoint<
  1193. tls::stream<as::ip::tcp::socket>,
  1194. null_strand
  1195. >
  1196. >;
  1197. return std::make_shared<callable_overlay<sync_client_t>>(
  1198. sync_client_t::constructor_access(),
  1199. ioc,
  1200. force_move(host),
  1201. force_move(port),
  1202. force_move(path),
  1203. version
  1204. );
  1205. }
  1206. template <typename Ioc>
  1207. inline std::shared_ptr<
  1208. callable_overlay<
  1209. sync_client<
  1210. ws_endpoint<
  1211. tls::stream<as::ip::tcp::socket>,
  1212. null_strand
  1213. >
  1214. >
  1215. >
  1216. >
  1217. make_tls_sync_client_no_strand_ws(Ioc& ioc, std::string host, std::uint16_t port, std::string path, protocol_version version) {
  1218. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1219. return make_tls_sync_client_no_strand_ws(
  1220. ioc,
  1221. force_move(host),
  1222. std::to_string(port),
  1223. force_move(path),
  1224. version
  1225. );
  1226. }
  1227. #endif // defined(MQTT_USE_WS)
  1228. #endif // defined(MQTT_USE_TLS)
  1229. // 32bit Packet Id (experimental)
  1230. template <typename Ioc>
  1231. inline std::shared_ptr<
  1232. callable_overlay<
  1233. sync_client<
  1234. tcp_endpoint<
  1235. as::ip::tcp::socket,
  1236. strand
  1237. >,
  1238. 4
  1239. >
  1240. >
  1241. >
  1242. make_sync_client_32(Ioc& ioc, std::string host, std::string port, protocol_version version) {
  1243. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1244. using sync_client_t = sync_client<
  1245. tcp_endpoint<
  1246. as::ip::tcp::socket,
  1247. strand
  1248. >,
  1249. 4
  1250. >;
  1251. return std::make_shared<callable_overlay<sync_client_t>>(
  1252. sync_client_t::constructor_access(),
  1253. ioc,
  1254. force_move(host),
  1255. force_move(port),
  1256. #if defined(MQTT_USE_WS)
  1257. "/",
  1258. #endif // defined(MQTT_USE_WS)
  1259. version
  1260. );
  1261. }
  1262. template <typename Ioc>
  1263. inline std::shared_ptr<
  1264. callable_overlay<
  1265. sync_client<
  1266. tcp_endpoint<
  1267. as::ip::tcp::socket,
  1268. strand
  1269. >,
  1270. 4
  1271. >
  1272. >
  1273. >
  1274. make_sync_client_32(Ioc& ioc, std::string host, std::uint16_t port, protocol_version version) {
  1275. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1276. return make_sync_client_32(
  1277. ioc,
  1278. force_move(host),
  1279. std::to_string(port),
  1280. version
  1281. );
  1282. }
  1283. template <typename Ioc>
  1284. inline std::shared_ptr<
  1285. callable_overlay<
  1286. sync_client<
  1287. tcp_endpoint<
  1288. as::ip::tcp::socket,
  1289. null_strand
  1290. >,
  1291. 4
  1292. >
  1293. >
  1294. >
  1295. make_sync_client_no_strand_32(Ioc& ioc, std::string host, std::string port, protocol_version version) {
  1296. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1297. using sync_client_t = sync_client<
  1298. tcp_endpoint<
  1299. as::ip::tcp::socket,
  1300. null_strand
  1301. >,
  1302. 4
  1303. >;
  1304. return std::make_shared<callable_overlay<sync_client_t>>(
  1305. sync_client_t::constructor_access(),
  1306. ioc,
  1307. force_move(host),
  1308. force_move(port),
  1309. #if defined(MQTT_USE_WS)
  1310. "/",
  1311. #endif // defined(MQTT_USE_WS)
  1312. version
  1313. );
  1314. }
  1315. template <typename Ioc>
  1316. inline std::shared_ptr<
  1317. callable_overlay<
  1318. sync_client<
  1319. tcp_endpoint<
  1320. as::ip::tcp::socket,
  1321. null_strand
  1322. >,
  1323. 4
  1324. >
  1325. >
  1326. >
  1327. make_sync_client_no_strand_32(Ioc& ioc, std::string host, std::uint16_t port, protocol_version version) {
  1328. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1329. return make_sync_client_no_strand_32(
  1330. ioc,
  1331. force_move(host),
  1332. std::to_string(port),
  1333. version
  1334. );
  1335. }
  1336. #if defined(MQTT_USE_WS)
  1337. template <typename Ioc>
  1338. inline std::shared_ptr<
  1339. callable_overlay<
  1340. sync_client<
  1341. ws_endpoint<
  1342. as::ip::tcp::socket,
  1343. strand
  1344. >,
  1345. 4
  1346. >
  1347. >
  1348. >
  1349. make_sync_client_ws_32(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version) {
  1350. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1351. using sync_client_t = sync_client<
  1352. ws_endpoint<
  1353. as::ip::tcp::socket,
  1354. strand
  1355. >,
  1356. 4
  1357. >;
  1358. return std::make_shared<callable_overlay<sync_client_t>>(
  1359. sync_client_t::constructor_access(),
  1360. ioc,
  1361. force_move(host),
  1362. force_move(port),
  1363. force_move(path),
  1364. version
  1365. );
  1366. }
  1367. template <typename Ioc>
  1368. inline std::shared_ptr<
  1369. callable_overlay<
  1370. sync_client<
  1371. ws_endpoint<
  1372. as::ip::tcp::socket,
  1373. strand
  1374. >,
  1375. 4
  1376. >
  1377. >
  1378. >
  1379. make_sync_client_ws_32(Ioc& ioc, std::string host, std::uint16_t port, std::string path, protocol_version version) {
  1380. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1381. return make_sync_client_ws_32(
  1382. ioc,
  1383. force_move(host),
  1384. std::to_string(port),
  1385. force_move(path),
  1386. version
  1387. );
  1388. }
  1389. template <typename Ioc>
  1390. inline std::shared_ptr<
  1391. callable_overlay<
  1392. sync_client<
  1393. ws_endpoint<
  1394. as::ip::tcp::socket,
  1395. null_strand
  1396. >,
  1397. 4
  1398. >
  1399. >
  1400. >
  1401. make_sync_client_no_strand_ws_32(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version) {
  1402. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1403. using sync_client_t = sync_client<
  1404. ws_endpoint<
  1405. as::ip::tcp::socket,
  1406. null_strand
  1407. >,
  1408. 4
  1409. >;
  1410. return std::make_shared<callable_overlay<sync_client_t>>(
  1411. sync_client_t::constructor_access(),
  1412. ioc,
  1413. force_move(host),
  1414. force_move(port),
  1415. force_move(path),
  1416. version
  1417. );
  1418. }
  1419. template <typename Ioc>
  1420. inline std::shared_ptr<
  1421. callable_overlay<
  1422. sync_client<
  1423. ws_endpoint<
  1424. as::ip::tcp::socket,
  1425. null_strand
  1426. >,
  1427. 4
  1428. >
  1429. >
  1430. >
  1431. make_sync_client_no_strand_ws_32(Ioc& ioc, std::string host, std::uint16_t port, std::string path, protocol_version version) {
  1432. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1433. return make_sync_client_no_strand_ws_32(
  1434. ioc,
  1435. force_move(host),
  1436. std::to_string(port),
  1437. force_move(path),
  1438. version
  1439. );
  1440. }
  1441. #endif // defined(MQTT_USE_WS)
  1442. #if defined(MQTT_USE_TLS)
  1443. template <typename Ioc>
  1444. inline std::shared_ptr<
  1445. callable_overlay<
  1446. sync_client<
  1447. tcp_endpoint<
  1448. tls::stream<as::ip::tcp::socket>,
  1449. strand
  1450. >,
  1451. 4
  1452. >
  1453. >
  1454. >
  1455. make_tls_sync_client_32(Ioc& ioc, std::string host, std::string port, protocol_version version) {
  1456. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1457. using sync_client_t = sync_client<
  1458. tcp_endpoint<
  1459. tls::stream<as::ip::tcp::socket>,
  1460. strand
  1461. >,
  1462. 4
  1463. >;
  1464. return std::make_shared<callable_overlay<sync_client_t>>(
  1465. sync_client_t::constructor_access(),
  1466. ioc,
  1467. force_move(host),
  1468. force_move(port),
  1469. #if defined(MQTT_USE_WS)
  1470. "/",
  1471. #endif // defined(MQTT_USE_WS)
  1472. version
  1473. );
  1474. }
  1475. template <typename Ioc>
  1476. inline std::shared_ptr<
  1477. callable_overlay<
  1478. sync_client<
  1479. tcp_endpoint<
  1480. tls::stream<as::ip::tcp::socket>,
  1481. strand
  1482. >,
  1483. 4
  1484. >
  1485. >
  1486. >
  1487. make_tls_sync_client_32(Ioc& ioc, std::string host, std::uint16_t port, protocol_version version) {
  1488. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1489. return make_tls_sync_client_32(
  1490. ioc,
  1491. force_move(host),
  1492. std::to_string(port),
  1493. version
  1494. );
  1495. }
  1496. template <typename Ioc>
  1497. inline std::shared_ptr<
  1498. callable_overlay<
  1499. sync_client<
  1500. tcp_endpoint<
  1501. tls::stream<as::ip::tcp::socket>,
  1502. null_strand
  1503. >,
  1504. 4
  1505. >
  1506. >
  1507. >
  1508. make_tls_sync_client_no_strand_32(Ioc& ioc, std::string host, std::string port, protocol_version version) {
  1509. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1510. using sync_client_t = sync_client<
  1511. tcp_endpoint<
  1512. tls::stream<as::ip::tcp::socket>,
  1513. null_strand
  1514. >,
  1515. 4
  1516. >;
  1517. return std::make_shared<callable_overlay<sync_client_t>>(
  1518. sync_client_t::constructor_access(),
  1519. ioc,
  1520. force_move(host),
  1521. force_move(port),
  1522. #if defined(MQTT_USE_WS)
  1523. "/",
  1524. #endif // defined(MQTT_USE_WS)
  1525. version
  1526. );
  1527. }
  1528. template <typename Ioc>
  1529. inline std::shared_ptr<
  1530. callable_overlay<
  1531. sync_client<
  1532. tcp_endpoint<
  1533. tls::stream<as::ip::tcp::socket>,
  1534. null_strand
  1535. >,
  1536. 4
  1537. >
  1538. >
  1539. >
  1540. make_tls_sync_client_no_strand_32(Ioc& ioc, std::string host, std::uint16_t port, protocol_version version) {
  1541. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1542. return make_tls_sync_client_no_strand_32(
  1543. ioc,
  1544. force_move(host),
  1545. std::to_string(port),
  1546. version
  1547. );
  1548. }
  1549. #if defined(MQTT_USE_WS)
  1550. template <typename Ioc>
  1551. inline std::shared_ptr<
  1552. callable_overlay<
  1553. sync_client<
  1554. ws_endpoint<
  1555. tls::stream<as::ip::tcp::socket>,
  1556. strand
  1557. >,
  1558. 4
  1559. >
  1560. >
  1561. >
  1562. make_tls_sync_client_ws_32(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version) {
  1563. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1564. using sync_client_t = sync_client<
  1565. ws_endpoint<
  1566. tls::stream<as::ip::tcp::socket>,
  1567. strand
  1568. >,
  1569. 4
  1570. >;
  1571. return std::make_shared<callable_overlay<sync_client_t>>(
  1572. sync_client_t::constructor_access(),
  1573. ioc,
  1574. force_move(host),
  1575. force_move(port),
  1576. force_move(path),
  1577. version
  1578. );
  1579. }
  1580. template <typename Ioc>
  1581. inline std::shared_ptr<
  1582. callable_overlay<
  1583. sync_client<
  1584. ws_endpoint<
  1585. tls::stream<as::ip::tcp::socket>,
  1586. strand
  1587. >,
  1588. 4
  1589. >
  1590. >
  1591. >
  1592. make_tls_sync_client_ws_32(Ioc& ioc, std::string host, std::uint16_t port, std::string path, protocol_version version) {
  1593. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1594. return make_tls_sync_client_ws_32(
  1595. ioc,
  1596. force_move(host),
  1597. std::to_string(port),
  1598. force_move(path),
  1599. version
  1600. );
  1601. }
  1602. template <typename Ioc>
  1603. inline std::shared_ptr<
  1604. callable_overlay<
  1605. sync_client<
  1606. ws_endpoint<
  1607. tls::stream<as::ip::tcp::socket>,
  1608. null_strand
  1609. >,
  1610. 4
  1611. >
  1612. >
  1613. >
  1614. make_tls_sync_client_no_strand_ws_32(Ioc& ioc, std::string host, std::string port, std::string path, protocol_version version) {
  1615. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1616. using sync_client_t = sync_client<
  1617. ws_endpoint<
  1618. tls::stream<as::ip::tcp::socket>,
  1619. null_strand
  1620. >,
  1621. 4
  1622. >;
  1623. return std::make_shared<callable_overlay<sync_client_t>>(
  1624. sync_client_t::constructor_access(),
  1625. ioc,
  1626. force_move(host),
  1627. force_move(port),
  1628. force_move(path),
  1629. version
  1630. );
  1631. }
  1632. template <typename Ioc>
  1633. inline std::shared_ptr<
  1634. callable_overlay<
  1635. sync_client<
  1636. ws_endpoint<
  1637. tls::stream<as::ip::tcp::socket>,
  1638. null_strand
  1639. >,
  1640. 4
  1641. >
  1642. >
  1643. >
  1644. make_tls_sync_client_no_strand_ws_32(Ioc& ioc, std::string host, std::uint16_t port, std::string path, protocol_version version) {
  1645. static_assert(std::is_same<Ioc, as::io_context>::value, "The type of ioc must be boost::asio::io_context");
  1646. return make_tls_sync_client_no_strand_ws_32(
  1647. ioc,
  1648. force_move(host),
  1649. std::to_string(port),
  1650. force_move(path),
  1651. version
  1652. );
  1653. }
  1654. #endif // defined(MQTT_USE_WS)
  1655. #endif // defined(MQTT_USE_TLS)
  1656. } // namespace MQTT_NS
  1657. #endif // MQTT_SYNC_CLIENT_HPP