null_socket_service.hpp 16 KB

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