1[/ 2 / Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com) 3 / 4 / Distributed under the Boost Software License, Version 1.0. (See accompanying 5 / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 /] 7 8[section:using Using Boost.Asio] 9 10[heading Supported Platforms] 11 12The following platform and compiler combinations are regularly tested: 13 14* Linux using g++ 4.1 or later 15* Linux using clang 3.2 or later 16* FreeBSD using g++ 4.1 or later 17* macOS using Xcode 8 or later 18* Win32 using Visual C++ 9.0 or later 19* Win32 using g++ 4.1 or later (MinGW) 20* Win64 using Visual C++ 9.0 or later 21 22The following platforms may also work: 23 24* AIX 25* Android 26* HP-UX 27* iOS 28* NetBSD 29* OpenBSD 30* QNX Neutrino 31* Solaris 32* Tru64 33* Win32 using Cygwin. (`__USE_W32_SOCKETS` must be defined.) 34 35[heading Dependencies] 36 37The following libraries must be available in order to link programs that use 38Boost.Asio: 39 40* Boost.System for the `boost::system::error_code` and 41`boost::system::system_error` classes. 42 43* Boost.Coroutine (optional) if you use [link boost_asio.reference.spawn 44`spawn()`] to launch coroutines. 45 46* Boost.Regex (optional) if you use any of the [link 47boost_asio.reference.read_until `read_until()`] or [link 48boost_asio.reference.async_read_until `async_read_until()`] overloads that take 49a `boost::regex` parameter. 50 51* [@http://www.openssl.org OpenSSL] (optional) if you use Boost.Asio's SSL 52support. 53 54Furthermore, some of the examples also require the Boost.Thread, 55Boost.Date_Time or Boost.Serialization libraries. 56 57[note With MSVC or Borland C++ you may want to add `-DBOOST_DATE_TIME_NO_LIB` 58and `-DBOOST_REGEX_NO_LIB` to your project settings to disable autolinking of 59the Boost.Date_Time and Boost.Regex libraries respectively. Alternatively, you 60may choose to build these libraries and link to them.] 61 62[heading Building Boost Libraries] 63 64You may build the subset of Boost libraries required to use Boost.Asio and its 65examples by running the following command from the root of the Boost download 66package: 67 68[pre 69 b2 --with-system --with-thread --with-date_time --with-regex --with-serialization stage 70] 71 72This assumes that you have already built `b2`. Consult the Boost.Build 73documentation for more details. 74 75[/ 76 77[heading Compiling Programs With Boost.Asio] 78 79Consider the following minimal Boost.Asio program [^simple.cpp]: 80 81 #include <boost/asio.hpp> 82 #include <iostream> 83 #include <ostream> 84 85 int main() 86 { 87 boost::asio::ip::tcp::iostream s("www.boost.org", "http"); 88 89 s << "GET / HTTP/1.0\r\n"; 90 s << "Host: www.boost.org\r\n"; 91 s << "\r\n" << std::flush; 92 93 std::cout << s.rdbuf(); 94 95 return 0; 96 } 97 98The following compiler commands may be used to build the program (note that the 99name of the `boost_system` library may vary depending on the compiler version): 100 101[table 102 [ 103 [OS] 104 [Compiler] 105 [Command] 106 ] 107 [ 108 [FreeBSD] 109 [g++] 110 [[^g++ -I['boost_root] -pthread simple.cpp -L['boost_root]/stage/lib -lboost_system-gcc]] 111 ] 112 [ 113 [Linux] 114 [g++] 115 [[^g++ -I['boost_root] -pthread simple.cpp -L['boost_root]/stage/lib -lboost_system-gcc41]] 116 ] 117 [ 118 [macOS] 119 [g++] 120 [[^g++ -I['boost_root] simple.cpp -L['boost_root]/stage/lib -lboost_system]] 121 ] 122 [ 123 [Solaris] 124 [g++] 125 [[^g++ -I['boost_root] simple.cpp -L['boost_root]/stage/lib -lboost_system -lsocket -lnsl -lpthread]] 126 ] 127 [ 128 [Windows] 129 [MSVC 9.0] 130 [[^cl /EHsc /GR /MT /I['boost_root] /D_WIN32_WINNT=0x500 simple.cpp /link /libpath:['boost_root]/stage/lib]] 131 ] 132] 133 134] 135 136[heading Optional separate compilation] 137 138By default, Boost.Asio is a header-only library. However, some developers may 139prefer to build Boost.Asio using separately compiled source code. To do this, 140add `#include <boost/asio/impl/src.hpp>` to one (and only one) source file in a 141program, then build the program with `BOOST_ASIO_SEPARATE_COMPILATION` defined 142in the project\/compiler settings. Alternatively, `BOOST_ASIO_DYN_LINK` may be 143defined to build a separately-compiled Boost.Asio as part of a shared library. 144 145If using Boost.Asio's SSL support, you will also need to add `#include 146<boost/asio/ssl/impl/src.hpp>`. 147 148[heading Macros] 149 150The macros listed in the table below may be used to control the behaviour of 151Boost.Asio. 152 153[table 154 [[Macro][Description]] 155 [ 156 [`BOOST_ASIO_ENABLE_BUFFER_DEBUGGING`] 157 [ 158 Enables Boost.Asio's buffer debugging support, which can help identify when 159 invalid buffers are used in read or write operations (e.g. if a 160 std::string object being written is destroyed before the write operation 161 completes). 162 163 When using Microsoft Visual C++ 11.0 or later, this macro is defined 164 automatically if the compiler's iterator debugging support is enabled, 165 unless `BOOST_ASIO_DISABLE_BUFFER_DEBUGGING` has been defined. 166 167 When using g++, this macro is defined automatically if standard library 168 debugging is enabled (`_GLIBCXX_DEBUG` is defined), unless 169 `BOOST_ASIO_DISABLE_BUFFER_DEBUGGING` has been defined. 170 ] 171 ] 172 [ 173 [`BOOST_ASIO_DISABLE_BUFFER_DEBUGGING`] 174 [ 175 Explictly disables Boost.Asio's buffer debugging support. 176 ] 177 ] 178 [ 179 [`BOOST_ASIO_DISABLE_DEV_POLL`] 180 [ 181 Explicitly disables [^/dev/poll] support on Solaris, forcing the use of 182 a `select`-based implementation. 183 ] 184 ] 185 [ 186 [`BOOST_ASIO_DISABLE_EPOLL`] 187 [ 188 Explicitly disables `epoll` support on Linux, forcing the use of a 189 `select`-based implementation. 190 ] 191 ] 192 [ 193 [`BOOST_ASIO_DISABLE_EVENTFD`] 194 [ 195 Explicitly disables `eventfd` support on Linux, forcing the use of a 196 pipe to interrupt blocked epoll/select system calls. 197 ] 198 ] 199 [ 200 [`BOOST_ASIO_DISABLE_KQUEUE`] 201 [ 202 Explicitly disables `kqueue` support on macOS and BSD variants, 203 forcing the use of a `select`-based implementation. 204 ] 205 ] 206 [ 207 [`BOOST_ASIO_DISABLE_IOCP`] 208 [ 209 Explicitly disables I/O completion ports support on Windows, forcing the 210 use of a `select`-based implementation. 211 ] 212 ] 213 [ 214 [`BOOST_ASIO_DISABLE_THREADS`] 215 [ 216 Explicitly disables Boost.Asio's threading support, independent of whether 217 or not Boost as a whole supports threads. 218 ] 219 ] 220 [ 221 [`BOOST_ASIO_NO_WIN32_LEAN_AND_MEAN`] 222 [ 223 By default, Boost.Asio will automatically define `WIN32_LEAN_AND_MEAN` when 224 compiling for Windows, to minimise the number of Windows SDK header files 225 and features that are included. The presence of 226 `BOOST_ASIO_NO_WIN32_LEAN_AND_MEAN` prevents `WIN32_LEAN_AND_MEAN` from 227 being defined. 228 ] 229 ] 230 [ 231 [`BOOST_ASIO_NO_NOMINMAX`] 232 [ 233 By default, Boost.Asio will automatically define `NOMINMAX` when 234 compiling for Windows, to suppress the definition of the `min()` and 235 `max()` macros. The presence of `BOOST_ASIO_NO_NOMINMAX` prevents 236 `NOMINMAX` from being defined. 237 ] 238 ] 239 [ 240 [`BOOST_ASIO_NO_DEFAULT_LINKED_LIBS`] 241 [ 242 When compiling for Windows using Microsoft Visual C++ or Borland C++, Boost.Asio 243 will automatically link in the necessary Windows SDK libraries for sockets 244 support (i.e. [^ws2_32.lib] and [^mswsock.lib], or [^ws2.lib] when 245 building for Windows CE). The `BOOST_ASIO_NO_DEFAULT_LINKED_LIBS` macro 246 prevents these libraries from being linked. 247 ] 248 ] 249 [ 250 [`BOOST_ASIO_ENABLE_CANCELIO`] 251 [ 252 Enables use of the `CancelIo` function on older versions of Windows. If 253 not enabled, calls to `cancel()` on a socket object will always fail with 254 `asio::error::operation_not_supported` when run on Windows XP, Windows 255 Server 2003, and earlier versions of Windows. When running on Windows 256 Vista, Windows Server 2008, and later, the `CancelIoEx` function is 257 always used. 258 259 The `CancelIo` function has two issues that should be considered before 260 enabling its use: 261 262 * It will only cancel asynchronous operations that were initiated in the 263 current thread. 264 265 * It can appear to complete without error, but the request 266 to cancel the unfinished operations may be silently ignored by the 267 operating system. Whether it works or not seems to depend on the 268 drivers that are installed. 269 270 For portable cancellation, consider using one of the following 271 alternatives: 272 273 * Disable asio's I/O completion port backend by defining 274 BOOST_ASIO_DISABLE_IOCP. 275 276 * Use the socket object's close() function to simultaneously 277 cancel the outstanding operations and close the socket. 278 ] 279 ] 280 [ 281 [`BOOST_ASIO_NO_TYPEID`] 282 [ 283 Disables uses of the `typeid` operator in Boost.Asio. Defined 284 automatically if `BOOST_NO_TYPEID` is defined. 285 ] 286 ] 287 [ 288 [`BOOST_ASIO_HASH_MAP_BUCKETS`] 289 [ 290 Determines the number of buckets in Boost.Asio's internal `hash_map` 291 objects. The value should be a comma separated list of prime numbers, in 292 ascending order. The `hash_map` implementation will automatically 293 increase the number of buckets as the number of elements in the map 294 increases. 295 296 Some examples: 297 298 * Defining `BOOST_ASIO_HASH_MAP_BUCKETS` to `1021` means that the 299 `hash_map` objects will always contain 1021 buckets, irrespective of 300 the number of elements in the map. 301 302 * Defining `BOOST_ASIO_HASH_MAP_BUCKETS` to `53,389,1543` means that the 303 `hash_map` objects will initially contain 53 buckets. The number of 304 buckets will be increased to 389 and then 1543 as elements are added to 305 the map. 306 ] 307 ] 308] 309 310[heading Mailing List] 311 312A mailing list specifically for Boost.Asio may be found on 313[@http://sourceforge.net/mail/?group_id=122478 SourceForge.net]. Newsgroup 314access is provided via [@http://dir.gmane.org/gmane.comp.lib.boost.asio.user 315Gmane]. 316 317[heading Wiki] 318 319Users are encouraged to share examples, tips and FAQs on the Boost.Asio wiki, 320which is located at [@http://think-async.com/Asio/]. 321 322[endsect] 323