- 1 Description
- 1.1 Library composition
- 1.2 Function module composition
- 1.2.1 Network communication library
- 1.2.2 Network IO event engine
- 1.2.3 Web server framework
- 1.2.4 Thread and thread pool module
- 1.2.5 HTTP protocol
- 1.2.6 Redis client library
- 1.2.7 MIME protocol library
- 1.2.8 Network coroutine library
- 1.2.9 Database related
- 1.2.10 K-V disk storage module (zdb) for numeric keys
- 1.2.11 Other function libraries
- 1.2.11.1 Common data structure module
- 1.2.11.2 Memory operation module
- 1.2.11.3 Common string operation module
- 1.2.11.4 File Directory module
- 1.2.11.5 Read configuration file module
- 1.2.11.6 File queue processing library
- 1.2.11.7 Json parsing library
- 1.2.11.8 Xml parsing library
- 1.2.11.9 Common coding library
- 2 Platform support and compilation
- 3 Description of directory structure
- 4 Who are using acl
- 5 License
- 6 Reference
The acl project is a cross-platform (supporting LINUX, WIN32, Solaris, MacOS, FreeBSD) network communication library and server programming framework, while providing more useful functional libraries. Through this library, users can easily write server programs, WEB applications, and database applications that support multiple modes (multi-threaded, multi-process, non-blocking, trigger, UDP, and coroutine). In addition, the library also provides client communication libraries for common applications (such as: HTTP, SMTP, ICMP, redis, memcache, beanstalk, handler socket), common streaming codec library: XML/JSON/MIME/BASE64/UUCODE/ QPCODE/RFC2047 etc.
This project consists of 5 libraries and a large number of examples. The description of the five libraries is as follows:
- lib_acl: This library is the most basic library, the other four libraries are dependent on the library; the library is implemented in C language.
- lib_protocol: This library mainly implements the http protocol and the icmp/ping protocol; the library is implemented in C language.
- lib_acl_cpp: This library encapsulates the lib_acl/lib_protocol libraries in C++ and adds some other valuable functional applications.
- lib_fiber: This library supports the coroutine library, directly hooks the system read/write API, and supports high-concurrency network programming with epoll.
- lib_dict: This library mainly implements the dictionary storage of KEY-VALUE, which also depends on BDB, CDB and tokyocabinet libraries.
- lib_tls: This library encapsulates the openssl library so that the communication mode of lib_acl can support ssl.
This module is the most basic streaming communication module for the entire acl network communication. It not only supports network streaming, but also supports file streaming. It mainly supports:
- Read data by line, compatible with \r\n under win32, and compatible with the end of \n under UNIX
- Read data by line but require automatic removal of the trailing \n or \r\n
- Read data as a string separator
- Read the specified length of data
- Try to read a row of data or try to read the specified length of data
- Detect network IO status
- Write a row of data
- Write data by formatter, similar to fprintf
- File stream location operation, similar to fseek
- Write a set of data at once, similar to writev under unix
- Truncate the file, similar to ftrunk
- Get the file size
- Get the current file stream pointer location, similar to ftell
- Get the file size
- Obtain the local address and remote address of the network stream
This module mainly supports network server monitoring (supports TCP/UDP/UNIX domain socket), network client connection (supports TCP/UNIX domain socket), DNS domain name query and result cache (supports calling system gethostbyname/getaddrinfo function and direct Send DNS protocol two ways), socket (socket) operation and take the local network card and other functions.
Support non-blocking mode connection, read (by row read, specified length read), write (write line, write specified length, write a set of data) and other operations.
It mainly supports common network application protocols, such as: HTTP, SMTP, ICMP, in which HTTP and ICMP modules implement blocking and non-blocking communication methods. In addition, the HTTP protocol supports server and client in C++ version of lib_acl_cpp. Two communication methods, when used as a server, support the interface usage similar to JAVA HttpServlet. When used as a client mode, it supports connection pool and cluster management. The module supports both cookie, session, and HTTP MIME file upload. Rich functions such as block transfer, automatic character set conversion, automatic decompression, and breakpoint resume.
Support memcached, beanstalk, handler socket client communication library, the communication library supports connection pool mode.
Supports select (UNIX/LINUX/WIN32), poll (UNIX/LINUX), epoll (LINUX), kqueue (BSD), devpoll (solaris), iocp (WIN32), window message (WIN32) and other system event engines, and supports Reactor And Proactor two programming models.
This module is the most important module in acl, and provides the infrastructure commonly used in server programming. The server framework is derived from the famous Postfix. It has been expanded on the basis of the following. The main service models that have been supported are:
One connection to a process, the advantage of this model is that the programming is simple, safe and stable, and the disadvantage is that the degree of concurrency is not high;
Each child process handles all client connections by a group of threads in the thread pool. The IO event trigger mode is used. The connection is bound to a thread only when the connection has data readable. The thread is returned immediately after processing. For the thread pool, the biggest advantage of this model is that it can handle a large number of client connections with a small number of threads, and the programming is relatively simple (relative to the non-blocking model);
Each child process consists of a single non-blocking thread that handles a large number of foreign client connections (similar to nginx/squid/ircd) in a completely non-blocking IO manner. The advantage of this model is that it has high processing efficiency and low resource consumption. Can handle a large number of client connections, the disadvantage is that programming is more complicated;
Although the non-blocking service model can obtain large concurrent processing capability, the programming complexity is high. The coroutine model combines the features of large concurrent processing and low programming complexity, enabling programmers to easily implement sequential IO programming. Business logic;
The model is mainly used to support the UDP network process and the service model is added;
The model instance is mainly used to process the background service process of some scheduled tasks (similar to the system's crontab).
The sub-process utility in the server framework adopts the semi-resident service model, supports the sub-process pre-boot mechanism, the maximum and minimum process number control, the sub-process abnormal alarm, and the single process to listen to multiple addresses (can simultaneously listen to TCP/UDP sockets and UNIX). Domain sockets), child process security control, log output to syslog-ng, multi-process TCP connection uniformity; configuration file-driven mode, one configuration file per service, convenient process management and online upgrade of service process.
Provides a cross-platform support for the Posix-compliant thread interface (WIN32 support); the thread pool module minimizes lock conflicts in thread task allocation (used in the multi-process multi-threaded service model in the acl server framework).
Provides a complete HTTP protocol implementation, supports HTTP/1.0, 1.1 version; supports both client mode and server mode:
- Support connection pool mode;
- Support chunked block transfer;
- Support compressed transmission;
- Support SSL encrypted transmission;
- Support for resumed breakpoints;
- Support setting/acquisition of cookies;
- Support Websocket.
- Support Java-like HttpServlet usage;
- Support chunked block transfer;
- Support compressed transmission;
- Support SSL encrypted transmission;
- Support for resumed breakpoints;
- Support setting/acquisition of cookies;
- Support HTTP MIME format;
- Support Websocket.
- Support redis cluster mode and non-cluster mode;
- Support connection pool mode;
- Divide into separate C++ classes according to the redis data structure type;
- Each command is mapped to 1 to more functions. Specific content reference: [Use the acl library to write efficient C++ redis client application] (http://zsxxsz.iteye.com/blog/2184744)
- Support streaming MIME data parsing;
- Support MIME RFC2045, RFC2047, RFC822.
Direct hook system The underlying IO API, in conjunction with epoll, implements a high-concurrency, high-performance programming framework for network IO. This module enables some native common blocking network libraries (such as client libraries such as mysql/redis/http) to directly support high Concurrent network operation; by using this module, the programmer uses the sequential thinking programming method to change the blocking mode to the non-blocking mode inside the coroutine library, thus greatly improving the network concurrency and processing performance.
Designed a unified database operation interface and connection pool processing, currently supports sqlite/mysql/postgresql.
Take the KEY/VALUE block storage method, because the KEY is limited to the numeric type, you only need the memory calculation to calculate the position of the KEY, and the KEY stores the location of the VALUE, so you only need two disk positioning for any data query. (I used this method to replace K-V storage using B-trees such as BSD and TC when doing traffic statistics storage.)
The module provides common hash tables (and multiple hash algorithms), dynamic arrays, doubly linked lists, balanced binary trees, queues, binary search trees, 256-fork matching trees, and other array structures; provides a unified data structure traversal method (using acl_foreach).
This module provides three memory pool models:
- Basic memory mode: The system's malloc/free API is encapsulated internally to provide security measures such as memory verification. This method also provides an external registration interface that allows users to register their own memory allocation models. ;
- memory slice (slab) mode: allocate multiple fixed-length memory chains according to different sizes, which can effectively reduce memory fragmentation and greatly improve memory allocation efficiency;
- memory chain mode: Allocate small memory of different lengths on one memory page, which can use memory very effectively and reduce memory waste.
Supports string matching lookup, pre (post) comparison, string splitting, string case conversion, H2B/B2H conversion, URL encoding/decoding, etc.
Support multi-level directory creation, multi-level directory scanning, file handle caching, etc., while processing multi-level directories in a round-robin manner, avoiding the potential for stack overflow in recursive mode.
Supports reading the configuration file of the name=value format. When the value is long, you can use the backslash () to wrap the line, and use the configuration table to extract the configuration items in the configuration file.
Supports the creation, scanning, and deletion of multiple sets of directory queue files; it is commonly used in service programs for temporary file queue scheduling.
Supports streaming parsing of json data while supporting json packet assembly.
Support streaming methods to parse xml data while supporting xml packet assembly.
It also includes codecs such as rfc2047, url, base64, uucode, qpcode, charset, etc. These decoding libraries are all streamed and are suitable for multiple network IO models (blocking/non-blocking TCP, UDP).
The entire project currently supports Linux (AS4, 5, 6, CS4, 5, 6, ubuntu), Windows, MacOS, FreeBSD, Solaris, Android, IOS.
- Linux/UNIX: The compiler is gcc, enter the lib_acl/lib_protocol/lib_acl_cpp directory directly in the terminal command line mode, run the make command.
- Windows: Can be compiled with VC2003/VC2008/VC2010/VC2012/vc2013/vc2015. (If you need to compile with VC6/VC2005, you can refer to the compilation conditions of VC2003).
- MacOS: Compiled with xcode.
- Support for CMake cross-platform compilation
There are a few things to keep in mind when using dynamic libraries in a WIN32 environment:
- When using the dynamic library of lib_acl, it needs to be predefined in the user's project: ACL_DLL;
- When using the HTTP library or ICMP library in the lib_protocol dynamic library, you need to predefine HTTP_DLL or ICMP_DLL in the project;
- When using the dynamic library of lib_acl_cpp, you need to predefine ACL_CPP_DLL in the project. If you use the VC2003 compiler environment, you need to predefine VC2003.
- When using the dynamic library of lib_dict, you need to predefine DICT_DLL in the project;
- When using a dynamic library of lib_tls, you need to predefine TLS_DLL in your project.
- Detailed compilation process, see: [compilation and use of acl library] (BUILD.md)
- init : mainly used to initialize the acl base library
- stdlib: is a relatively basic function library. In the stdlib/ root directory, it mainly includes some functions related to logging, network/file stream processing, VSTRING buffer operation, etc. There are two directories under stdlib/, as follows :
- 2.1 common : This directory is mainly used for some commonly used data structures and algorithmic function libraries, such as hash tables, linked lists, queues, dynamic arrays, stacks, caches, balanced binary trees, pattern matching trees, etc.
- 2.2 memory : This directory mainly contains function libraries related to memory operations, such as memory base allocation and verification, memory pool management, memory slice management, etc.
- 2.3 filedir: This directory mainly contains libraries related to directory traversal, directory creation, etc.
- 2.4 configure : This directory mainly contains the analysis library of the configuration file;
- 2.5 iostuff: This directory mainly contains some commonly used function libraries for IO operations, such as read/write timeout, setting the blocking mode of IO handles, etc.
- 2.6 string : This directory mainly contains some commonly used string manipulation libraries, providing more flexible and efficient string manipulation functions than standard C;
- 2.7 debug : Mainly used to assist in debugging memory leaks and other functions;
- 2.8 sys: is mainly a package function library of APIs related to different operating system platforms;
- **net: is a function library related to network operation, including network monitoring, network connection, DNS query, socket parameter setting and other functions;
- 3.1 connect : Mainly a function library related to network connection, including network connection, domain socket connection, etc.;
- 3.2 listen : Mainly related to the network monitoring function library, including network monitoring, domain socket monitoring, etc.;
- 3.3 dns: Mainly related to the DNS domain name query, including the encapsulation of interfaces such as gethostbyname, and the ability to directly send UDP packets according to the RFC1035 standard.
- **event: Mainly encapsulates system API interfaces such as select/poll/epoll/iocp/win message/kqueue/devpoll, which makes handling network events more flexible, efficient, and simple. It also includes timer interface, many in acl. Network applications will use these interfaces, such as aio, master and other modules; **
- aio: A function that mainly contains asynchronous operations on the network. This library is very efficient when dealing with high concurrency, and provides a more advanced calling method than the base API, than using a file like libevent. The library is simpler and thread safe;
- msg: mainly contains thread-based message events and network-based message events;
- thread: Mainly encapsulates the basic thread API under each OS platform, which makes the external interface consistent, eliminates the difference of the platform, and also provides a semi-resident thread pool function library, as well as thread-local variables. Expansion
- db: Mainly some database-related function libraries, defines a common database connection pool framework (and implements mysql connection pool instance); a simple in-memory database (by hash table, linked list, balanced binary tree) Combined); ZDB data storage engine, which is an efficient digital key-based storage engine;
- proctl: the parent and child process control function library under the win32 platform;
- code : Common coding function library, including base64 codec, URL codec and some Chinese character set encoding;
- unit_test : contains a library of functions for testing C language units;
- xml: is a streaming xml parser and constructor that supports blocking and blocking network communication;
- json: is a streaming json parser and constructor that supports blocking and blocking network communications;
- **master: is a server framework that supports multiple server modes in the UNIX environment. Currently, it supports multi-process mode, multi-process multi-thread mode, multi-process non-blocking mode, multi-process trigger mode and UDP communication mode; *
- http: HTTP protocol related library, support HTTP/1.1, communication mode supports synchronous/asynchronous mode
- icmp: icmp/ping protocol library, supporting synchronous/asynchronous communication
- smtp: mail client sending protocol library
- stdlib: mainly contains string processing class (string), xml/json parsing library, zlib compression library (depends on zlib library), logging class, character set transcoding (ivel library is required in UNIX environment), memcached client Library, mutual exclusion class (supports thread lock, file lock);
- **stream: Supports network flow/file flow, supports blocking/non-blocking communication modes, supports select/poll/epoll/iocp/win32 message/kqueue/devpoll in non-blocking mode; supports ssl encrypted transmission (blocking) And non-blocking mode, need polarsl library); **
- ipc: provides a way to integrate blocking modules with non-blocking modules in non-blocking communication mode;
- http: A complete HTTP communication library and protocol parsing library, support client and server mode, support ssl/gzip transmission mode; support most interfaces similar to Java HttpServlet mode, convenient to write CGI and WEB server programs ;
- db: encapsulates the MYSQL/SQLITE library and supports database connection pooling;
- hsocket: implements the complete handler-socket client communication library;
- mime: Supports complete library related to mail encoding (rfc2045-rfc2047/rfc822/base64/uucode encoding and decoding library for mail).
- master: Server framework library that encapsulates the C library
- beanstalk: message queue application beanstalkd client communication library, support connection pool
- connpool: Universal connection pool library
- hscoket: mysql plugin handle-socket client communication library, support connection pool
- memcache: client library of memcached application, support connection pool and connection pool cluster management
- queue: disk file queue operation library
- ipc: Blocking/non-blocking communication integration library
- session: HTTP session library
- redis: Full implementation of the redis protocol client communication library (12 major categories, more than 150 commands), support connection pooling and connection pool cluster management
- disque: Support for cluster message queue service disque client library, support connection pool and connection pool cluster management
- c directory: This directory is mainly a network coroutine library implemented in C language version, which contains source files and header files.
- cpp directory: This directory contains the C language version of the network coroutine library
- samples directory: There are a lot of examples in this directory using the programming of the coroutine library.
- Class index map:
- Asynchronous IO class inheritance graph
- IO stream inheritance graph
- acl service framework daemon event processing flow ![acl service daemon event processing flow] (res/img/acl_master.jpg)
- acl server framework child process event processing flow ![Service Child Process Event Flow] (res/img/master_proc.jpg)
- Receive a CGI program that uploads files: ![CGI program to receive uploaded files] (res/img/cgi_upload.jpg)
- File download client program: ![File Download Client Program] (res/img/http_download.jpg)
- Web downloader:
3.6 There are a lot of examples in the acl library for reference, please refer to: SAMPLES.md
3.7 Acl using FAQ: FAQ.md
- LGPL-v3 license (see LICENSE.txt in the acl project)
- WEB site: https://blog.csdn.net/zsxxsz
- Github: https://github.com/acl-dev/acl
- Oschina: https://gitee.com/acl-dev/acl
- Weibo: http://weibo.com/zsxxsz
- QQ Group: 693868497