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 16KB

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