Asio and Boost.Asio


元旦过后我就开始准备自己搞一个epoll的封装库,以期扔掉这个无比庞大的boost(对x86的服务器系统来说是还OK,但对一些嵌入式的应用来说,实在吃不消)。
但是始终卡在client端socket关闭后,server端针对broken pipe的signal(多线程中的signal)的处理上,这个问题一拖就拖了将近一个星期,实在汗顔。
后来实在有点火了,就准备照boost asio来扒一个下来,结果,扒着扒着发现asio原来完全可以独立于boost来运行(作为一个独立的library)。
这下真的搞的火大了。OMG,我又浪费了将近一周的生命…

以下是来自asio作者Christopher Kohlhoff对asio与boost.asio的区别说明:

Asio and Boost.Asio

Asio comes in two variants: (non-Boost) Asio and Boost.Asio. The differences between the two are outlined below.

What are the differences in the source code?

— Asio is in a namespace called asio::, whereas Boost.Asio puts everything under boost::asio::.

— The main Asio header file is called asio.hpp. The corresponding header in Boost.Asio is boost/asio.hpp. All other headers are similarly changed.

— Any macros used by or defined in Asio are prefixed with ASIO_. In Boost.Asio they are prefixed with BOOST_ASIO_.

— Asio includes a class for launching threads: asio::thread. Boost.Asio does not include this class, to avoid overlap with the Boost.Thread library

— Boost.Asio uses the Boost.System library to provide support for error codes ( boost::system::error_code and boost::system::system_error). Asio includes these under its own namespace ( asio::error_code and asio::system_error). The Boost.System version of these classes currently supports better extensibility for user-defined error codes.

— Asio is header-file-only and for most uses does not require linking against any Boost library. Boost.Asio always requires that you link against the Boost.System library, and also against Boost.Thread if you want to launch threads using boost::thread.

 

Where do I get a release package?

Asio is available for download from SourceForge, in a package named asio-X.Y.Z.tar.gz (or .tar.bz2 or .zip).

Boost.Asio is included in the Boost 1.35 distribution. It is also available as a separate package on SourceForge, named boost_asio_X_Y_Z.tar.gz. The latter is intended to be copied over the top of an existing Boost source code distribution.

 

Where are the source code repositories?

Asio uses a sourceforge-hosted CVS repository. Details of how to access it may be found here. It may also be browsed via the web.

Boost.Asio is checked into Boost’s subversion repository.

 

How are both versions maintained?

All development is done in the Asio CVS repository. The source is periodically converted into Boost format using a script called boostify.pl, and the changes merged into the Boost subversion repository.

 

Will Asio be discontinued now that Boost.Asio is included with Boost?

No. There are projects using Asio and they will continue to be supported.

 

Should I use Asio or Boost.Asio?

It depends. Here are some things to consider:

— If you prefer the convenience of header-file-only libraries then using Asio over Boost.Asio is suggested.

— If you must use a version of Boost older than 1.35 then Boost.Asio is not included. You can use Boost.Asio by copying it over the top of your Boost distribution (see above), but not everyone is comfortable doing this. In that case, using Asio over Boost.Asio is suggested.

— New versions of both the Asio and Boost.Asio packages will be created on a faster release cycle than that followed by Boost. If you want to use the latest features you can still use Boost.Asio as long as you are happy to copy it over the top of your Boost distribution. If you don’t want to do this, use Asio rather than Boost.Asio.

 

Can Asio and Boost.Asio coexist in the same program?

Yes. Since they use different namespaces there should be no conflicts, although obviously the types themselves are not interchangeable. (In case you’re wondering why you might want to do this, consider a situation where a program is using third party libraries that are also using Asio internally.)

Leave a comment

Your email address will not be published. Required fields are marked *