ae4dffb09ce6f090d1e332df48fbd31286ee28b4
[platform/upstream/boost.git] / doc / html / boost_asio / using.html
1 <html>
2 <head>
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.78.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">
11 </head>
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>
20 </tr></table>
21 <hr>
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>
24 </div>
25 <div class="section">
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>
29 <h4>
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
32       Platforms</a>
33     </h4>
34 <p>
35       The following platforms and compilers have been tested:
36     </p>
37 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
38 <li class="listitem">
39           Win32 and Win64 using Visual C++ 7.1 and Visual C++ 8.0.
40         </li>
41 <li class="listitem">
42           Win32 using MinGW.
43         </li>
44 <li class="listitem">
45           Win32 using Cygwin. (<code class="computeroutput"><span class="identifier">__USE_W32_SOCKETS</span></code>
46           must be defined.)
47         </li>
48 <li class="listitem">
49           Linux (2.4 or 2.6 kernels) using g++ 3.3 or later.
50         </li>
51 <li class="listitem">
52           Solaris using g++ 3.3 or later.
53         </li>
54 <li class="listitem">
55           Mac OS X 10.4 using g++ 3.3 or later.
56         </li>
57 </ul></div>
58 <p>
59       The following platforms may also work:
60     </p>
61 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
62 <li class="listitem">
63           AIX 5.3 using XL C/C++ v9.
64         </li>
65 <li class="listitem">
66           HP-UX 11i v3 using patched aC++ A.06.14.
67         </li>
68 <li class="listitem">
69           QNX Neutrino 6.3 using g++ 3.3 or later.
70         </li>
71 <li class="listitem">
72           Solaris using Sun Studio 11 or later.
73         </li>
74 <li class="listitem">
75           Tru64 v5.1 using Compaq C++ v7.1.
76         </li>
77 <li class="listitem">
78           Win32 using Borland C++ 5.9.2
79         </li>
80 </ul></div>
81 <h4>
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>
84     </h4>
85 <p>
86       The following libraries must be available in order to link programs that use
87       Boost.Asio:
88     </p>
89 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
90 <li class="listitem">
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.
93         </li>
94 <li class="listitem">
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>
98           parameter.
99         </li>
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.
103         </li>
104 </ul></div>
105 <p>
106       Furthermore, some of the examples also require the Boost.Thread, Boost.Date_Time
107       or Boost.Serialization libraries.
108     </p>
109 <div class="note"><table border="0" summary="Note">
110 <tr>
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>
113 </tr>
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.
119       </p></td></tr>
120 </table></div>
121 <h4>
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
124       Boost Libraries</a>
125     </h4>
126 <p>
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
129       package:
130     </p>
131 <pre class="programlisting">bjam --with-system --with-thread --with-date_time --with-regex --with-serialization stage
132 </pre>
133 <p>
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.
136     </p>
137 <h4>
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>
141     </h4>
142 <p>
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">&lt;</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">&gt;</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
149       library.
150     </p>
151 <p>
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">&lt;</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">&gt;</span></code>.
153     </p>
154 <h4>
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>
157     </h4>
158 <p>
159       The macros listed in the table below may be used to control the behaviour of
160       Boost.Asio.
161     </p>
162 <div class="informaltable"><table class="table">
163 <colgroup>
164 <col>
165 <col>
166 </colgroup>
167 <thead><tr>
168 <th>
169               <p>
170                 Macro
171               </p>
172             </th>
173 <th>
174               <p>
175                 Description
176               </p>
177             </th>
178 </tr></thead>
179 <tbody>
180 <tr>
181 <td>
182               <p>
183                 <code class="computeroutput"><span class="identifier">BOOST_ASIO_ENABLE_BUFFER_DEBUGGING</span></code>
184               </p>
185             </td>
186 <td>
187               <p>
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).
192               </p>
193               <p>
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>
197                 has been defined.
198               </p>
199               <p>
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>
203                 has been defined.
204               </p>
205             </td>
206 </tr>
207 <tr>
208 <td>
209               <p>
210                 <code class="computeroutput"><span class="identifier">BOOST_ASIO_DISABLE_BUFFER_DEBUGGING</span></code>
211               </p>
212             </td>
213 <td>
214               <p>
215                 Explictly disables Boost.Asio's buffer debugging support.
216               </p>
217             </td>
218 </tr>
219 <tr>
220 <td>
221               <p>
222                 <code class="computeroutput"><span class="identifier">BOOST_ASIO_DISABLE_DEV_POLL</span></code>
223               </p>
224             </td>
225 <td>
226               <p>
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
229                 implementation.
230               </p>
231             </td>
232 </tr>
233 <tr>
234 <td>
235               <p>
236                 <code class="computeroutput"><span class="identifier">BOOST_ASIO_DISABLE_EPOLL</span></code>
237               </p>
238             </td>
239 <td>
240               <p>
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
243                 implementation.
244               </p>
245             </td>
246 </tr>
247 <tr>
248 <td>
249               <p>
250                 <code class="computeroutput"><span class="identifier">BOOST_ASIO_DISABLE_EVENTFD</span></code>
251               </p>
252             </td>
253 <td>
254               <p>
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.
258               </p>
259             </td>
260 </tr>
261 <tr>
262 <td>
263               <p>
264                 <code class="computeroutput"><span class="identifier">BOOST_ASIO_DISABLE_KQUEUE</span></code>
265               </p>
266             </td>
267 <td>
268               <p>
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.
271               </p>
272             </td>
273 </tr>
274 <tr>
275 <td>
276               <p>
277                 <code class="computeroutput"><span class="identifier">BOOST_ASIO_DISABLE_IOCP</span></code>
278               </p>
279             </td>
280 <td>
281               <p>
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
284                 implementation.
285               </p>
286             </td>
287 </tr>
288 <tr>
289 <td>
290               <p>
291                 <code class="computeroutput"><span class="identifier">BOOST_ASIO_DISABLE_THREADS</span></code>
292               </p>
293             </td>
294 <td>
295               <p>
296                 Explicitly disables Boost.Asio's threading support, independent of
297                 whether or not Boost as a whole supports threads.
298               </p>
299             </td>
300 </tr>
301 <tr>
302 <td>
303               <p>
304                 <code class="computeroutput"><span class="identifier">BOOST_ASIO_NO_WIN32_LEAN_AND_MEAN</span></code>
305               </p>
306             </td>
307 <td>
308               <p>
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>
313                 from being defined.
314               </p>
315             </td>
316 </tr>
317 <tr>
318 <td>
319               <p>
320                 <code class="computeroutput"><span class="identifier">BOOST_ASIO_NO_NOMINMAX</span></code>
321               </p>
322             </td>
323 <td>
324               <p>
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>
330                 from being defined.
331               </p>
332             </td>
333 </tr>
334 <tr>
335 <td>
336               <p>
337                 <code class="computeroutput"><span class="identifier">BOOST_ASIO_NO_DEFAULT_LINKED_LIBS</span></code>
338               </p>
339             </td>
340 <td>
341               <p>
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.
348               </p>
349             </td>
350 </tr>
351 <tr>
352 <td>
353               <p>
354                 <code class="computeroutput"><span class="identifier">BOOST_ASIO_SOCKET_STREAMBUF_MAX_ARITY</span></code>
355               </p>
356             </td>
357 <td>
358               <p>
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.
363               </p>
364             </td>
365 </tr>
366 <tr>
367 <td>
368               <p>
369                 <code class="computeroutput"><span class="identifier">BOOST_ASIO_SOCKET_IOSTREAM_MAX_ARITY</span></code>
370               </p>
371             </td>
372 <td>
373               <p>
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.
378               </p>
379             </td>
380 </tr>
381 <tr>
382 <td>
383               <p>
384                 <code class="computeroutput"><span class="identifier">BOOST_ASIO_ENABLE_CANCELIO</span></code>
385               </p>
386             </td>
387 <td>
388               <p>
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.
397               </p>
398               <p>
399                 The <code class="computeroutput"><span class="identifier">CancelIo</span></code> function
400                 has two issues that should be considered before enabling its use:
401               </p>
402               <p>
403                 * It will only cancel asynchronous operations that were initiated
404                 in the current thread.
405               </p>
406               <p>
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
410                 are installed.
411               </p>
412               <p>
413                 For portable cancellation, consider using one of the following alternatives:
414               </p>
415               <p>
416                 * Disable asio's I/O completion port backend by defining BOOST_ASIO_DISABLE_IOCP.
417               </p>
418               <p>
419                 * Use the socket object's close() function to simultaneously cancel
420                 the outstanding operations and close the socket.
421               </p>
422             </td>
423 </tr>
424 <tr>
425 <td>
426               <p>
427                 <code class="computeroutput"><span class="identifier">BOOST_ASIO_NO_TYPEID</span></code>
428               </p>
429             </td>
430 <td>
431               <p>
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>
434                 is defined.
435               </p>
436             </td>
437 </tr>
438 <tr>
439 <td>
440               <p>
441                 <code class="computeroutput"><span class="identifier">BOOST_ASIO_HASH_MAP_BUCKETS</span></code>
442               </p>
443             </td>
444 <td>
445               <p>
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.
451               </p>
452               <p>
453                 Some examples:
454               </p>
455               <p>
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
460                 in the map.
461               </p>
462               <p>
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
467                 map.
468               </p>
469             </td>
470 </tr>
471 </tbody>
472 </table></div>
473 <h4>
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
476       List</a>
477     </h4>
478 <p>
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>.
481     </p>
482 <h4>
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>
485     </h4>
486 <p>
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>.
489     </p>
490 </div>
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 &#169; 2003-2014 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>)
496       </p>
497 </div></td>
498 </tr></table>
499 <hr>
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>
502 </div>
503 </body>
504 </html>