PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/asio/socket_base.hpp

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