Comparison of open-source C/C ++ Network Libraries

Source: Internet
Author: User
Tags epoll

In the open-source C/C ++ network library, there are only a few commonly used ones. Ace should be the most well-known in the industry, but it is just a heavyweight big guy, lightweight libevent, libev, and boost ASIO.

Ace is a large middleware product with around 0.2 million lines of code. It is too ambitious. There are a bunch of design patterns, with a layer-by-layer architecture. When using ace, it depends on the situation, you can use it on that layer. Supports cross-platform.

Boost ASIO is an asynchronous Io library that encapsulates common socket operations and simplifies socket-based program development. Supports cross-platform.

Libevent is a network library written in C language. It officially supports Linux-like operating systems. The latest version adds iocp support for Windows. Because iocp is asynchronous Io, it is completely different from the poll model, epoll model, and FreeBSD's kqueue in Linux in terms of usage, just like the reactor and proactor modes in Ace, you need to change your mind when using them. If there are no special requirements on performance, use the select model in libevent to implement cross-platform operations. The select model can span windows,
Linux, UNIX, Solaris, and other systems.

Libev is written in C language and only supports Linux libraries. I used to encapsulate only the epoll model in my previous studies. I don't know whether the new version has been improved. The method is similar to libevent, but it is very concise. The Code volume is the minimum one, which is thousands of lines of code. Obviously, this Code cannot be supported across platforms. If you only need to run it in Linux, you can use this library.

The ACE network library is in use and is always confused about memory management. The allocated memory needs to be released without knowing where to release it. Ace is a library used for research, it can be said that the encapsulation in this book has implemented all the patterns listed in the Design Patterns in the code. It feels like using Java. If you want to use ACE as your network library, never use it as a network library. You need to use it as a framework. If you only want to use its network library, you do not need to use ACE, it is too huge to learn. However, if you use it as a framework, you will feel that it is really nice to use. There are all such things, such as thread pools, memory pools, timers, and recursive locks, it is very convenient. Boost ASIO is more intuitive in terms of memory management. The following is a simple comparison with Ace.

1. Layered Architecture:
The bottom layer of ACE is the c-style OS adaptation layer, the top layer is the c ++-based wrap class, And the next layer is some frameworks (accpetor, connector, reactor, proactor, etc ), the top layer is the Framework Service.
Boost. similar to ASIO, the bottom layer is the OS adaptation layer. The top layer is some template classes, the top layer is the parameterization of the template classes (TCP/UDP), and the top layer is the service, it only has one framework, io_service.
Livevent abstracts multiplexing models in different operating systems. You can use different models to provide services through event functions.

2. Scope:
Ace includes logs, IPC, thread pool, shared memory, Configuration Services, recursive locks, and timers.
ASIO only involves socket and provides simple thread operations.
Libevent only provides simple Network API encapsulation, thread pool, memory pool, and recursive lock.

3. Design Mode:
Ace mainly applies reactor and proactor.
ASIO mainly applies proactor.
Libevent is in reactor mode.

4. Thread Scheduling:
The reactor of ACE is single-thread scheduling, and proactor supports multi-thread scheduling.
ASIO supports single-thread and multi-thread scheduling.
The libevent Thread Scheduling requires you to register different event handles on your own.

5. Event dispatch processing:
Ace is mainly used to register the handler class. When an event is assigned, it calls its handler's virtual hook function. Implement Virtual functions such as ace_handler/ace_svc_handler/ace_event_handler.
ASIO is a hanlder event dispatch based on function objects. Any function may become a hanlder with less virtual table maintenance and better scheduling than Ace.
Libevent implements event distribution based on the registered Event Callback Function.

6. Release Method:
Ace is open-source and free, and does not rely on the 3rd-party library. When an application uses it, it publishes a dynamic library through dynamic links.
ASIO is open-source and free-of-charge and relies on boost. When using an application, you only need to include the header file and do not need dynamic libraries.
Libevent is open-source and free, and is generally compiled as a static library for use.

7. Portability:
Ace supports multiple platforms and has no portability issues. It is said that socket programming has many buckets in Linux.
ASIO supports multiple platforms and has no portability issues.
Libevent mainly supports Linux and FreeBSD platforms. It supports the select model on other platforms, and the efficiency is not too high.

8. Development difficulty:
Developing applications based on ACE requires a high level of programmer requirements. To make good use of it, you must have a good understanding of its framework. Under its framework, developers often create a new object and do not know where to release it.

Developing applications based on ASIO requires programmers to be familiar with function objects, function pointers, and boost: bind in the boost library. Memory management and control.

It is relatively easy to develop applications based on libevent. For details, refer to the open-source application memcached, which uses the libevent library.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.