5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef BOOST_ASIO_SOCKET_BASE_HPP
12 #define BOOST_ASIO_SOCKET_BASE_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
19 #include <boost/asio/detail/io_control.hpp>
20 #include <boost/asio/detail/socket_option.hpp>
21 #include <boost/asio/detail/socket_types.hpp>
23 #include <boost/asio/detail/push_options.hpp>
28 /// The socket_base class is used as a base for the basic_stream_socket and
29 /// basic_datagram_socket class templates so that we have a common place to
30 /// define the shutdown_type and enum.
34 /// Different ways a socket may be shutdown.
37 #if defined(GENERATING_DOCUMENTATION)
38 /// Shutdown the receive side of the socket.
39 shutdown_receive = implementation_defined,
41 /// Shutdown the send side of the socket.
42 shutdown_send = implementation_defined,
44 /// Shutdown both send and receive on the socket.
45 shutdown_both = implementation_defined
47 shutdown_receive = BOOST_ASIO_OS_DEF(SHUT_RD),
48 shutdown_send = BOOST_ASIO_OS_DEF(SHUT_WR),
49 shutdown_both = BOOST_ASIO_OS_DEF(SHUT_RDWR)
53 /// Bitmask type for flags that can be passed to send and receive operations.
54 typedef int message_flags;
56 #if defined(GENERATING_DOCUMENTATION)
57 /// Peek at incoming data without removing it from the input queue.
58 static const int message_peek = implementation_defined;
60 /// Process out-of-band data.
61 static const int message_out_of_band = implementation_defined;
63 /// Specify that the data should not be subject to routing.
64 static const int message_do_not_route = implementation_defined;
66 /// Specifies that the data marks the end of a record.
67 static const int message_end_of_record = implementation_defined;
69 BOOST_ASIO_STATIC_CONSTANT(int,
70 message_peek = BOOST_ASIO_OS_DEF(MSG_PEEK));
71 BOOST_ASIO_STATIC_CONSTANT(int,
72 message_out_of_band = BOOST_ASIO_OS_DEF(MSG_OOB));
73 BOOST_ASIO_STATIC_CONSTANT(int,
74 message_do_not_route = BOOST_ASIO_OS_DEF(MSG_DONTROUTE));
75 BOOST_ASIO_STATIC_CONSTANT(int,
76 message_end_of_record = BOOST_ASIO_OS_DEF(MSG_EOR));
81 * For use with basic_socket::wait() and basic_socket::async_wait().
85 /// Wait for a socket to become ready to read.
88 /// Wait for a socket to become ready to write.
91 /// Wait for a socket to have error conditions pending.
95 /// Socket option to permit sending of broadcast messages.
97 * Implements the SOL_SOCKET/SO_BROADCAST socket option.
100 * Setting the option:
102 * boost::asio::ip::udp::socket socket(io_context);
104 * boost::asio::socket_base::broadcast option(true);
105 * socket.set_option(option);
109 * Getting the current option value:
111 * boost::asio::ip::udp::socket socket(io_context);
113 * boost::asio::socket_base::broadcast option;
114 * socket.get_option(option);
115 * bool is_set = option.value();
119 * Socket_Option, Boolean_Socket_Option.
121 #if defined(GENERATING_DOCUMENTATION)
122 typedef implementation_defined broadcast;
124 typedef boost::asio::detail::socket_option::boolean<
125 BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_BROADCAST)>
129 /// Socket option to enable socket-level debugging.
131 * Implements the SOL_SOCKET/SO_DEBUG socket option.
134 * Setting the option:
136 * boost::asio::ip::tcp::socket socket(io_context);
138 * boost::asio::socket_base::debug option(true);
139 * socket.set_option(option);
143 * Getting the current option value:
145 * boost::asio::ip::tcp::socket socket(io_context);
147 * boost::asio::socket_base::debug option;
148 * socket.get_option(option);
149 * bool is_set = option.value();
153 * Socket_Option, Boolean_Socket_Option.
155 #if defined(GENERATING_DOCUMENTATION)
156 typedef implementation_defined debug;
158 typedef boost::asio::detail::socket_option::boolean<
159 BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_DEBUG)> debug;
162 /// Socket option to prevent routing, use local interfaces only.
164 * Implements the SOL_SOCKET/SO_DONTROUTE socket option.
167 * Setting the option:
169 * boost::asio::ip::udp::socket socket(io_context);
171 * boost::asio::socket_base::do_not_route option(true);
172 * socket.set_option(option);
176 * Getting the current option value:
178 * boost::asio::ip::udp::socket socket(io_context);
180 * boost::asio::socket_base::do_not_route option;
181 * socket.get_option(option);
182 * bool is_set = option.value();
186 * Socket_Option, Boolean_Socket_Option.
188 #if defined(GENERATING_DOCUMENTATION)
189 typedef implementation_defined do_not_route;
191 typedef boost::asio::detail::socket_option::boolean<
192 BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_DONTROUTE)>
196 /// Socket option to send keep-alives.
198 * Implements the SOL_SOCKET/SO_KEEPALIVE socket option.
201 * Setting the option:
203 * boost::asio::ip::tcp::socket socket(io_context);
205 * boost::asio::socket_base::keep_alive option(true);
206 * socket.set_option(option);
210 * Getting the current option value:
212 * boost::asio::ip::tcp::socket socket(io_context);
214 * boost::asio::socket_base::keep_alive option;
215 * socket.get_option(option);
216 * bool is_set = option.value();
220 * Socket_Option, Boolean_Socket_Option.
222 #if defined(GENERATING_DOCUMENTATION)
223 typedef implementation_defined keep_alive;
225 typedef boost::asio::detail::socket_option::boolean<
226 BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_KEEPALIVE)> keep_alive;
229 /// Socket option for the send buffer size of a socket.
231 * Implements the SOL_SOCKET/SO_SNDBUF socket option.
234 * Setting the option:
236 * boost::asio::ip::tcp::socket socket(io_context);
238 * boost::asio::socket_base::send_buffer_size option(8192);
239 * socket.set_option(option);
243 * Getting the current option value:
245 * boost::asio::ip::tcp::socket socket(io_context);
247 * boost::asio::socket_base::send_buffer_size option;
248 * socket.get_option(option);
249 * int size = option.value();
253 * Socket_Option, Integer_Socket_Option.
255 #if defined(GENERATING_DOCUMENTATION)
256 typedef implementation_defined send_buffer_size;
258 typedef boost::asio::detail::socket_option::integer<
259 BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_SNDBUF)>
263 /// Socket option for the send low watermark.
265 * Implements the SOL_SOCKET/SO_SNDLOWAT socket option.
268 * Setting the option:
270 * boost::asio::ip::tcp::socket socket(io_context);
272 * boost::asio::socket_base::send_low_watermark option(1024);
273 * socket.set_option(option);
277 * Getting the current option value:
279 * boost::asio::ip::tcp::socket socket(io_context);
281 * boost::asio::socket_base::send_low_watermark option;
282 * socket.get_option(option);
283 * int size = option.value();
287 * Socket_Option, Integer_Socket_Option.
289 #if defined(GENERATING_DOCUMENTATION)
290 typedef implementation_defined send_low_watermark;
292 typedef boost::asio::detail::socket_option::integer<
293 BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_SNDLOWAT)>
297 /// Socket option for the receive buffer size of a socket.
299 * Implements the SOL_SOCKET/SO_RCVBUF socket option.
302 * Setting the option:
304 * boost::asio::ip::tcp::socket socket(io_context);
306 * boost::asio::socket_base::receive_buffer_size option(8192);
307 * socket.set_option(option);
311 * Getting the current option value:
313 * boost::asio::ip::tcp::socket socket(io_context);
315 * boost::asio::socket_base::receive_buffer_size option;
316 * socket.get_option(option);
317 * int size = option.value();
321 * Socket_Option, Integer_Socket_Option.
323 #if defined(GENERATING_DOCUMENTATION)
324 typedef implementation_defined receive_buffer_size;
326 typedef boost::asio::detail::socket_option::integer<
327 BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_RCVBUF)>
331 /// Socket option for the receive low watermark.
333 * Implements the SOL_SOCKET/SO_RCVLOWAT socket option.
336 * Setting the option:
338 * boost::asio::ip::tcp::socket socket(io_context);
340 * boost::asio::socket_base::receive_low_watermark option(1024);
341 * socket.set_option(option);
345 * Getting the current option value:
347 * boost::asio::ip::tcp::socket socket(io_context);
349 * boost::asio::socket_base::receive_low_watermark option;
350 * socket.get_option(option);
351 * int size = option.value();
355 * Socket_Option, Integer_Socket_Option.
357 #if defined(GENERATING_DOCUMENTATION)
358 typedef implementation_defined receive_low_watermark;
360 typedef boost::asio::detail::socket_option::integer<
361 BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_RCVLOWAT)>
362 receive_low_watermark;
365 /// Socket option to allow the socket to be bound to an address that is
368 * Implements the SOL_SOCKET/SO_REUSEADDR socket option.
371 * Setting the option:
373 * boost::asio::ip::tcp::acceptor acceptor(io_context);
375 * boost::asio::socket_base::reuse_address option(true);
376 * acceptor.set_option(option);
380 * Getting the current option value:
382 * boost::asio::ip::tcp::acceptor acceptor(io_context);
384 * boost::asio::socket_base::reuse_address option;
385 * acceptor.get_option(option);
386 * bool is_set = option.value();
390 * Socket_Option, Boolean_Socket_Option.
392 #if defined(GENERATING_DOCUMENTATION)
393 typedef implementation_defined reuse_address;
395 typedef boost::asio::detail::socket_option::boolean<
396 BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_REUSEADDR)>
400 /// Socket option to specify whether the socket lingers on close if unsent
403 * Implements the SOL_SOCKET/SO_LINGER socket option.
406 * Setting the option:
408 * boost::asio::ip::tcp::socket socket(io_context);
410 * boost::asio::socket_base::linger option(true, 30);
411 * socket.set_option(option);
415 * Getting the current option value:
417 * boost::asio::ip::tcp::socket socket(io_context);
419 * boost::asio::socket_base::linger option;
420 * socket.get_option(option);
421 * bool is_set = option.enabled();
422 * unsigned short timeout = option.timeout();
426 * Socket_Option, Linger_Socket_Option.
428 #if defined(GENERATING_DOCUMENTATION)
429 typedef implementation_defined linger;
431 typedef boost::asio::detail::socket_option::linger<
432 BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_LINGER)>
436 /// Socket option for putting received out-of-band data inline.
438 * Implements the SOL_SOCKET/SO_OOBINLINE socket option.
441 * Setting the option:
443 * boost::asio::ip::tcp::socket socket(io_context);
445 * boost::asio::socket_base::out_of_band_inline option(true);
446 * socket.set_option(option);
450 * Getting the current option value:
452 * boost::asio::ip::tcp::socket socket(io_context);
454 * boost::asio::socket_base::out_of_band_inline option;
455 * socket.get_option(option);
456 * bool value = option.value();
460 * Socket_Option, Boolean_Socket_Option.
462 #if defined(GENERATING_DOCUMENTATION)
463 typedef implementation_defined out_of_band_inline;
465 typedef boost::asio::detail::socket_option::boolean<
466 BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_OOBINLINE)>
470 /// Socket option to report aborted connections on accept.
472 * Implements a custom socket option that determines whether or not an accept
473 * operation is permitted to fail with boost::asio::error::connection_aborted.
474 * By default the option is false.
477 * Setting the option:
479 * boost::asio::ip::tcp::acceptor acceptor(io_context);
481 * boost::asio::socket_base::enable_connection_aborted option(true);
482 * acceptor.set_option(option);
486 * Getting the current option value:
488 * boost::asio::ip::tcp::acceptor acceptor(io_context);
490 * boost::asio::socket_base::enable_connection_aborted option;
491 * acceptor.get_option(option);
492 * bool is_set = option.value();
496 * Socket_Option, Boolean_Socket_Option.
498 #if defined(GENERATING_DOCUMENTATION)
499 typedef implementation_defined enable_connection_aborted;
501 typedef boost::asio::detail::socket_option::boolean<
502 boost::asio::detail::custom_socket_option_level,
503 boost::asio::detail::enable_connection_aborted_option>
504 enable_connection_aborted;
507 /// IO control command to get the amount of data that can be read without
510 * Implements the FIONREAD IO control command.
514 * boost::asio::ip::tcp::socket socket(io_context);
516 * boost::asio::socket_base::bytes_readable command(true);
517 * socket.io_control(command);
518 * std::size_t bytes_readable = command.get();
522 * IO_Control_Command, Size_IO_Control_Command.
524 #if defined(GENERATING_DOCUMENTATION)
525 typedef implementation_defined bytes_readable;
527 typedef boost::asio::detail::io_control::bytes_readable bytes_readable;
530 /// The maximum length of the queue of pending incoming connections.
531 #if defined(GENERATING_DOCUMENTATION)
532 static const int max_listen_connections = implementation_defined;
534 BOOST_ASIO_STATIC_CONSTANT(int, max_listen_connections
535 = BOOST_ASIO_OS_DEF(SOMAXCONN));
538 #if !defined(BOOST_ASIO_NO_DEPRECATED)
539 /// (Deprecated: Use max_listen_connections.) The maximum length of the queue
540 /// of pending incoming connections.
541 #if defined(GENERATING_DOCUMENTATION)
542 static const int max_connections = implementation_defined;
544 BOOST_ASIO_STATIC_CONSTANT(int, max_connections
545 = BOOST_ASIO_OS_DEF(SOMAXCONN));
547 #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
550 /// Protected destructor to prevent deletion through this type.
559 #include <boost/asio/detail/pop_options.hpp>
561 #endif // BOOST_ASIO_SOCKET_BASE_HPP