null_socket_service.hpp 17 KB

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