PageRenderTime 59ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/Source/ThirdParty/ASIO/include/asio/socket_base.hpp

https://gitlab.com/Teo-Mirror/AtomicGameEngine
C++ Header | 520 lines | 142 code | 31 blank | 347 comment | 1 complexity | 3460a8ab04a41489c2698cdb76b5138b MD5 | raw file
  1. //
  2. // socket_base.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_SOCKET_BASE_HPP
  11. #define ASIO_SOCKET_BASE_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. #include "asio/detail/io_control.hpp"
  17. #include "asio/detail/socket_option.hpp"
  18. #include "asio/detail/socket_types.hpp"
  19. #include "asio/detail/push_options.hpp"
  20. namespace asio {
  21. /// The socket_base class is used as a base for the basic_stream_socket and
  22. /// basic_datagram_socket class templates so that we have a common place to
  23. /// define the shutdown_type and enum.
  24. class socket_base
  25. {
  26. public:
  27. /// Different ways a socket may be shutdown.
  28. enum shutdown_type
  29. {
  30. #if defined(GENERATING_DOCUMENTATION)
  31. /// Shutdown the receive side of the socket.
  32. shutdown_receive = implementation_defined,
  33. /// Shutdown the send side of the socket.
  34. shutdown_send = implementation_defined,
  35. /// Shutdown both send and receive on the socket.
  36. shutdown_both = implementation_defined
  37. #else
  38. shutdown_receive = ASIO_OS_DEF(SHUT_RD),
  39. shutdown_send = ASIO_OS_DEF(SHUT_WR),
  40. shutdown_both = ASIO_OS_DEF(SHUT_RDWR)
  41. #endif
  42. };
  43. /// Bitmask type for flags that can be passed to send and receive operations.
  44. typedef int message_flags;
  45. #if defined(GENERATING_DOCUMENTATION)
  46. /// Peek at incoming data without removing it from the input queue.
  47. static const int message_peek = implementation_defined;
  48. /// Process out-of-band data.
  49. static const int message_out_of_band = implementation_defined;
  50. /// Specify that the data should not be subject to routing.
  51. static const int message_do_not_route = implementation_defined;
  52. /// Specifies that the data marks the end of a record.
  53. static const int message_end_of_record = implementation_defined;
  54. #else
  55. ASIO_STATIC_CONSTANT(int,
  56. message_peek = ASIO_OS_DEF(MSG_PEEK));
  57. ASIO_STATIC_CONSTANT(int,
  58. message_out_of_band = ASIO_OS_DEF(MSG_OOB));
  59. ASIO_STATIC_CONSTANT(int,
  60. message_do_not_route = ASIO_OS_DEF(MSG_DONTROUTE));
  61. ASIO_STATIC_CONSTANT(int,
  62. message_end_of_record = ASIO_OS_DEF(MSG_EOR));
  63. #endif
  64. /// Socket option to permit sending of broadcast messages.
  65. /**
  66. * Implements the SOL_SOCKET/SO_BROADCAST socket option.
  67. *
  68. * @par Examples
  69. * Setting the option:
  70. * @code
  71. * asio::ip::udp::socket socket(io_service);
  72. * ...
  73. * asio::socket_base::broadcast option(true);
  74. * socket.set_option(option);
  75. * @endcode
  76. *
  77. * @par
  78. * Getting the current option value:
  79. * @code
  80. * asio::ip::udp::socket socket(io_service);
  81. * ...
  82. * asio::socket_base::broadcast option;
  83. * socket.get_option(option);
  84. * bool is_set = option.value();
  85. * @endcode
  86. *
  87. * @par Concepts:
  88. * Socket_Option, Boolean_Socket_Option.
  89. */
  90. #if defined(GENERATING_DOCUMENTATION)
  91. typedef implementation_defined broadcast;
  92. #else
  93. typedef asio::detail::socket_option::boolean<
  94. ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_BROADCAST)>
  95. broadcast;
  96. #endif
  97. /// Socket option to enable socket-level debugging.
  98. /**
  99. * Implements the SOL_SOCKET/SO_DEBUG socket option.
  100. *
  101. * @par Examples
  102. * Setting the option:
  103. * @code
  104. * asio::ip::tcp::socket socket(io_service);
  105. * ...
  106. * asio::socket_base::debug option(true);
  107. * socket.set_option(option);
  108. * @endcode
  109. *
  110. * @par
  111. * Getting the current option value:
  112. * @code
  113. * asio::ip::tcp::socket socket(io_service);
  114. * ...
  115. * asio::socket_base::debug option;
  116. * socket.get_option(option);
  117. * bool is_set = option.value();
  118. * @endcode
  119. *
  120. * @par Concepts:
  121. * Socket_Option, Boolean_Socket_Option.
  122. */
  123. #if defined(GENERATING_DOCUMENTATION)
  124. typedef implementation_defined debug;
  125. #else
  126. typedef asio::detail::socket_option::boolean<
  127. ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_DEBUG)> debug;
  128. #endif
  129. /// Socket option to prevent routing, use local interfaces only.
  130. /**
  131. * Implements the SOL_SOCKET/SO_DONTROUTE socket option.
  132. *
  133. * @par Examples
  134. * Setting the option:
  135. * @code
  136. * asio::ip::udp::socket socket(io_service);
  137. * ...
  138. * asio::socket_base::do_not_route option(true);
  139. * socket.set_option(option);
  140. * @endcode
  141. *
  142. * @par
  143. * Getting the current option value:
  144. * @code
  145. * asio::ip::udp::socket socket(io_service);
  146. * ...
  147. * asio::socket_base::do_not_route option;
  148. * socket.get_option(option);
  149. * bool is_set = option.value();
  150. * @endcode
  151. *
  152. * @par Concepts:
  153. * Socket_Option, Boolean_Socket_Option.
  154. */
  155. #if defined(GENERATING_DOCUMENTATION)
  156. typedef implementation_defined do_not_route;
  157. #else
  158. typedef asio::detail::socket_option::boolean<
  159. ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_DONTROUTE)>
  160. do_not_route;
  161. #endif
  162. /// Socket option to send keep-alives.
  163. /**
  164. * Implements the SOL_SOCKET/SO_KEEPALIVE socket option.
  165. *
  166. * @par Examples
  167. * Setting the option:
  168. * @code
  169. * asio::ip::tcp::socket socket(io_service);
  170. * ...
  171. * asio::socket_base::keep_alive option(true);
  172. * socket.set_option(option);
  173. * @endcode
  174. *
  175. * @par
  176. * Getting the current option value:
  177. * @code
  178. * asio::ip::tcp::socket socket(io_service);
  179. * ...
  180. * asio::socket_base::keep_alive option;
  181. * socket.get_option(option);
  182. * bool is_set = option.value();
  183. * @endcode
  184. *
  185. * @par Concepts:
  186. * Socket_Option, Boolean_Socket_Option.
  187. */
  188. #if defined(GENERATING_DOCUMENTATION)
  189. typedef implementation_defined keep_alive;
  190. #else
  191. typedef asio::detail::socket_option::boolean<
  192. ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_KEEPALIVE)> keep_alive;
  193. #endif
  194. /// Socket option for the send buffer size of a socket.
  195. /**
  196. * Implements the SOL_SOCKET/SO_SNDBUF socket option.
  197. *
  198. * @par Examples
  199. * Setting the option:
  200. * @code
  201. * asio::ip::tcp::socket socket(io_service);
  202. * ...
  203. * asio::socket_base::send_buffer_size option(8192);
  204. * socket.set_option(option);
  205. * @endcode
  206. *
  207. * @par
  208. * Getting the current option value:
  209. * @code
  210. * asio::ip::tcp::socket socket(io_service);
  211. * ...
  212. * asio::socket_base::send_buffer_size option;
  213. * socket.get_option(option);
  214. * int size = option.value();
  215. * @endcode
  216. *
  217. * @par Concepts:
  218. * Socket_Option, Integer_Socket_Option.
  219. */
  220. #if defined(GENERATING_DOCUMENTATION)
  221. typedef implementation_defined send_buffer_size;
  222. #else
  223. typedef asio::detail::socket_option::integer<
  224. ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_SNDBUF)>
  225. send_buffer_size;
  226. #endif
  227. /// Socket option for the send low watermark.
  228. /**
  229. * Implements the SOL_SOCKET/SO_SNDLOWAT socket option.
  230. *
  231. * @par Examples
  232. * Setting the option:
  233. * @code
  234. * asio::ip::tcp::socket socket(io_service);
  235. * ...
  236. * asio::socket_base::send_low_watermark option(1024);
  237. * socket.set_option(option);
  238. * @endcode
  239. *
  240. * @par
  241. * Getting the current option value:
  242. * @code
  243. * asio::ip::tcp::socket socket(io_service);
  244. * ...
  245. * asio::socket_base::send_low_watermark option;
  246. * socket.get_option(option);
  247. * int size = option.value();
  248. * @endcode
  249. *
  250. * @par Concepts:
  251. * Socket_Option, Integer_Socket_Option.
  252. */
  253. #if defined(GENERATING_DOCUMENTATION)
  254. typedef implementation_defined send_low_watermark;
  255. #else
  256. typedef asio::detail::socket_option::integer<
  257. ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_SNDLOWAT)>
  258. send_low_watermark;
  259. #endif
  260. /// Socket option for the receive buffer size of a socket.
  261. /**
  262. * Implements the SOL_SOCKET/SO_RCVBUF socket option.
  263. *
  264. * @par Examples
  265. * Setting the option:
  266. * @code
  267. * asio::ip::tcp::socket socket(io_service);
  268. * ...
  269. * asio::socket_base::receive_buffer_size option(8192);
  270. * socket.set_option(option);
  271. * @endcode
  272. *
  273. * @par
  274. * Getting the current option value:
  275. * @code
  276. * asio::ip::tcp::socket socket(io_service);
  277. * ...
  278. * asio::socket_base::receive_buffer_size option;
  279. * socket.get_option(option);
  280. * int size = option.value();
  281. * @endcode
  282. *
  283. * @par Concepts:
  284. * Socket_Option, Integer_Socket_Option.
  285. */
  286. #if defined(GENERATING_DOCUMENTATION)
  287. typedef implementation_defined receive_buffer_size;
  288. #else
  289. typedef asio::detail::socket_option::integer<
  290. ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_RCVBUF)>
  291. receive_buffer_size;
  292. #endif
  293. /// Socket option for the receive low watermark.
  294. /**
  295. * Implements the SOL_SOCKET/SO_RCVLOWAT socket option.
  296. *
  297. * @par Examples
  298. * Setting the option:
  299. * @code
  300. * asio::ip::tcp::socket socket(io_service);
  301. * ...
  302. * asio::socket_base::receive_low_watermark option(1024);
  303. * socket.set_option(option);
  304. * @endcode
  305. *
  306. * @par
  307. * Getting the current option value:
  308. * @code
  309. * asio::ip::tcp::socket socket(io_service);
  310. * ...
  311. * asio::socket_base::receive_low_watermark option;
  312. * socket.get_option(option);
  313. * int size = option.value();
  314. * @endcode
  315. *
  316. * @par Concepts:
  317. * Socket_Option, Integer_Socket_Option.
  318. */
  319. #if defined(GENERATING_DOCUMENTATION)
  320. typedef implementation_defined receive_low_watermark;
  321. #else
  322. typedef asio::detail::socket_option::integer<
  323. ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_RCVLOWAT)>
  324. receive_low_watermark;
  325. #endif
  326. /// Socket option to allow the socket to be bound to an address that is
  327. /// already in use.
  328. /**
  329. * Implements the SOL_SOCKET/SO_REUSEADDR socket option.
  330. *
  331. * @par Examples
  332. * Setting the option:
  333. * @code
  334. * asio::ip::tcp::acceptor acceptor(io_service);
  335. * ...
  336. * asio::socket_base::reuse_address option(true);
  337. * acceptor.set_option(option);
  338. * @endcode
  339. *
  340. * @par
  341. * Getting the current option value:
  342. * @code
  343. * asio::ip::tcp::acceptor acceptor(io_service);
  344. * ...
  345. * asio::socket_base::reuse_address option;
  346. * acceptor.get_option(option);
  347. * bool is_set = option.value();
  348. * @endcode
  349. *
  350. * @par Concepts:
  351. * Socket_Option, Boolean_Socket_Option.
  352. */
  353. #if defined(GENERATING_DOCUMENTATION)
  354. typedef implementation_defined reuse_address;
  355. #else
  356. typedef asio::detail::socket_option::boolean<
  357. ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_REUSEADDR)>
  358. reuse_address;
  359. #endif
  360. /// Socket option to specify whether the socket lingers on close if unsent
  361. /// data is present.
  362. /**
  363. * Implements the SOL_SOCKET/SO_LINGER socket option.
  364. *
  365. * @par Examples
  366. * Setting the option:
  367. * @code
  368. * asio::ip::tcp::socket socket(io_service);
  369. * ...
  370. * asio::socket_base::linger option(true, 30);
  371. * socket.set_option(option);
  372. * @endcode
  373. *
  374. * @par
  375. * Getting the current option value:
  376. * @code
  377. * asio::ip::tcp::socket socket(io_service);
  378. * ...
  379. * asio::socket_base::linger option;
  380. * socket.get_option(option);
  381. * bool is_set = option.enabled();
  382. * unsigned short timeout = option.timeout();
  383. * @endcode
  384. *
  385. * @par Concepts:
  386. * Socket_Option, Linger_Socket_Option.
  387. */
  388. #if defined(GENERATING_DOCUMENTATION)
  389. typedef implementation_defined linger;
  390. #else
  391. typedef asio::detail::socket_option::linger<
  392. ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_LINGER)>
  393. linger;
  394. #endif
  395. /// Socket option to report aborted connections on accept.
  396. /**
  397. * Implements a custom socket option that determines whether or not an accept
  398. * operation is permitted to fail with asio::error::connection_aborted.
  399. * By default the option is false.
  400. *
  401. * @par Examples
  402. * Setting the option:
  403. * @code
  404. * asio::ip::tcp::acceptor acceptor(io_service);
  405. * ...
  406. * asio::socket_base::enable_connection_aborted option(true);
  407. * acceptor.set_option(option);
  408. * @endcode
  409. *
  410. * @par
  411. * Getting the current option value:
  412. * @code
  413. * asio::ip::tcp::acceptor acceptor(io_service);
  414. * ...
  415. * asio::socket_base::enable_connection_aborted option;
  416. * acceptor.get_option(option);
  417. * bool is_set = option.value();
  418. * @endcode
  419. *
  420. * @par Concepts:
  421. * Socket_Option, Boolean_Socket_Option.
  422. */
  423. #if defined(GENERATING_DOCUMENTATION)
  424. typedef implementation_defined enable_connection_aborted;
  425. #else
  426. typedef asio::detail::socket_option::boolean<
  427. asio::detail::custom_socket_option_level,
  428. asio::detail::enable_connection_aborted_option>
  429. enable_connection_aborted;
  430. #endif
  431. /// (Deprecated: Use non_blocking().) IO control command to
  432. /// set the blocking mode of the socket.
  433. /**
  434. * Implements the FIONBIO IO control command.
  435. *
  436. * @par Example
  437. * @code
  438. * asio::ip::tcp::socket socket(io_service);
  439. * ...
  440. * asio::socket_base::non_blocking_io command(true);
  441. * socket.io_control(command);
  442. * @endcode
  443. *
  444. * @par Concepts:
  445. * IO_Control_Command, Boolean_IO_Control_Command.
  446. */
  447. #if defined(GENERATING_DOCUMENTATION)
  448. typedef implementation_defined non_blocking_io;
  449. #else
  450. typedef asio::detail::io_control::non_blocking_io non_blocking_io;
  451. #endif
  452. /// IO control command to get the amount of data that can be read without
  453. /// blocking.
  454. /**
  455. * Implements the FIONREAD IO control command.
  456. *
  457. * @par Example
  458. * @code
  459. * asio::ip::tcp::socket socket(io_service);
  460. * ...
  461. * asio::socket_base::bytes_readable command(true);
  462. * socket.io_control(command);
  463. * std::size_t bytes_readable = command.get();
  464. * @endcode
  465. *
  466. * @par Concepts:
  467. * IO_Control_Command, Size_IO_Control_Command.
  468. */
  469. #if defined(GENERATING_DOCUMENTATION)
  470. typedef implementation_defined bytes_readable;
  471. #else
  472. typedef asio::detail::io_control::bytes_readable bytes_readable;
  473. #endif
  474. /// The maximum length of the queue of pending incoming connections.
  475. #if defined(GENERATING_DOCUMENTATION)
  476. static const int max_connections = implementation_defined;
  477. #else
  478. ASIO_STATIC_CONSTANT(int, max_connections
  479. = ASIO_OS_DEF(SOMAXCONN));
  480. #endif
  481. protected:
  482. /// Protected destructor to prevent deletion through this type.
  483. ~socket_base()
  484. {
  485. }
  486. };
  487. } // namespace asio
  488. #include "asio/detail/pop_options.hpp"
  489. #endif // ASIO_SOCKET_BASE_HPP