Acl
C/C++ server and network library, including coroutine,redis client,http/https/websocket,mqtt, mysql/postgresql/sqlite client with C/C++ for Linux, Android, iOS, MacOS, Windows, etc..
Install / Use
/learn @acl-dev/AclREADME
Acl -- Advanced Cross-Platform C/C++ Network Communication Library and Server Framework
0. About Acl Project
Acl (Advanced C/C++ Library) is a powerful cross-platform network communication library and server programming framework that supports Linux, Windows, Solaris, FreeBSD, macOS, Android, iOS, and HarmonyOS. Numerous applications developed with Acl run on various devices, providing stable and reliable services to hundreds of millions of users.
The Acl project includes a rich set of functional modules: network communication, server framework, application protocols, various codecs, and more. It has built-in implementations of common network protocols such as HTTP/SMTP/ICMP/MQTT/Redis/Memcached/Beanstalk/Handler Socket, as well as complete codec libraries including XML/JSON/MIME/BASE64/UUCODE/QPCODE/RFC2047/RFC1035, etc. Additionally, Acl provides a unified abstract interface for mainstream databases (MySQL, PostgreSQL, SQLite), enabling developers to write database applications more easily, quickly, and securely.
Software Architecture

1. Six Core Modules
As a fully-featured C/C++ foundation library, Acl provides rich and practical functionality for application development. The six core modules include: Network Communication, Coroutine, HTTP, Redis Client, MQTT, and Server Framework.
1.1. Basic Network Module
Stream Processing Module
This module is the cornerstone of Acl's network communication, providing a unified streaming communication interface that supports both network streams and file streams. Main features include:
- Read data line by line, automatically compatible with
\r\non Windows and\non UNIX - Read data line by line with automatic removal of trailing newline characters (
\nor\r\n) - Read data with custom string delimiters
- Read data of specified length
- Try to read a line or specified length of data
- Detect network IO status
- Write a line of data
- Formatted data writing (similar to
fprintf) - File stream positioning operations (similar to
fseek) - Batch write data (similar to UNIX
writev) - Truncate files (similar to
ftruncate) - Get file size and current file stream pointer position (similar to
ftell) - Get local and remote addresses of network streams
Network Operation Module
This module provides complete network operation functionality, including:
- Network server listening (supports TCP/UDP/UNIX domain sockets)
- Network client connection (supports TCP/UNIX domain sockets)
- DNS domain name query and result caching (supports both system API calls and direct DNS protocol)
- Socket operations and local network interface information retrieval
Non-blocking Network Stream
Comprehensive support for non-blocking network operations, including non-blocking connections, reads (line reads, specified length reads), writes (line writes, specified length writes, batch writes), etc.
Common Network Application Protocol Library
Built-in implementations of common network application protocols such as HTTP, SMTP, ICMP, etc. The HTTP and ICMP modules support both blocking and non-blocking communication modes. The HTTP protocol in the C++ version of lib_acl_cpp provides both server and client modes:
- Server Mode: Provides a Java HttpServlet-like interface, supports Cookie, Session, HTTP MIME file upload, etc.
- Client Mode: Supports connection pool and cluster management, chunked transfer, automatic character set conversion, automatic decompression, resume download, and other rich features
Common Network Communication Library
Provides client communication libraries for Memcached, Beanstalk, Handler Socket, etc., all supporting connection pool mode.
1.2. Coroutine
Acl's coroutine module is a mature and stable cross-platform coroutine library that has been widely used and validated in many important projects.
Platform Support
- Supports mainstream operating systems including Linux, macOS, Windows, iOS, and Android
- Supports multiple CPU architectures including x86, ARM, etc.
- Supports multiple event engines including select/poll/epoll/kqueue/iocp/win32 GUI messages
Core Features
- Complete DNS Protocol Implementation: DNS protocol is natively implemented in coroutines, DNS API can be used directly in coroutines
- System API Hook: Automatically hooks system IO APIs on Unix and Windows platforms to enable coroutine support
- Read APIs: read/readv/recv/recvfrom/recvmsg
- Write APIs: write/writev/send/sendto/sendmsg/sendfile64
- Socket APIs: socket/listen/accept/connect/setsockopt
- Event APIs: select/poll/epoll_create/epoll_ctl/epoll_wait
- DNS APIs: gethostbyname/gethostbyname_r/getaddrinfo/freeaddrinfo
- Shared Stack Mode: Supports shared stack mode to significantly reduce memory usage
Synchronization Primitives
- Coroutine Mutex and Semaphore: For synchronization between coroutines
- Coroutine Event: Supports synchronous communication between coroutines and threads
For more details, see Using Acl Coroutine Library
1.3. HTTP Module
Complete implementation of HTTP/1.1 protocol, supporting both client and server application development.
Main Features
- Java HttpServlet-like Interface (server side): Provides familiar programming interface, reducing learning curve
- Connection Pool Mode (client side): Efficiently manages connection resources, improves performance
- Chunked Transfer: Supports streaming data transfer
- Compression: Built-in Gzip compression/decompression support
- SSL/TLS Encryption: Supports secure encrypted transmission
- Resume Download: Supports resume download for large files
- Cookie Management: Complete cookie setting and retrieval functionality
- Session Management (server side): Built-in session management mechanism
- WebSocket Support: Supports WebSocket protocol
- HTTP MIME Format: Supports MIME multipart data format
- Sync/Async Mode: Flexible choice of communication modes
1.4. Redis Client
Acl's Redis client module is powerful, high-performance, and easy to use, making it an ideal choice for production environments.
Features
- Rich Command Support: Supports Redis data types and commands including Bitmap/String/Hash/List/Set/Sorted Set/PubSub/HyperLogLog/Geo/Script/Stream/Server/Cluster
- STL-style Interface: Provides STL-like C++ interface for each Redis command, conforming to C++ programming conventions
- Smart Cluster Management: Client automatically caches and adapts to changes in Redis cluster hash slots without manual intervention
- Multiple Communication Modes: Supports standalone, cluster, and pipeline modes with unified interface
- Connection Pool Support: Built-in connection pool supporting standalone and cluster modes, improving resource utilization
- High Performance: Excellent performance in cluster and pipeline modes
- Automatic Retry: Automatically retries on network errors, improving reliability
- Coroutine Friendly: Can be used in shared stack coroutine mode
For more details, see Using Acl Redis Client
1.5. MQTT Module
Acl fully implements the MQTT 3.1.1 protocol with a streaming parser design that can flexibly adapt to various IO modes.
Core Features
- Complete MQTT 3.1.1 Protocol Support: Implements all standard commands
- CONNECT/CONNACK/PUBLISH/PUBACK/PUBREC/PUBREL/PUBCOMP
- SUBSCRIBE/SUBACK/UNSUBSCRIBE/UNSUBACK
- PINGREQ/PINGRESP/DISCONNECT
- Object-Oriented Design: Each MQTT command corresponds to an independent class with clear structure
- Streaming Parser: Independent of IO mode, can be combined with any network communication method
- Separation of Parsing and Communication: Data parsing is completely decoupled from network communication, providing high flexibility
- Dual-End Support: Can b
