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