3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Using Boost.Asio</title>
5 <link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7 <link rel="home" href="../boost_asio.html" title="Boost.Asio">
8 <link rel="up" href="../boost_asio.html" title="Boost.Asio">
9 <link rel="prev" href="overview/implementation.html" title="Platform-Specific Implementation Notes">
10 <link rel="next" href="tutorial.html" title="Tutorial">
12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13 <table cellpadding="2" width="100%"><tr>
14 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
15 <td align="center"><a href="../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../more/index.htm">More</a></td>
22 <div class="spirit-nav">
23 <a accesskey="p" href="overview/implementation.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../boost_asio.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../boost_asio.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="tutorial.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
26 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
27 <a name="boost_asio.using"></a><a class="link" href="using.html" title="Using Boost.Asio">Using Boost.Asio</a>
28 </h2></div></div></div>
30 <a name="boost_asio.using.h0"></a>
31 <span class="phrase"><a name="boost_asio.using.supported_platforms"></a></span><a class="link" href="using.html#boost_asio.using.supported_platforms">Supported
35 The following platforms and compilers have been tested:
37 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
39 Win32 and Win64 using Visual C++ 7.1 and Visual C++ 8.0.
45 Win32 using Cygwin. (<code class="computeroutput"><span class="identifier">__USE_W32_SOCKETS</span></code>
49 Linux (2.4 or 2.6 kernels) using g++ 3.3 or later.
52 Solaris using g++ 3.3 or later.
55 Mac OS X 10.4 using g++ 3.3 or later.
59 The following platforms may also work:
61 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
63 AIX 5.3 using XL C/C++ v9.
66 HP-UX 11i v3 using patched aC++ A.06.14.
69 QNX Neutrino 6.3 using g++ 3.3 or later.
72 Solaris using Sun Studio 11 or later.
75 Tru64 v5.1 using Compaq C++ v7.1.
78 Win32 using Borland C++ 5.9.2
82 <a name="boost_asio.using.h1"></a>
83 <span class="phrase"><a name="boost_asio.using.dependencies"></a></span><a class="link" href="using.html#boost_asio.using.dependencies">Dependencies</a>
86 The following libraries must be available in order to link programs that use
89 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
91 Boost.System for the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">system</span><span class="special">::</span><span class="identifier">error_code</span></code>
92 and <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">system</span><span class="special">::</span><span class="identifier">system_error</span></code> classes.
95 Boost.Regex (optional) if you use any of the <a class="link" href="reference/read_until.html" title="read_until"><code class="computeroutput"><span class="identifier">read_until</span><span class="special">()</span></code></a>
96 or <a class="link" href="reference/async_read_until.html" title="async_read_until"><code class="computeroutput"><span class="identifier">async_read_until</span><span class="special">()</span></code></a>
97 overloads that take a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">regex</span></code>
100 <li class="listitem">
101 <a href="http://www.openssl.org" target="_top">OpenSSL</a> (optional) if you use
102 Boost.Asio's SSL support.
106 Furthermore, some of the examples also require the Boost.Thread, Boost.Date_Time
107 or Boost.Serialization libraries.
109 <div class="note"><table border="0" summary="Note">
111 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/src/images/note.png"></td>
112 <th align="left">Note</th>
114 <tr><td align="left" valign="top"><p>
115 With MSVC or Borland C++ you may want to add <code class="computeroutput"><span class="special">-</span><span class="identifier">DBOOST_DATE_TIME_NO_LIB</span></code> and <code class="computeroutput"><span class="special">-</span><span class="identifier">DBOOST_REGEX_NO_LIB</span></code>
116 to your project settings to disable autolinking of the Boost.Date_Time and
117 Boost.Regex libraries respectively. Alternatively, you may choose to build
118 these libraries and link to them.
122 <a name="boost_asio.using.h2"></a>
123 <span class="phrase"><a name="boost_asio.using.building_boost_libraries"></a></span><a class="link" href="using.html#boost_asio.using.building_boost_libraries">Building
127 You may build the subset of Boost libraries required to use Boost.Asio and
128 its examples by running the following command from the root of the Boost download
131 <pre class="programlisting">bjam --with-system --with-thread --with-date_time --with-regex --with-serialization stage
134 This assumes that you have already built <code class="computeroutput"><span class="identifier">bjam</span></code>.
135 Consult the Boost.Build documentation for more details.
138 <a name="boost_asio.using.h3"></a>
139 <span class="phrase"><a name="boost_asio.using.optional_separate_compilation"></a></span><a class="link" href="using.html#boost_asio.using.optional_separate_compilation">Optional
140 separate compilation</a>
143 By default, Boost.Asio is a header-only library. However, some developers may
144 prefer to build Boost.Asio using separately compiled source code. To do this,
145 add <code class="computeroutput"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">asio</span><span class="special">/</span><span class="identifier">impl</span><span class="special">/</span><span class="identifier">src</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code> to one (and only one) source file in a
146 program, then build the program with <code class="computeroutput"><span class="identifier">BOOST_ASIO_SEPARATE_COMPILATION</span></code>
147 defined in the project/compiler settings. Alternatively, <code class="computeroutput"><span class="identifier">BOOST_ASIO_DYN_LINK</span></code>
148 may be defined to build a separately-compiled Boost.Asio as part of a shared
152 If using Boost.Asio's SSL support, you will also need to add <code class="computeroutput"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">asio</span><span class="special">/</span><span class="identifier">ssl</span><span class="special">/</span><span class="identifier">impl</span><span class="special">/</span><span class="identifier">src</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code>.
155 <a name="boost_asio.using.h4"></a>
156 <span class="phrase"><a name="boost_asio.using.macros"></a></span><a class="link" href="using.html#boost_asio.using.macros">Macros</a>
159 The macros listed in the table below may be used to control the behaviour of
162 <div class="informaltable"><table class="table">
183 <code class="computeroutput"><span class="identifier">BOOST_ASIO_ENABLE_BUFFER_DEBUGGING</span></code>
188 Enables Boost.Asio's buffer debugging support, which can help identify
189 when invalid buffers are used in read or write operations (e.g. if
190 a std::string object being written is destroyed before the write
191 operation completes).
194 When using Microsoft Visual C++, this macro is defined automatically
195 if the compiler's iterator debugging support is enabled, unless
196 <code class="computeroutput"><span class="identifier">BOOST_ASIO_DISABLE_BUFFER_DEBUGGING</span></code>
200 When using g++, this macro is defined automatically if standard library
201 debugging is enabled (<code class="computeroutput"><span class="identifier">_GLIBCXX_DEBUG</span></code>
202 is defined), unless <code class="computeroutput"><span class="identifier">BOOST_ASIO_DISABLE_BUFFER_DEBUGGING</span></code>
210 <code class="computeroutput"><span class="identifier">BOOST_ASIO_DISABLE_BUFFER_DEBUGGING</span></code>
215 Explictly disables Boost.Asio's buffer debugging support.
222 <code class="computeroutput"><span class="identifier">BOOST_ASIO_DISABLE_DEV_POLL</span></code>
227 Explicitly disables <code class="literal">/dev/poll</code> support on Solaris,
228 forcing the use of a <code class="computeroutput"><span class="identifier">select</span></code>-based
236 <code class="computeroutput"><span class="identifier">BOOST_ASIO_DISABLE_EPOLL</span></code>
241 Explicitly disables <code class="computeroutput"><span class="identifier">epoll</span></code>
242 support on Linux, forcing the use of a <code class="computeroutput"><span class="identifier">select</span></code>-based
250 <code class="computeroutput"><span class="identifier">BOOST_ASIO_DISABLE_EVENTFD</span></code>
255 Explicitly disables <code class="computeroutput"><span class="identifier">eventfd</span></code>
256 support on Linux, forcing the use of a pipe to interrupt blocked
257 epoll/select system calls.
264 <code class="computeroutput"><span class="identifier">BOOST_ASIO_DISABLE_KQUEUE</span></code>
269 Explicitly disables <code class="computeroutput"><span class="identifier">kqueue</span></code>
270 support on Mac OS X and BSD variants, forcing the use of a <code class="computeroutput"><span class="identifier">select</span></code>-based implementation.
277 <code class="computeroutput"><span class="identifier">BOOST_ASIO_DISABLE_IOCP</span></code>
282 Explicitly disables I/O completion ports support on Windows, forcing
283 the use of a <code class="computeroutput"><span class="identifier">select</span></code>-based
291 <code class="computeroutput"><span class="identifier">BOOST_ASIO_DISABLE_THREADS</span></code>
296 Explicitly disables Boost.Asio's threading support, independent of
297 whether or not Boost as a whole supports threads.
304 <code class="computeroutput"><span class="identifier">BOOST_ASIO_NO_WIN32_LEAN_AND_MEAN</span></code>
309 By default, Boost.Asio will automatically define <code class="computeroutput"><span class="identifier">WIN32_LEAN_AND_MEAN</span></code>
310 when compiling for Windows, to minimise the number of Windows SDK
311 header files and features that are included. The presence of <code class="computeroutput"><span class="identifier">BOOST_ASIO_NO_WIN32_LEAN_AND_MEAN</span></code>
312 prevents <code class="computeroutput"><span class="identifier">WIN32_LEAN_AND_MEAN</span></code>
320 <code class="computeroutput"><span class="identifier">BOOST_ASIO_NO_NOMINMAX</span></code>
325 By default, Boost.Asio will automatically define <code class="computeroutput"><span class="identifier">NOMINMAX</span></code>
326 when compiling for Windows, to suppress the definition of the <code class="computeroutput"><span class="identifier">min</span><span class="special">()</span></code>
327 and <code class="computeroutput"><span class="identifier">max</span><span class="special">()</span></code>
328 macros. The presence of <code class="computeroutput"><span class="identifier">BOOST_ASIO_NO_NOMINMAX</span></code>
329 prevents <code class="computeroutput"><span class="identifier">NOMINMAX</span></code>
337 <code class="computeroutput"><span class="identifier">BOOST_ASIO_NO_DEFAULT_LINKED_LIBS</span></code>
342 When compiling for Windows using Microsoft Visual C++ or Borland
343 C++, Boost.Asio will automatically link in the necessary Windows
344 SDK libraries for sockets support (i.e. <code class="literal">ws2_32.lib</code>
345 and <code class="literal">mswsock.lib</code>, or <code class="literal">ws2.lib</code>
346 when building for Windows CE). The <code class="computeroutput"><span class="identifier">BOOST_ASIO_NO_DEFAULT_LINKED_LIBS</span></code>
347 macro prevents these libraries from being linked.
354 <code class="computeroutput"><span class="identifier">BOOST_ASIO_SOCKET_STREAMBUF_MAX_ARITY</span></code>
359 Determines the maximum number of arguments that may be passed to
360 the <code class="computeroutput"><span class="identifier">basic_socket_streambuf</span></code>
361 class template's <code class="computeroutput"><span class="identifier">connect</span></code>
362 member function. Defaults to 5.
369 <code class="computeroutput"><span class="identifier">BOOST_ASIO_SOCKET_IOSTREAM_MAX_ARITY</span></code>
374 Determines the maximum number of arguments that may be passed to
375 the <code class="computeroutput"><span class="identifier">basic_socket_iostream</span></code>
376 class template's constructor and <code class="computeroutput"><span class="identifier">connect</span></code>
377 member function. Defaults to 5.
384 <code class="computeroutput"><span class="identifier">BOOST_ASIO_ENABLE_CANCELIO</span></code>
389 Enables use of the <code class="computeroutput"><span class="identifier">CancelIo</span></code>
390 function on older versions of Windows. If not enabled, calls to
391 <code class="computeroutput"><span class="identifier">cancel</span><span class="special">()</span></code>
392 on a socket object will always fail with <code class="computeroutput"><span class="identifier">asio</span><span class="special">::</span><span class="identifier">error</span><span class="special">::</span><span class="identifier">operation_not_supported</span></code>
393 when run on Windows XP, Windows Server 2003, and earlier versions
394 of Windows. When running on Windows Vista, Windows Server 2008, and
395 later, the <code class="computeroutput"><span class="identifier">CancelIoEx</span></code>
396 function is always used.
399 The <code class="computeroutput"><span class="identifier">CancelIo</span></code> function
400 has two issues that should be considered before enabling its use:
403 * It will only cancel asynchronous operations that were initiated
404 in the current thread.
407 * It can appear to complete without error, but the request to cancel
408 the unfinished operations may be silently ignored by the operating
409 system. Whether it works or not seems to depend on the drivers that
413 For portable cancellation, consider using one of the following alternatives:
416 * Disable asio's I/O completion port backend by defining BOOST_ASIO_DISABLE_IOCP.
419 * Use the socket object's close() function to simultaneously cancel
420 the outstanding operations and close the socket.
427 <code class="computeroutput"><span class="identifier">BOOST_ASIO_NO_TYPEID</span></code>
432 Disables uses of the <code class="computeroutput"><span class="keyword">typeid</span></code>
433 operator in Boost.Asio. Defined automatically if <code class="computeroutput"><span class="identifier">BOOST_NO_TYPEID</span></code>
441 <code class="computeroutput"><span class="identifier">BOOST_ASIO_HASH_MAP_BUCKETS</span></code>
446 Determines the number of buckets in Boost.Asio's internal <code class="computeroutput"><span class="identifier">hash_map</span></code> objects. The value should
447 be a comma separated list of prime numbers, in ascending order. The
448 <code class="computeroutput"><span class="identifier">hash_map</span></code> implementation
449 will automatically increase the number of buckets as the number of
450 elements in the map increases.
456 * Defining <code class="computeroutput"><span class="identifier">BOOST_ASIO_HASH_MAP_BUCKETS</span></code>
457 to <code class="computeroutput"><span class="number">1021</span></code> means that the
458 <code class="computeroutput"><span class="identifier">hash_map</span></code> objects
459 will always contain 1021 buckets, irrespective of the number of elements
463 * Defining <code class="computeroutput"><span class="identifier">BOOST_ASIO_HASH_MAP_BUCKETS</span></code>
464 to <code class="computeroutput"><span class="number">53</span><span class="special">,</span><span class="number">389</span><span class="special">,</span><span class="number">1543</span></code> means that the <code class="computeroutput"><span class="identifier">hash_map</span></code>
465 objects will initially contain 53 buckets. The number of buckets
466 will be increased to 389 and then 1543 as elements are added to the
474 <a name="boost_asio.using.h5"></a>
475 <span class="phrase"><a name="boost_asio.using.mailing_list"></a></span><a class="link" href="using.html#boost_asio.using.mailing_list">Mailing
479 A mailing list specifically for Boost.Asio may be found on <a href="http://sourceforge.net/mail/?group_id=122478" target="_top">SourceForge.net</a>.
480 Newsgroup access is provided via <a href="http://dir.gmane.org/gmane.comp.lib.boost.asio.user" target="_top">Gmane</a>.
483 <a name="boost_asio.using.h6"></a>
484 <span class="phrase"><a name="boost_asio.using.wiki"></a></span><a class="link" href="using.html#boost_asio.using.wiki">Wiki</a>
487 Users are encouraged to share examples, tips and FAQs on the Boost.Asio wiki,
488 which is located at <a href="http://think-async.com/Asio/" target="_top">http://think-async.com/Asio/</a>.
491 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
492 <td align="left"></td>
493 <td align="right"><div class="copyright-footer">Copyright © 2003-2017 Christopher M. Kohlhoff<p>
494 Distributed under the Boost Software License, Version 1.0. (See accompanying
495 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
500 <div class="spirit-nav">
501 <a accesskey="p" href="overview/implementation.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../boost_asio.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../boost_asio.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="tutorial.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>