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