Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

null_socket_service.hpp 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. //
  2. // detail/null_socket_service.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef ASIO_DETAIL_NULL_SOCKET_SERVICE_HPP
  11. #define ASIO_DETAIL_NULL_SOCKET_SERVICE_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #if defined(ASIO_WINDOWS_RUNTIME)
  17. #include "asio/buffer.hpp"
  18. #include "asio/error.hpp"
  19. #include "asio/io_context.hpp"
  20. #include "asio/socket_base.hpp"
  21. #include "asio/detail/bind_handler.hpp"
  22. #include "asio/detail/push_options.hpp"
  23. namespace asio {
  24. namespace detail {
  25. template <typename Protocol>
  26. class null_socket_service
  27. {
  28. public:
  29. // The protocol type.
  30. typedef Protocol protocol_type;
  31. // The endpoint type.
  32. typedef typename Protocol::endpoint endpoint_type;
  33. // The native type of a socket.
  34. typedef int native_handle_type;
  35. // The implementation type of the socket.
  36. struct implementation_type
  37. {
  38. };
  39. // Constructor.
  40. null_socket_service(asio::io_context& io_context)
  41. : io_context_(io_context)
  42. {
  43. }
  44. // Destroy all user-defined handler objects owned by the service.
  45. void shutdown()
  46. {
  47. }
  48. // Construct a new socket implementation.
  49. void construct(implementation_type&)
  50. {
  51. }
  52. // Move-construct a new socket implementation.
  53. void move_construct(implementation_type&, implementation_type&)
  54. {
  55. }
  56. // Move-assign from another socket implementation.
  57. void move_assign(implementation_type&,
  58. null_socket_service&, implementation_type&)
  59. {
  60. }
  61. // Move-construct a new socket implementation from another protocol type.
  62. template <typename Protocol1>
  63. void converting_move_construct(implementation_type&,
  64. typename null_socket_service<Protocol1>::implementation_type&)
  65. {
  66. }
  67. // Destroy a socket implementation.
  68. void destroy(implementation_type&)
  69. {
  70. }
  71. // Open a new socket implementation.
  72. asio::error_code open(implementation_type&,
  73. const protocol_type&, asio::error_code& ec)
  74. {
  75. ec = asio::error::operation_not_supported;
  76. return ec;
  77. }
  78. // Assign a native socket to a socket implementation.
  79. asio::error_code assign(implementation_type&, const protocol_type&,
  80. const native_handle_type&, asio::error_code& ec)
  81. {
  82. ec = asio::error::operation_not_supported;
  83. return ec;
  84. }
  85. // Determine whether the socket is open.
  86. bool is_open(const implementation_type&) const
  87. {
  88. return false;
  89. }
  90. // Destroy a socket implementation.
  91. asio::error_code close(implementation_type&,
  92. asio::error_code& ec)
  93. {
  94. ec = asio::error::operation_not_supported;
  95. return ec;
  96. }
  97. // Get the native socket representation.
  98. native_handle_type native_handle(implementation_type&)
  99. {
  100. return 0;
  101. }
  102. // Cancel all operations associated with the socket.
  103. asio::error_code cancel(implementation_type&,
  104. asio::error_code& ec)
  105. {
  106. ec = asio::error::operation_not_supported;
  107. return ec;
  108. }
  109. // Determine whether the socket is at the out-of-band data mark.
  110. bool at_mark(const implementation_type&,
  111. asio::error_code& ec) const
  112. {
  113. ec = asio::error::operation_not_supported;
  114. return false;
  115. }
  116. // Determine the number of bytes available for reading.
  117. std::size_t available(const implementation_type&,
  118. asio::error_code& ec) const
  119. {
  120. ec = asio::error::operation_not_supported;
  121. return 0;
  122. }
  123. // Place the socket into the state where it will listen for new connections.
  124. asio::error_code listen(implementation_type&,
  125. int, asio::error_code& ec)
  126. {
  127. ec = asio::error::operation_not_supported;
  128. return ec;
  129. }
  130. // Perform an IO control command on the socket.
  131. template <typename IO_Control_Command>
  132. asio::error_code io_control(implementation_type&,
  133. IO_Control_Command&, asio::error_code& ec)
  134. {
  135. ec = asio::error::operation_not_supported;
  136. return ec;
  137. }
  138. // Gets the non-blocking mode of the socket.
  139. bool non_blocking(const implementation_type&) const
  140. {
  141. return false;
  142. }
  143. // Sets the non-blocking mode of the socket.
  144. asio::error_code non_blocking(implementation_type&,
  145. bool, asio::error_code& ec)
  146. {
  147. ec = asio::error::operation_not_supported;
  148. return ec;
  149. }
  150. // Gets the non-blocking mode of the native socket implementation.
  151. bool native_non_blocking(const implementation_type&) const
  152. {
  153. return false;
  154. }
  155. // Sets the non-blocking mode of the native socket implementation.
  156. asio::error_code native_non_blocking(implementation_type&,
  157. bool, asio::error_code& ec)
  158. {
  159. ec = asio::error::operation_not_supported;
  160. return ec;
  161. }
  162. // Disable sends or receives on the socket.
  163. asio::error_code shutdown(implementation_type&,
  164. socket_base::shutdown_type, asio::error_code& ec)
  165. {
  166. ec = asio::error::operation_not_supported;
  167. return ec;
  168. }
  169. // Bind the socket to the specified local endpoint.
  170. asio::error_code bind(implementation_type&,
  171. const endpoint_type&, asio::error_code& ec)
  172. {
  173. ec = asio::error::operation_not_supported;
  174. return ec;
  175. }
  176. // Set a socket option.
  177. template <typename Option>
  178. asio::error_code set_option(implementation_type&,
  179. const Option&, asio::error_code& ec)
  180. {
  181. ec = asio::error::operation_not_supported;
  182. return ec;
  183. }
  184. // Set a socket option.
  185. template <typename Option>
  186. asio::error_code get_option(const implementation_type&,
  187. Option&, asio::error_code& ec) const
  188. {
  189. ec = asio::error::operation_not_supported;
  190. return ec;
  191. }
  192. // Get the local endpoint.
  193. endpoint_type local_endpoint(const implementation_type&,
  194. asio::error_code& ec) const
  195. {
  196. ec = asio::error::operation_not_supported;
  197. return endpoint_type();
  198. }
  199. // Get the remote endpoint.
  200. endpoint_type remote_endpoint(const implementation_type&,
  201. asio::error_code& ec) const
  202. {
  203. ec = asio::error::operation_not_supported;
  204. return endpoint_type();
  205. }
  206. // Send the given data to the peer.
  207. template <typename ConstBufferSequence>
  208. std::size_t send(implementation_type&, const ConstBufferSequence&,
  209. socket_base::message_flags, asio::error_code& ec)
  210. {
  211. ec = asio::error::operation_not_supported;
  212. return 0;
  213. }
  214. // Wait until data can be sent without blocking.
  215. std::size_t send(implementation_type&, const null_buffers&,
  216. socket_base::message_flags, asio::error_code& ec)
  217. {
  218. ec = asio::error::operation_not_supported;
  219. return 0;
  220. }
  221. // Start an asynchronous send. The data being sent must be valid for the
  222. // lifetime of the asynchronous operation.
  223. template <typename ConstBufferSequence, typename Handler>
  224. void async_send(implementation_type&, const ConstBufferSequence&,
  225. socket_base::message_flags, Handler& handler)
  226. {
  227. asio::error_code ec = asio::error::operation_not_supported;
  228. const std::size_t bytes_transferred = 0;
  229. io_context_.post(detail::bind_handler(handler, ec, bytes_transferred));
  230. }
  231. // Start an asynchronous wait until data can be sent without blocking.
  232. template <typename Handler>
  233. void async_send(implementation_type&, const null_buffers&,
  234. socket_base::message_flags, Handler& handler)
  235. {
  236. asio::error_code ec = asio::error::operation_not_supported;
  237. const std::size_t bytes_transferred = 0;
  238. io_context_.post(detail::bind_handler(handler, ec, bytes_transferred));
  239. }
  240. // Receive some data from the peer. Returns the number of bytes received.
  241. template <typename MutableBufferSequence>
  242. std::size_t receive(implementation_type&, const MutableBufferSequence&,
  243. socket_base::message_flags, asio::error_code& ec)
  244. {
  245. ec = asio::error::operation_not_supported;
  246. return 0;
  247. }
  248. // Wait until data can be received without blocking.
  249. std::size_t receive(implementation_type&, const null_buffers&,
  250. socket_base::message_flags, asio::error_code& ec)
  251. {
  252. ec = asio::error::operation_not_supported;
  253. return 0;
  254. }
  255. // Start an asynchronous receive. The buffer for the data being received
  256. // must be valid for the lifetime of the asynchronous operation.
  257. template <typename MutableBufferSequence, typename Handler>
  258. void async_receive(implementation_type&, const MutableBufferSequence&,
  259. socket_base::message_flags, Handler& handler)
  260. {
  261. asio::error_code ec = asio::error::operation_not_supported;
  262. const std::size_t bytes_transferred = 0;
  263. io_context_.post(detail::bind_handler(handler, ec, bytes_transferred));
  264. }
  265. // Wait until data can be received without blocking.
  266. template <typename Handler>
  267. void async_receive(implementation_type&, const null_buffers&,
  268. socket_base::message_flags, Handler& handler)
  269. {
  270. asio::error_code ec = asio::error::operation_not_supported;
  271. const std::size_t bytes_transferred = 0;
  272. io_context_.post(detail::bind_handler(handler, ec, bytes_transferred));
  273. }
  274. // Receive some data with associated flags. Returns the number of bytes
  275. // received.
  276. template <typename MutableBufferSequence>
  277. std::size_t receive_with_flags(implementation_type&,
  278. const MutableBufferSequence&, socket_base::message_flags,
  279. socket_base::message_flags&, asio::error_code& ec)
  280. {
  281. ec = asio::error::operation_not_supported;
  282. return 0;
  283. }
  284. // Wait until data can be received without blocking.
  285. std::size_t receive_with_flags(implementation_type&,
  286. const null_buffers&, socket_base::message_flags,
  287. socket_base::message_flags&, asio::error_code& ec)
  288. {
  289. ec = asio::error::operation_not_supported;
  290. return 0;
  291. }
  292. // Start an asynchronous receive. The buffer for the data being received
  293. // must be valid for the lifetime of the asynchronous operation.
  294. template <typename MutableBufferSequence, typename Handler>
  295. void async_receive_with_flags(implementation_type&,
  296. const MutableBufferSequence&, socket_base::message_flags,
  297. socket_base::message_flags&, Handler& handler)
  298. {
  299. asio::error_code ec = asio::error::operation_not_supported;
  300. const std::size_t bytes_transferred = 0;
  301. io_context_.post(detail::bind_handler(handler, ec, bytes_transferred));
  302. }
  303. // Wait until data can be received without blocking.
  304. template <typename Handler>
  305. void async_receive_with_flags(implementation_type&,
  306. const null_buffers&, socket_base::message_flags,
  307. socket_base::message_flags&, Handler& handler)
  308. {
  309. asio::error_code ec = asio::error::operation_not_supported;
  310. const std::size_t bytes_transferred = 0;
  311. io_context_.post(detail::bind_handler(handler, ec, bytes_transferred));
  312. }
  313. // Send a datagram to the specified endpoint. Returns the number of bytes
  314. // sent.
  315. template <typename ConstBufferSequence>
  316. std::size_t send_to(implementation_type&, const ConstBufferSequence&,
  317. const endpoint_type&, socket_base::message_flags,
  318. asio::error_code& ec)
  319. {
  320. ec = asio::error::operation_not_supported;
  321. return 0;
  322. }
  323. // Wait until data can be sent without blocking.
  324. std::size_t send_to(implementation_type&, const null_buffers&,
  325. const endpoint_type&, socket_base::message_flags,
  326. asio::error_code& ec)
  327. {
  328. ec = asio::error::operation_not_supported;
  329. return 0;
  330. }
  331. // Start an asynchronous send. The data being sent must be valid for the
  332. // lifetime of the asynchronous operation.
  333. template <typename ConstBufferSequence, typename Handler>
  334. void async_send_to(implementation_type&, const ConstBufferSequence&,
  335. const endpoint_type&, socket_base::message_flags,
  336. Handler& handler)
  337. {
  338. asio::error_code ec = asio::error::operation_not_supported;
  339. const std::size_t bytes_transferred = 0;
  340. io_context_.post(detail::bind_handler(handler, ec, bytes_transferred));
  341. }
  342. // Start an asynchronous wait until data can be sent without blocking.
  343. template <typename Handler>
  344. void async_send_to(implementation_type&, const null_buffers&,
  345. const endpoint_type&, socket_base::message_flags, Handler& handler)
  346. {
  347. asio::error_code ec = asio::error::operation_not_supported;
  348. const std::size_t bytes_transferred = 0;
  349. io_context_.post(detail::bind_handler(handler, ec, bytes_transferred));
  350. }
  351. // Receive a datagram with the endpoint of the sender. Returns the number of
  352. // bytes received.
  353. template <typename MutableBufferSequence>
  354. std::size_t receive_from(implementation_type&, const MutableBufferSequence&,
  355. endpoint_type&, socket_base::message_flags,
  356. asio::error_code& ec)
  357. {
  358. ec = asio::error::operation_not_supported;
  359. return 0;
  360. }
  361. // Wait until data can be received without blocking.
  362. std::size_t receive_from(implementation_type&, const null_buffers&,
  363. endpoint_type&, socket_base::message_flags,
  364. asio::error_code& ec)
  365. {
  366. ec = asio::error::operation_not_supported;
  367. return 0;
  368. }
  369. // Start an asynchronous receive. The buffer for the data being received and
  370. // the sender_endpoint object must both be valid for the lifetime of the
  371. // asynchronous operation.
  372. template <typename MutableBufferSequence, typename Handler>
  373. void async_receive_from(implementation_type&,
  374. const MutableBufferSequence&, endpoint_type&,
  375. socket_base::message_flags, Handler& handler)
  376. {
  377. asio::error_code ec = asio::error::operation_not_supported;
  378. const std::size_t bytes_transferred = 0;
  379. io_context_.post(detail::bind_handler(handler, ec, bytes_transferred));
  380. }
  381. // Wait until data can be received without blocking.
  382. template <typename Handler>
  383. void async_receive_from(implementation_type&,
  384. const null_buffers&, endpoint_type&,
  385. socket_base::message_flags, Handler& handler)
  386. {
  387. asio::error_code ec = asio::error::operation_not_supported;
  388. const std::size_t bytes_transferred = 0;
  389. io_context_.post(detail::bind_handler(handler, ec, bytes_transferred));
  390. }
  391. // Accept a new connection.
  392. template <typename Socket>
  393. asio::error_code accept(implementation_type&,
  394. Socket&, endpoint_type*, asio::error_code& ec)
  395. {
  396. ec = asio::error::operation_not_supported;
  397. return ec;
  398. }
  399. // Start an asynchronous accept. The peer and peer_endpoint objects
  400. // must be valid until the accept's handler is invoked.
  401. template <typename Socket, typename Handler>
  402. void async_accept(implementation_type&, Socket&,
  403. endpoint_type*, Handler& handler)
  404. {
  405. asio::error_code ec = asio::error::operation_not_supported;
  406. io_context_.post(detail::bind_handler(handler, ec));
  407. }
  408. // Connect the socket to the specified endpoint.
  409. asio::error_code connect(implementation_type&,
  410. const endpoint_type&, asio::error_code& ec)
  411. {
  412. ec = asio::error::operation_not_supported;
  413. return ec;
  414. }
  415. // Start an asynchronous connect.
  416. template <typename Handler>
  417. void async_connect(implementation_type&,
  418. const endpoint_type&, Handler& handler)
  419. {
  420. asio::error_code ec = asio::error::operation_not_supported;
  421. io_context_.post(detail::bind_handler(handler, ec));
  422. }
  423. private:
  424. asio::io_context& io_context_;
  425. };
  426. } // namespace detail
  427. } // namespace asio
  428. #include "asio/detail/pop_options.hpp"
  429. #endif // defined(ASIO_WINDOWS_RUNTIME)
  430. #endif // ASIO_DETAIL_NULL_SOCKET_SERVICE_HPP