前几天有空来学习大名鼎鼎的Boost库,由于英文看着费劲,就开始自己翻译。费了半天劲,才发现原来已经有前辈做过了,非常感谢…^_^. 转自网络。下面只给出中文版的,有疑惑的请直接链接到官网对照即可(文中已给出链接)。
Boost.Asio是一个跨平台的C + +库,它用现代C++方法为网络编程人员提供一致的异步I/O模型。
Using
Boost.Asio
如何在你的应用程序中使用Boost.Asio库,以及关于库依赖和所支持平台信息。
Tutorial
介绍使用Boost.Asio必备的基本概念,同时示范如何使用Boost.Aaio开发简单的客户端/服务器程序。
Examples
在更加复杂的应用程序中使用Boost.Asio的示例。
Reference
类和函数的详细参考
Design
Boost.Asio库的基本原理及设计思路。
已测试的平台和编译器:
- Win32 and Win64 using Visual C++ 7.1 and Visual C++ 8.0.
- Win32 using MinGW.
- Win32 using Cygwin. (__USE_W32_SOCKETSmust be defined.)
- Linux (2.4 or 2.6 kernels) using g++ 3.3 or later.
- Solaris using g++ 3.3 or later.
- Mac OS X 10.4 using g++ 3.3 or later.
以下的平台可能也可以使用:
- AIX 5.3 using XL C/C++ v9.
- HP-UX 11i v3 using patched aC++ A.06.14.
- QNX Neutrino 6.3 using g++ 3.3 or later.
- Solaris using Sun Studio 11 or later.
- Tru64 v5.1 using Compaq C++ v7.1.
- Win32 using Borland C++ 5.9.2
依赖性:
以下是使用Boost.Asio必需的链接库:
- Boost.System 中的boost::system::error_code和boost::system::system_error类。
- Boost.Regex (可选)。read_until()或async_read_until()函数的重载形式都需要boost::regex参数。
如果你使用它们,则需要Boost.Regex库。
- OpenSSL(可选) 。如果需要Boost.Asio支持SSL,则需要OpenSSL库。
另外,一些例子需要提供Boost.Thread,Boost.Date_Time 或Boost.Serialization 库的支持。
注意:
使用MSVC或Borland C++,你可能需要在“工程设置”中分别添加-DBOOST_DATE_TIME_NO_LIB和-DBOOST_REGEX_NO_LIB声明,分别禁止Boost.Date_Time和Boost.Regex的自动链接,当然你也可以这样做:build这两个库,然后链接。
-----------------------------------------------------------------------------------------------------
Building
Boost Libraries
编译Boost库:
You may build the subset of Boost libraries required to use Boost.Asio and its examples by running the following command from the root of the Boost download package:
你可以在下载包的根目录下执行如下的命令来编译Boost.Asio所必需的Boost库子集。
bjam--with-system--with-thread--with-date_time--with-regex--with-serializationstage
This assumes that you have already builtbjam. Consult the Boost.Build documentation for more details.
这里假设你已经编译了bjam。请参考Boost.Build文档以获得更多信息。
---------------------------------------------------------------------------------------------------------------------------
宏
The macros listed in the table below may be used to control the behaviour of Boost.Asio.
下表中的宏用来控制Boost.Asio的状态。
Macro
Description
BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
|
Enables Boost.Asio's buffer debugging support, which can help identify when invalid buffers are used in read or write operations (e.g. if a std::string object being written is destroyed before the write operation completes).
When using Microsoft Visual C++, this macro is defined automatically if the compiler's iterator debugging support is enabled, unlessBOOST_ASIO_DISABLE_BUFFER_DEBUGGINGhas been
defined.
When using g++, this macro is defined automatically if standard library debugging is enabled (_GLIBCXX_DEBUGis defined), unlessBOOST_ASIO_DISABLE_BUFFER_DEBUGGINGhas
been defined.
|
BOOST_ASIO_DISABLE_BUFFER_DEBUGGING
|
Explictly disables Boost.Asio's buffer debugging support.
|
BOOST_ASIO_DISABLE_DEV_POLL
|
Explicitly disables /dev/poll support on Solaris, forcing the use of aselect-based implementation.
|
BOOST_ASIO_DISABLE_EPOLL
|
Explicitly disablesepollsupport on Linux, forcing the use of aselect-based implementation.
|
BOOST_ASIO_DISABLE_KQUEUE
|
Explicitly disableskqueuesupport on Mac OS X and BSD variants, forcing the use of aselect-based implementation.
|
BOOST_ASIO_DISABLE_IOCP
|
Explicitly disables I/O completion ports support on Windows, forcing the use of aselect-based implementation.
|
BOOST_ASIO_NO_WIN32_LEAN_AND_MEAN
|
By default, Boost.Asio will automatically defineWIN32_LEAN_AND_MEANwhen compiling for Windows, to minimise the number of Windows SDK header files and features that are included.
The presence ofBOOST_ASIO_NO_WIN32_LEAN_AND_MEANpreventsWIN32_LEAN_AND_MEANfrom being defined.
|
BOOST_ASIO_NO_DEFAULT_LINKED_LIBS
|
When compiling for Windows using Microsoft Visual C++ or Borland C++, Boost.Asio will automatically link in the necessary Windows SDK libraries for sockets support (i.e. ws2_32.lib and mswsock.lib, or ws2.lib when building
for Windows CE). TheBOOST_ASIO_NO_DEFAULT_LINKED_LIBSmacro prevents these libraries from being linked.
|
BOOST_ASIO_SOCKET_STREAMBUF_MAX_ARITY
|
Determines the maximum number of arguments that may be passed to thebasic_socket_streambufclass template'sconnectmember function.
Defaults to 5.
|
BOOST_ASIO_SOCKET_IOSTREAM_MAX_ARITY
|
Determines the maximum number of arguments that may be passed to thebasic_socket_iostreamclass template's constructor andconnectmember
function. Defaults to 5.
|
BOOST_ASIO_ENABLE_CANCELIO
|
Enables use of theCancelIofunction on older versions of Windows. If not enabled, calls tocancel()on
a socket object will always fail withasio::error::operation_not_supportedwhen
run on Windows XP, Windows Server 2003, and earlier versions of Windows. When running on Windows Vista, Windows Server 2008, and later, theCancelIoExfunction is always used.
TheCancelIofunction has two issues that should be considered before enabling its use:
* It will only cancel asynchronous operations that were initiated in the current thread.
* It can appear to complete without error, but the request to cancel the unfinished operations may be silently ignored by the operating system. Whether it works or not seems to depend on the drivers that are installed.
For portable cancellation, consider using one of the following alternatives:
* Disable asio's I/O completion port backend by defining BOOST_ASIO_DISABLE_IOCP.
* Use the socket object's close() function to simultaneously cancel the outstanding operations and close the socket.
|
基本技能
本指南的第一部分主要介绍使用Asio工具包所需要了解的基本概念。在进入复杂的网络编程世界之前,这些示例程序将举一些使用简单异步定时器的例子。
- Timer1、使用同步定时器
- Timer2、使用异步定时器
- Timer3、回调函数绑定参数
- Timer4、成员函数作为回调函数
- Timer5、多线程回调同步
介绍套接字
这部分的实例主要介绍如何使用Asio开发简单的客户端/服务器程序。这些程序都基于同时支持TCP和UDP协议的daytime协议。
前三个程序用TCP实现daytime协议。
- Daytime1、同步TCP daytime客户端
- Daytime2、同步TCP daytime服务器
- Daytime3、异步TCP daytime服务器
接下来的三个程序用UDP实现daytime协议。
- Daytime4、同步UDP daytime客户端
- Daytime5、同步UDP daytime服务器
- Daytime6、异步UDP daytime服务器
本部分的最后一个程序演示了asio怎样将TCP和UDP服务器简易的组合到一个程序里。
- Daytime7、结合了TCP/UDP的同步服务器
Boost.Asio是一个跨平台的C + +库,它用现代C++方法为网络编程人员提供一致的异步I/O模型。
Using
Boost.Asio
如何在你的应用程序中使用Boost.Asio库,以及关于库依赖和所支持平台信息。
Tutorial
介绍使用Boost.Asio必备的基本概念,同时示范如何使用Boost.Aaio开发简单的客户端/服务器程序。
Examples
在更加复杂的应用程序中使用Boost.Asio的示例。
Reference
类和函数的详细参考
Design
Boost.Asio库的基本原理及设计思路。
已测试的平台和编译器:
- Win32 and Win64 using Visual C++ 7.1 and Visual C++ 8.0.
- Win32 using MinGW.
- Win32 using Cygwin. (__USE_W32_SOCKETSmust be defined.)
- Linux (2.4 or 2.6 kernels) using g++ 3.3 or later.
- Solaris using g++ 3.3 or later.
- Mac OS X 10.4 using g++ 3.3 or later.
以下的平台可能也可以使用:
- AIX 5.3 using XL C/C++ v9.
- HP-UX 11i v3 using patched aC++ A.06.14.
- QNX Neutrino 6.3 using g++ 3.3 or later.
- Solaris using Sun Studio 11 or later.
- Tru64 v5.1 using Compaq C++ v7.1.
- Win32 using Borland C++ 5.9.2
依赖性:
以下是使用Boost.Asio必需的链接库:
- Boost.System 中的boost::system::error_code和boost::system::system_error类。
- Boost.Regex (可选)。read_until()或async_read_until()函数的重载形式都需要boost::regex参数。
如果你使用它们,则需要Boost.Regex库。
- OpenSSL(可选) 。如果需要Boost.Asio支持SSL,则需要OpenSSL库。
另外,一些例子需要提供Boost.Thread,Boost.Date_Time 或Boost.Serialization 库的支持。
注意:
使用MSVC或Borland C++,你可能需要在“工程设置”中分别添加-DBOOST_DATE_TIME_NO_LIB和-DBOOST_REGEX_NO_LIB声明,分别禁止Boost.Date_Time和Boost.Regex的自动链接,当然你也可以这样做:build这两个库,然后链接。
-----------------------------------------------------------------------------------------------------
Building
Boost Libraries
编译Boost库:
You may build the subset of Boost libraries required to use Boost.Asio and its examples by running the following command from the root of the Boost download package:
你可以在下载包的根目录下执行如下的命令来编译Boost.Asio所必需的Boost库子集。
bjam--with-system--with-thread--with-date_time--with-regex--with-serializationstage
This assumes that you have already builtbjam. Consult the Boost.Build documentation for more details.
这里假设你已经编译了bjam。请参考Boost.Build文档以获得更多信息。
---------------------------------------------------------------------------------------------------------------------------
宏
The macros listed in the table below may be used to control the behaviour of Boost.Asio.
下表中的宏用来控制Boost.Asio的状态。
Macro
Description
BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
|
Enables Boost.Asio's buffer debugging support, which can help identify when invalid buffers are used in read or write operations (e.g. if a std::string object being written is destroyed before the write operation completes).
When using Microsoft Visual C++, this macro is defined automatically if the compiler's iterator debugging support is enabled, unlessBOOST_ASIO_DISABLE_BUFFER_DEBUGGINGhas been
defined.
When using g++, this macro is defined automatically if standard library debugging is enabled (_GLIBCXX_DEBUGis defined), unlessBOOST_ASIO_DISABLE_BUFFER_DEBUGGINGhas
been defined.
|
BOOST_ASIO_DISABLE_BUFFER_DEBUGGING
|
Explictly disables Boost.Asio's buffer debugging support.
|
BOOST_ASIO_DISABLE_DEV_POLL
|
Explicitly disables /dev/poll support on Solaris, forcing the use of aselect-based implementation.
|
BOOST_ASIO_DISABLE_EPOLL
|
Explicitly disablesepollsupport on Linux, forcing the use of aselect-based implementation.
|
BOOST_ASIO_DISABLE_KQUEUE
|
Explicitly disableskqueuesupport on Mac OS X and BSD variants, forcing the use of aselect-based implementation.
|
BOOST_ASIO_DISABLE_IOCP
|
Explicitly disables I/O completion ports support on Windows, forcing the use of aselect-based implementation.
|
BOOST_ASIO_NO_WIN32_LEAN_AND_MEAN
|
By default, Boost.Asio will automatically defineWIN32_LEAN_AND_MEANwhen compiling for Windows, to minimise the number of Windows SDK header files and features that are included.
The presence ofBOOST_ASIO_NO_WIN32_LEAN_AND_MEANpreventsWIN32_LEAN_AND_MEANfrom being defined.
|
BOOST_ASIO_NO_DEFAULT_LINKED_LIBS
|
When compiling for Windows using Microsoft Visual C++ or Borland C++, Boost.Asio will automatically link in the necessary Windows SDK libraries for sockets support (i.e. ws2_32.lib and mswsock.lib, or ws2.lib when building
for Windows CE). TheBOOST_ASIO_NO_DEFAULT_LINKED_LIBSmacro prevents these libraries from being linked.
|
BOOST_ASIO_SOCKET_STREAMBUF_MAX_ARITY
|
Determines the maximum number of arguments that may be passed to thebasic_socket_streambufclass template'sconnectmember function.
Defaults to 5.
|
BOOST_ASIO_SOCKET_IOSTREAM_MAX_ARITY
|
Determines the maximum number of arguments that may be passed to thebasic_socket_iostreamclass template's constructor andconnectmember
function. Defaults to 5.
|
BOOST_ASIO_ENABLE_CANCELIO
|
Enables use of theCancelIofunction on older versions of Windows. If not enabled, calls tocancel()on
a socket object will always fail withasio::error::operation_not_supportedwhen
run on Windows XP, Windows Server 2003, and earlier versions of Windows. When running on Windows Vista, Windows Server 2008, and later, theCancelIoExfunction is always used.
TheCancelIofunction has two issues that should be considered before enabling its use:
* It will only cancel asynchronous operations that were initiated in the current thread.
* It can appear to complete without error, but the request to cancel the unfinished operations may be silently ignored by the operating system. Whether it works or not seems to depend on the drivers that are installed.
For portable cancellation, consider using one of the following alternatives:
* Disable asio's I/O completion port backend by defining BOOST_ASIO_DISABLE_IOCP.
* Use the socket object's close() function to simultaneously cancel the outstanding operations and close the socket.
|
基本技能
本指南的第一部分主要介绍使用Asio工具包所需要了解的基本概念。在进入复杂的网络编程世界之前,这些示例程序将举一些使用简单异步定时器的例子。
- Timer1、使用同步定时器
- Timer2、使用异步定时器
- Timer3、回调函数绑定参数
- Timer4、成员函数作为回调函数
- Timer5、多线程回调同步
介绍套接字
这部分的实例主要介绍如何使用Asio开发简单的客户端/服务器程序。这些程序都基于同时支持TCP和UDP协议的daytime协议。
前三个程序用TCP实现daytime协议。
- Daytime1、同步TCP daytime客户端
- Daytime2、同步TCP daytime服务器
- Daytime3、异步TCP daytime服务器
接下来的三个程序用UDP实现daytime协议。
- Daytime4、同步UDP daytime客户端
- Daytime5、同步UDP daytime服务器
- Daytime6、异步UDP daytime服务器
本部分的最后一个程序演示了asio怎样将TCP和UDP服务器简易的组合到一个程序里。
- Daytime7、结合了TCP/UDP的同步服务器
分享到:
相关推荐
Boost.Asio C++ Network Programming(2nd).pdf Boost.Asio C++ Network Programming(2nd).pdf Boost.Asio C++ Network Programming(2nd).pdf
Boost.Asio C++ Network Programming Cookbook.pdf Boost.Asio C++ Network Programming Cookbook.pdf
Boost.Asio C++ Network Programming
Boost.Asio.C++.Network.Programming.,想了解的可以看看
翻译了“Overview”、“Using Boost.Asio”、“Tutorial”、“Examples”的完整章节。 [“Networking TS compatibility”](https://www.boost.org/doc/libs/1_72_0/doc/html/boost_asio/net_ts.html)的第二个表格未...
该c++ web server基于boost.asio库编写,同时支持http和https协议。该工程基于vs2015编译通过,相关配置和说明见readme.txt
Boost.Asio provides an excellent abstraction over it, making sure that with a minimal amount of coding, you can create beautiful client-server applications and have tons of fun doing it. And it ...
Boost.Asio C++ 网络编程 PDF 高清 非扫描 中文版
内置gitbook boost.asio网络编程所有源代码,采用c++17编写
The Boost.Asio library is aimed at reducing accidental complexity by introducing type systems and exploiting object-oriented methods, and decreasing the development time by providing high degrees of ...
st_asio_wrapper是一组类,功能是对boost.asio的包装(调试环境:boost-1.50.0),目的是简化boost.asio开发; 其特点是效率高、跨平台、完全异步,当然这是从boost.asio继承而来; 自动重连,数据透明传输,自动...
Boost.Asio C++ Network Programming源代码
简单来说,Boost.Asio是一个跨平台的、主要用于网络和其他一些底层输入/输出编程的C++库。 关于网络处理已经有很多解决方案,但是Boost.Asio是目前为止最优的方案。它在2005年就被包含进Boost,然后被大量Boost的...
st_asio_wrapper是一组类,功能是对boost.asio的包装(调试环境:boost-1.50.0),目的是简化boost.asio开发; 其特点是效率高、跨平台、完全异步,当然这是从boost.asio继承而来; 自动重连,数据透明传输,自动...
最新版本,最新排版
Boost.Asio C++ Network Programming 2nd edition. kindle文件转换的,还是可以复制粘贴的。
Boost.asio学习 下载地址: https://legacy.gitbook.com/book/mmoaay/boost-asio-cpp-network-programming-chinese/details
Boost.Asio.C++.Network.Programming 2013
oost.Asio C++ Network Programming Cookbook is filled with real-world problems related to network programming that show the Boost.Asio library in motion.