5 // Copyright (c) 2003-2016 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));
79 /// Socket option to permit sending of broadcast messages.
81 * Implements the SOL_SOCKET/SO_BROADCAST socket option.
86 * boost::asio::ip::udp::socket socket(io_service);
88 * boost::asio::socket_base::broadcast option(true);
89 * socket.set_option(option);
93 * Getting the current option value:
95 * boost::asio::ip::udp::socket socket(io_service);
97 * boost::asio::socket_base::broadcast option;
98 * socket.get_option(option);
99 * bool is_set = option.value();
103 * Socket_Option, Boolean_Socket_Option.
105 #if defined(GENERATING_DOCUMENTATION)
106 typedef implementation_defined broadcast;
108 typedef boost::asio::detail::socket_option::boolean<
109 BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_BROADCAST)>
113 /// Socket option to enable socket-level debugging.
115 * Implements the SOL_SOCKET/SO_DEBUG socket option.
118 * Setting the option:
120 * boost::asio::ip::tcp::socket socket(io_service);
122 * boost::asio::socket_base::debug option(true);
123 * socket.set_option(option);
127 * Getting the current option value:
129 * boost::asio::ip::tcp::socket socket(io_service);
131 * boost::asio::socket_base::debug option;
132 * socket.get_option(option);
133 * bool is_set = option.value();
137 * Socket_Option, Boolean_Socket_Option.
139 #if defined(GENERATING_DOCUMENTATION)
140 typedef implementation_defined debug;
142 typedef boost::asio::detail::socket_option::boolean<
143 BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_DEBUG)> debug;
146 /// Socket option to prevent routing, use local interfaces only.
148 * Implements the SOL_SOCKET/SO_DONTROUTE socket option.
151 * Setting the option:
153 * boost::asio::ip::udp::socket socket(io_service);
155 * boost::asio::socket_base::do_not_route option(true);
156 * socket.set_option(option);
160 * Getting the current option value:
162 * boost::asio::ip::udp::socket socket(io_service);
164 * boost::asio::socket_base::do_not_route option;
165 * socket.get_option(option);
166 * bool is_set = option.value();
170 * Socket_Option, Boolean_Socket_Option.
172 #if defined(GENERATING_DOCUMENTATION)
173 typedef implementation_defined do_not_route;
175 typedef boost::asio::detail::socket_option::boolean<
176 BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_DONTROUTE)>
180 /// Socket option to send keep-alives.
182 * Implements the SOL_SOCKET/SO_KEEPALIVE socket option.
185 * Setting the option:
187 * boost::asio::ip::tcp::socket socket(io_service);
189 * boost::asio::socket_base::keep_alive option(true);
190 * socket.set_option(option);
194 * Getting the current option value:
196 * boost::asio::ip::tcp::socket socket(io_service);
198 * boost::asio::socket_base::keep_alive option;
199 * socket.get_option(option);
200 * bool is_set = option.value();
204 * Socket_Option, Boolean_Socket_Option.
206 #if defined(GENERATING_DOCUMENTATION)
207 typedef implementation_defined keep_alive;
209 typedef boost::asio::detail::socket_option::boolean<
210 BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_KEEPALIVE)> keep_alive;
213 /// Socket option for the send buffer size of a socket.
215 * Implements the SOL_SOCKET/SO_SNDBUF socket option.
218 * Setting the option:
220 * boost::asio::ip::tcp::socket socket(io_service);
222 * boost::asio::socket_base::send_buffer_size option(8192);
223 * socket.set_option(option);
227 * Getting the current option value:
229 * boost::asio::ip::tcp::socket socket(io_service);
231 * boost::asio::socket_base::send_buffer_size option;
232 * socket.get_option(option);
233 * int size = option.value();
237 * Socket_Option, Integer_Socket_Option.
239 #if defined(GENERATING_DOCUMENTATION)
240 typedef implementation_defined send_buffer_size;
242 typedef boost::asio::detail::socket_option::integer<
243 BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_SNDBUF)>
247 /// Socket option for the send low watermark.
249 * Implements the SOL_SOCKET/SO_SNDLOWAT socket option.
252 * Setting the option:
254 * boost::asio::ip::tcp::socket socket(io_service);
256 * boost::asio::socket_base::send_low_watermark option(1024);
257 * socket.set_option(option);
261 * Getting the current option value:
263 * boost::asio::ip::tcp::socket socket(io_service);
265 * boost::asio::socket_base::send_low_watermark option;
266 * socket.get_option(option);
267 * int size = option.value();
271 * Socket_Option, Integer_Socket_Option.
273 #if defined(GENERATING_DOCUMENTATION)
274 typedef implementation_defined send_low_watermark;
276 typedef boost::asio::detail::socket_option::integer<
277 BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_SNDLOWAT)>
281 /// Socket option for the receive buffer size of a socket.
283 * Implements the SOL_SOCKET/SO_RCVBUF socket option.
286 * Setting the option:
288 * boost::asio::ip::tcp::socket socket(io_service);
290 * boost::asio::socket_base::receive_buffer_size option(8192);
291 * socket.set_option(option);
295 * Getting the current option value:
297 * boost::asio::ip::tcp::socket socket(io_service);
299 * boost::asio::socket_base::receive_buffer_size option;
300 * socket.get_option(option);
301 * int size = option.value();
305 * Socket_Option, Integer_Socket_Option.
307 #if defined(GENERATING_DOCUMENTATION)
308 typedef implementation_defined receive_buffer_size;
310 typedef boost::asio::detail::socket_option::integer<
311 BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_RCVBUF)>
315 /// Socket option for the receive low watermark.
317 * Implements the SOL_SOCKET/SO_RCVLOWAT socket option.
320 * Setting the option:
322 * boost::asio::ip::tcp::socket socket(io_service);
324 * boost::asio::socket_base::receive_low_watermark option(1024);
325 * socket.set_option(option);
329 * Getting the current option value:
331 * boost::asio::ip::tcp::socket socket(io_service);
333 * boost::asio::socket_base::receive_low_watermark option;
334 * socket.get_option(option);
335 * int size = option.value();
339 * Socket_Option, Integer_Socket_Option.
341 #if defined(GENERATING_DOCUMENTATION)
342 typedef implementation_defined receive_low_watermark;
344 typedef boost::asio::detail::socket_option::integer<
345 BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_RCVLOWAT)>
346 receive_low_watermark;
349 /// Socket option to allow the socket to be bound to an address that is
352 * Implements the SOL_SOCKET/SO_REUSEADDR socket option.
355 * Setting the option:
357 * boost::asio::ip::tcp::acceptor acceptor(io_service);
359 * boost::asio::socket_base::reuse_address option(true);
360 * acceptor.set_option(option);
364 * Getting the current option value:
366 * boost::asio::ip::tcp::acceptor acceptor(io_service);
368 * boost::asio::socket_base::reuse_address option;
369 * acceptor.get_option(option);
370 * bool is_set = option.value();
374 * Socket_Option, Boolean_Socket_Option.
376 #if defined(GENERATING_DOCUMENTATION)
377 typedef implementation_defined reuse_address;
379 typedef boost::asio::detail::socket_option::boolean<
380 BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_REUSEADDR)>
384 /// Socket option to specify whether the socket lingers on close if unsent
387 * Implements the SOL_SOCKET/SO_LINGER socket option.
390 * Setting the option:
392 * boost::asio::ip::tcp::socket socket(io_service);
394 * boost::asio::socket_base::linger option(true, 30);
395 * socket.set_option(option);
399 * Getting the current option value:
401 * boost::asio::ip::tcp::socket socket(io_service);
403 * boost::asio::socket_base::linger option;
404 * socket.get_option(option);
405 * bool is_set = option.enabled();
406 * unsigned short timeout = option.timeout();
410 * Socket_Option, Linger_Socket_Option.
412 #if defined(GENERATING_DOCUMENTATION)
413 typedef implementation_defined linger;
415 typedef boost::asio::detail::socket_option::linger<
416 BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_LINGER)>
420 /// Socket option to report aborted connections on accept.
422 * Implements a custom socket option that determines whether or not an accept
423 * operation is permitted to fail with boost::asio::error::connection_aborted.
424 * By default the option is false.
427 * Setting the option:
429 * boost::asio::ip::tcp::acceptor acceptor(io_service);
431 * boost::asio::socket_base::enable_connection_aborted option(true);
432 * acceptor.set_option(option);
436 * Getting the current option value:
438 * boost::asio::ip::tcp::acceptor acceptor(io_service);
440 * boost::asio::socket_base::enable_connection_aborted option;
441 * acceptor.get_option(option);
442 * bool is_set = option.value();
446 * Socket_Option, Boolean_Socket_Option.
448 #if defined(GENERATING_DOCUMENTATION)
449 typedef implementation_defined enable_connection_aborted;
451 typedef boost::asio::detail::socket_option::boolean<
452 boost::asio::detail::custom_socket_option_level,
453 boost::asio::detail::enable_connection_aborted_option>
454 enable_connection_aborted;
457 /// (Deprecated: Use non_blocking().) IO control command to
458 /// set the blocking mode of the socket.
460 * Implements the FIONBIO IO control command.
464 * boost::asio::ip::tcp::socket socket(io_service);
466 * boost::asio::socket_base::non_blocking_io command(true);
467 * socket.io_control(command);
471 * IO_Control_Command, Boolean_IO_Control_Command.
473 #if defined(GENERATING_DOCUMENTATION)
474 typedef implementation_defined non_blocking_io;
476 typedef boost::asio::detail::io_control::non_blocking_io non_blocking_io;
479 /// IO control command to get the amount of data that can be read without
482 * Implements the FIONREAD IO control command.
486 * boost::asio::ip::tcp::socket socket(io_service);
488 * boost::asio::socket_base::bytes_readable command(true);
489 * socket.io_control(command);
490 * std::size_t bytes_readable = command.get();
494 * IO_Control_Command, Size_IO_Control_Command.
496 #if defined(GENERATING_DOCUMENTATION)
497 typedef implementation_defined bytes_readable;
499 typedef boost::asio::detail::io_control::bytes_readable bytes_readable;
502 /// The maximum length of the queue of pending incoming connections.
503 #if defined(GENERATING_DOCUMENTATION)
504 static const int max_connections = implementation_defined;
506 BOOST_ASIO_STATIC_CONSTANT(int, max_connections
507 = BOOST_ASIO_OS_DEF(SOMAXCONN));
511 /// Protected destructor to prevent deletion through this type.
520 #include <boost/asio/detail/pop_options.hpp>
522 #endif // BOOST_ASIO_SOCKET_BASE_HPP