| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
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.
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.
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:
Network Operation Module
This module provides complete network operation functionality, including:
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:
Common Network Communication Library
Provides client communication libraries for Memcached, Beanstalk, Handler Socket, etc., all supporting connection pool mode.
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
Core Features
Synchronization Primitives
For more details, see Using Acl Coroutine Library
Complete implementation of HTTP/1.1 protocol, supporting both client and server application development.
Main Features
Acl's Redis client module is powerful, high-performance, and easy to use, making it an ideal choice for production environments.
Features
For more details, see Using Acl Redis Client
Acl fully implements the MQTT 3.1.1 protocol with a streaming parser design that can flexibly adapt to various IO modes.
Core Features
For more details, see Using Acl MQTT
The server framework is the core module in Acl, helping developers quickly build high-performance backend services (such as web services). Through the code generation tool in app/wizard, a complete service code framework can be generated in seconds.
Architecture Design
The Acl server framework consists of two parts:
Six Service Templates
Process Service Model
One connection per process.
Thread Service Model
Each process handles all client connections through a thread pool, using IO event triggering mechanism.
AIO Service Model (Non-blocking)
Similar to Nginx/Squid/IRCd, single thread handles many connections in non-blocking IO mode.
Coroutine Service Model
Combines the high concurrency capability of non-blocking model with the simplicity of synchronous programming.
UDP Service Model
Service model specifically for UDP communication.
Trigger Service Model
For handling scheduled tasks in background services (similar to system crontab).
MIME (Multipurpose Internet Mail Extensions) is an important data format standard widely used in email and web applications.
Features
Acl provides rich codecs, all using streaming parsing design, independent of the IO communication layer.
Supported Codec Formats
Acl provides a unified database abstraction interface to simplify database application development.
Core Features
Acl provides a general connection pool manager widely used in various client communication modules of the Acl library.
Application Scenarios
In addition to the Redis client, Acl implements various commonly used client communication libraries.
Supported Clients
Acl provides a complete DNS solution that can use system APIs or directly implement DNS protocol.
Features
Acl is a cross-platform library supporting mainstream operating systems and multiple compilation toolchains.
Supported Platforms
Compilation Methods
Linux/UNIX Platform
Compiler: gcc/clang
Make Method:
cd acl/
makeAfter compilation, the following will be generated in the acl/ directory:
CMake Method:
./cmake-build.shXMake Method:
xmakeWindows Platform
macOS/iOS Platform
Android Platform
Harmony Platform
Cross-Platform Compilation
When using Acl dynamic libraries in Windows environment, you need to add corresponding predefined macros in your project.
Predefined Macro Description
| Library Used | Required Predefined Macro | Description |
|---|---|---|
| lib_acl dynamic library | ACL_DLL | Base library |
| lib_protocol HTTP library | HTTP_DLL | HTTP protocol library |
| lib_protocol ICMP library | ICMP_DLL | ICMP protocol library |
| lib_acl_cpp dynamic library | ACL_CPP_DLL | C++ library |
Detailed Instructions
This is the simplest Acl program, demonstrating how to use Acl's string class.
#include <iostream>
#include "acl_cpp/lib_acl.hpp"
int main() {
acl::string buf = "hello world!\r\n";
std::cout << buf.c_str() << std::endl;
return 0;
}This example shows how to create a simple TCP echo server using Acl, handling client connections with multiple threads.
#include <thread>
#include "acl_cpp/lib_acl.hpp"
void run() {
const char* addr = "127.0.0.1:8088";
acl::server_socket server;
if (!server.open(addr)) { // Bind and listen on local address.
return;
}
while (true) {
acl::socket_stream* conn = server.accept(); // Wait for connection.
if (conn == NULL) {
break;
}
std::thread thread([=] { // Start a thread to handle the connection.
char buf[256];
int ret = conn->read(buf, sizeof(buf), false); // Read data.
if (ret > 0) {
conn->write(buf, ret); // Write received data.
}
delete conn;
});
thread.detach();
}
}This example shows how to create a TCP client using Acl, connecting to a server and sending/receiving data.
#include "acl_cpp/lib_acl.hpp"
void run() {
const char* addr = "127.0.0.1:8088";
int conn_timeout = 5, rw_timeout = 10;
acl::socket_stream conn;
if (!conn.open(addr, conn_timeout, rw_timeout)) { // Connect to server.
return;
}
const char data[] = "Hello world!\r\n";
if (conn.write(data, sizeof(data) - 1) == -1) { // Send data to server.
return;
}
char buf[256];
int ret = conn.read(buf, sizeof(buf) - 1, false);
if (ret > 0) { // Read from server.
buf[ret] = 0;
std::cout << buf << std::endl;
}
}This example shows how to create a high-concurrency TCP server using Acl coroutines, implementing asynchronous processing with sequential programming style.
#include "acl_cpp/lib_acl.hpp"
#include "fiber/go_fiber.hpp"
void run() {
const char* addr = "127.0.0.1:8088";
acl::server_socket server;
if (!server.open(addr)) {
return;
}
go[&] { // Create a server coroutine to wait for connections.
while (true) {
acl::shared_stream conn = server.shared_accept();
if (conn == nullptr) {
break;
}
go[conn] { // Create a client coroutine to handle the connection.
while (true) {
char buf[256];
int ret = conn->read(buf, sizeof(buf), false);
if (ret <= 0 || conn->write(buf, ret) != ret) {
break;
}
}
};
}
};
acl::fiber::schedule(); // Start the coroutine scheduling process.
}This example shows how to create an HTTP client using Acl, sending HTTP requests and getting responses.
#include "acl_cpp/lib_acl.hpp"
bool run() {
acl::http_request conn("www.baidu.com:80");
acl::http_header& header = conn.request_header()
header.set_url("/")
.set_keep_alive(false);
.set_content_type("text/html");
if (!conn.request(NULL, 0)) {
return false;
}
int status = conn.http_status();
if (status != 200) {
return false;
}
long long len = conn.body_length();
if (len <= 0) {
return true;
}
acl::string buf;
if (!conn.get_body(body)) {
return false;
}
return true;
}This example shows how to create a fully-featured HTTP server using Acl coroutines, supporting routing, configuration management, and other features.
#include "acl_cpp/lib_acl.hpp" // Must be before http_server.hpp
#include "fiber/http_server.hpp"
static char *var_cfg_debug_msg;
static acl::master_str_tbl var_conf_str_tab[] = {
{ "debug_msg", "test_msg", &var_cfg_debug_msg },
{ 0, 0, 0 }
};
static int var_cfg_io_timeout;
static acl::master_int_tbl var_conf_int_tab[] = {
{ "io_timeout", 120, &var_cfg_io_timeout, 0, 0 },
{ 0, 0 , 0 , 0, 0 }
};
int main(int argc, char* argv[]) {
const char* addr = "0.0.0.0|8194";
const char* conf = argc >= 2 ? argv[1] : NULL;
acl::http_server server;
// Call methods in acl::master_base class.
server.set_cfg_int(var_conf_int_tab).set_cfg_str(var_conf_str_tab);
// Call methods in acl::http_server.
server.on_proc_init([&addr] {
printf("---> after process init: addr=%s, io_timeout=%d\r\n", addr, var_cfg_io_timeout);
}).on_proc_exit([] {
printf("---> before process exit\r\n");
}).on_proc_sighup([] (acl::string& s) {
s = "+ok";
printf("---> process got sighup\r\n");
return true;
}).on_thread_accept([] (acl::socket_stream& conn) {
printf("---> accept %d\r\n", conn.sock_handle());
return true;
}).Get("/", [](acl::HttpRequest&, acl::HttpResponse& res) {
std::string buf("hello world1!\r\n");
res.setContentLength(buf.size());
return res.write(buf.c_str(), buf.size());
}).Post("/json", [](acl::HttpRequest& req, acl::HttpResponse& res) {
acl::json* json = req.getJson();
if (json) {
return res.write(*json);
} else {
std::string buf = "no json got\r\n";
res.setContentLength(buf.size());
return res.write(buf.c_str(), buf.size());
}
}).run_alone(addr, conf);
return 0;
}This example shows how to use the Acl Redis client for multi-threaded operations, including connection pool management and basic Redis commands.
#include <thread>
#include "acl_cpp/lib_acl.hpp"
static void thread_run(acl::redis_client_cluster& conns) {
acl::redis cmd(&conns);
std::map<acl::string, acl::string> attrs;
attrs["name1"] = "value1";
attrs["name2"] = "value2";
attrs["name3"] = "value3";
acl::string key = "hash-key-1";
if (!cmd.hmset(key, attrs)) {
printf("hmset error=%s\r\n", cmd.result_error());
return;
}
attrs.clear();
if (!cmd.hgetall(key, attrs)) {
printf("hgetall error=%s\r\n", cmd.result_error());
}
}
void run() {
const char* addr = "126.0.0.1:6379";
acl::redis_client_cluster conns;
conns.set(addr, 0);
const size_t nthreads = 10;
std::thread threads[nthreads];
// Create some threads to test redis using the same conns.
for (size_t i = 0; i < nthreads; i++) {
threads[i] = std::thread(thread_run, std::ref(conns));
}
// Wait for all threads to exit
for (size_t i = 0; i < nthreads; i++) {
threads[i].join();
}
}The Acl library provides a large number of sample codes for learning and reference, covering the usage of various functional modules.
Sample Index: SAMPLES.md
To help developers get started quickly, we provide many simple and easy-to-understand small examples.
Sample Repository: Acl Demos
Encountering problems when using Acl? Check the frequently asked questions.
FAQ Document: FAQ.md
Acl adopts the LGPL-v2.1 open source license and can be freely used in commercial and non-commercial projects.
License Details: LICENSE.txt
Official Resources
Community
Thanks to
for supporting the Acl project.
┌─────────────────────────────────────────────────────────┐
│ Application Layer │
│ Business code, HTTP server, WebSocket service, etc. │
└─────────────────────────────────────────────────────────┘
↓
┌────────────────────────────────────────────────────────┐
│ High-level API Layer │
│ ┌──────────┬──────────┬──────────┬──────────┐ │
│ │ HTTP │ Redis │ MQTT │ DB │ │
│ │ Module │ Module │ Module │ Module │ │
│ └──────────┴──────────┴──────────┴──────────┘ │
│ ┌──────────┬──────────┬──────────┬──────────┐ │
│ │ Master │ Fiber │ ConnPool │ Stream │ │
│ │Framework │Coroutine │ Pool │Processing│ │
│ └──────────┴──────────┴──────────┴──────────┘ │
└────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────┐
│ Core Library Layer │
│ - Network I/O (socket, stream, aio) │
│ - Event-driven (event, epoll, kqueue, iocp) │
│ - Memory management (memory pool, dbuf) │
│ - Data structures (string, array, hash, list) │
│ - Utilities (log, config, thread, process) │
└─────────────────────────────────────────────────────────┘
↓
┌───────────────────────────────────────────────────────────┐
│ Operating System Layer │
│ Linux / FreeBSD / macOS / Windows / Android / iOS / Harmony │
└───────────────────────────────────────────────────────────┘
acl/ ├── lib_acl/ # Core C library (base library) │ ├── include/ # Public header files │ ├── src/ # Source code implementation │ │ ├── stdlib/ # Standard library (string, memory, file, etc.) │ │ │ ├── common/ # Common data structures (hash, list, queue, tree, etc.) │ │ │ ├── memory/ # Memory management (memory pool, slab, dbuf) │ │ │ ├── string/ # String operations │ │ │ ├── filedir/ # File and directory operations │ │ │ ├── configure/ # Configuration file parsing │ │ │ ├── iostuff/ # IO utility functions │ │ │ ├── debug/ # Debugging tools │ │ │ └── sys/ # System-related wrappers │ │ ├── net/ # Network module │ │ │ ├── connect/ # Client connection │ │ │ ├── listen/ # Server listening │ │ │ └── dns/ # DNS resolution │ │ ├── event/ # Event engine (epoll/kqueue/iocp/select/poll) │ │ ├── aio/ # Asynchronous IO module │ │ ├── thread/ # Thread and thread pool │ │ ├── master/ # Server framework (process management) │ │ │ └── template/ # Service templates (process/thread/aio/coroutine/UDP/trigger) │ │ ├── db/ # Database module │ │ │ ├── mysql/ # MySQL support │ │ │ ├── memdb/ # In-memory database │ │ │ └── zdb/ # ZDB storage engine │ │ ├── json/ # JSON parser │ │ ├── xml/ # XML parser │ │ ├── code/ # Encoding/decoding (base64/url/html, etc.) │ │ ├── msg/ # Message queue │ │ ├── init/ # Initialization module │ │ ├── ioctl/ # IO control │ │ ├── proctl/ # Process control (Windows) │ │ └── unit_test/ # Unit testing framework │ └── samples/ # Extensive sample code │ ├── lib_protocol/ # Protocol library (C implementation) │ ├── include/ # Protocol header files │ ├── src/ # Protocol implementation │ │ ├── http/ # HTTP protocol │ │ ├── icmp/ # ICMP/Ping protocol │ │ └── smtp/ # SMTP mail protocol │ └── samples/ # Protocol samples │ ├── lib_acl_cpp/ # C++ wrapper library (advanced features) │ ├── include/ # C++ header files │ │ ├── acl_cpp/ # Main header directory │ │ │ ├── stdlib/ # Standard library wrapper │ │ │ ├── stream/ # Stream processing │ │ │ ├── http/ # HTTP client and server │ │ │ ├── redis/ # Redis client │ │ │ ├── mqtt/ # MQTT protocol │ │ │ ├── db/ # Database wrapper │ │ │ ├── mime/ # MIME protocol │ │ │ ├── master/ # Master framework wrapper │ │ │ ├── connpool/ # Connection pool │ │ │ ├── session/ # Session management │ │ │ ├── memcache/ # Memcached client │ │ │ ├── beanstalk/ # Beanstalk client │ │ │ ├── disque/ # Disque client │ │ │ ├── hsocket/ # Handler Socket client │ │ │ ├── ipc/ # Inter-process communication │ │ │ ├── queue/ # File queue │ │ │ ├── serialize/ # Serialization (JSON/Gson) │ │ │ ├── aliyun/ # Aliyun SDK (OSS, to be implemented) │ │ │ └── event/ # Event wrapper │ ├── src/ # C++ source implementation │ │ ├── stdlib/ # Standard library implementation (string/logger/charset/zlib, etc.) │ │ ├── stream/ # Stream implementation (socket/ssl/aio) │ │ ├── http/ # HTTP implementation │ │ │ ├── h2/ # HTTP/2 support (to be implemented) │ │ │ └── h3/ # HTTP/3 support (to be implemented) │ │ ├── redis/ # Redis client implementation │ │ ├── mqtt/ # MQTT protocol implementation │ │ ├── db/ # Database implementation │ │ ├── mime/ # MIME implementation │ │ ├── master/ # Master framework implementation │ │ ├── connpool/ # Connection pool implementation │ │ ├── session/ # Session implementation │ │ ├── memcache/ # Memcached implementation │ │ ├── beanstalk/ # Beanstalk implementation │ │ ├── disque/ # Disque implementation │ │ ├── hsocket/ # Handler Socket implementation │ │ ├── ipc/ # IPC implementation │ │ ├── queue/ # Queue implementation │ │ ├── serialize/ # Serialization implementation │ │ ├── smtp/ # SMTP implementation │ │ ├── aliyun/ # Aliyun OSS client implementation(to be implemented) │ │ └── net/ # Network utilities (DNS) │ └── samples/ # Rich sample code │ ├── http/ # HTTP samples │ ├── redis/ # Redis samples │ ├── mqtt/ # MQTT samples │ ├── db/ # Database samples │ ├── master/ # Master framework samples │ ├── fiber/ # Coroutine samples │ └── ... # More samples │ ├── lib_fiber/ # Coroutine library (core features) │ ├── c/ # C language implementation │ │ ├── include/ # Coroutine header files │ │ └── src/ # Coroutine source code │ │ ├── common/ # Common modules │ │ ├── fiber/ # Coroutine core │ │ ├── event/ # Event engine │ │ ├── sync/ # Synchronization primitives (mutex/sem/event) │ │ ├── hook/ # System API Hook │ │ └── ... │ ├── cpp/ # C++ wrapper │ │ ├── include/ # C++ header files │ │ └── src/ # C++ implementation │ ├── samples-c/ # C language samples │ ├── samples-c++/ # C++ samples │ ├── samples-c++1x/ # C++11/14/17 samples │ ├── samples-gui/ # GUI samples (Windows) │ └── unit_test/ # Unit tests │ ├── lib_dict/ # Dictionary library (optional) │ ├── bdb/ # Berkeley DB support │ ├── cdb/ # CDB support │ └── tc/ # Tokyo Cabinet support │ ├── lib_tls/ # TLS/SSL library (optional) │ └── src/ # TLS implementation │ ├── lib_rpc/ # RPC library (experimental) │ └── src/ # RPC implementation │ ├── app/ # Applications and tools │ ├── wizard/ # Code generation wizard (important tool) │ │ └── tmpl/ # Service templates (process/thread/aio/coroutine/UDP/trigger) │ ├── wizard_demo/ # Sample projects generated by wizard │ ├── master/ # Master service manager │ │ ├── daemon/ # Daemon process │ │ ├── tools/ # Management tools │ │ └── ... │ ├── jaws/ # Web application server │ ├── redis_tools/ # Redis toolset │ ├── net_tools/ # Network tools │ ├── gson/ # JSON serialization tool │ ├── jencode/ # Encoding conversion tool │ ├── iconv/ # Character set conversion │ └── ... │ ├── doc/ # Documentation directory │ ├── README.md # Documentation index │ ├── fiber/ # Coroutine documentation │ ├── http/ # HTTP documentation │ ├── redis/ # Redis documentation │ ├── mqtt/ # MQTT documentation │ ├── db/ # Database documentation │ ├── master/ # Master framework documentation │ ├── stream/ # Stream documentation │ ├── mime/ # MIME documentation │ ├── connpool/ # Connection pool documentation │ ├── rfc/ # RFC documentation │ └── ... │ ├── include/ # Third-party library header files │ ├── mysql/ # MySQL header files │ ├── pgsql/ # PostgreSQL header files │ ├── sqlite/ # SQLite header files │ ├── openssl-1.1.1q/ # OpenSSL header files │ ├── mbedtls/ # MbedTLS header files │ ├── polarssl/ # PolarSSL header files │ ├── zlib-1.2.11/ # Zlib header files │ └── ... │ ├── lib/ # Pre-compiled library files (by platform) │ ├── linux64/ # Linux 64-bit │ ├── linux32/ # Linux 32-bit │ ├── win32/ # Windows 32-bit │ ├── win64/ # Windows 64-bit │ ├── macos/ # macOS │ ├── freebsd/ # FreeBSD │ └── solaris/ # Solaris │ ├── android/ # Android platform support │ ├── acl_ndk20b/ # NDK r20b project │ ├── acl_ndk28c/ # NDK r28c project │ └── samples/ # Android samples │ ├── harmony/ # Harmony platform support │ ├── api9/ # HarmonyOS API 9 │ ├── api12/ # HarmonyOS API 12 │ ├── api13/ # HarmonyOS API 13 │ └── api16/ # HarmonyOS API 16 │ ├── xcode/ # Xcode project (macOS/iOS) │ └── ... # Xcode project files │ ├── dist/ # Installation directory (after make install) │ ├── include/ # Installed header files │ ├── lib/ # Installed library files │ └── master/ # Master configuration and scripts │ ├── unit_test/ # Unit tests │ └── ... # Test cases │ ├── packaging/ # Packaging configuration │ └── ... # RPM/DEB packaging scripts │ ├── CMakeLists.txt # CMake build configuration ├── Makefile # Main Makefile ├── xmake.lua # XMake build configuration ├── README.md # English documentation ├── README_CN.md # Chinese documentation ├── SAMPLES.md # Sample code index ├── FAQ.md # Frequently asked questions ├── BUILD.md # Build instructions ├── LICENSE.txt # Open source license └── changes.txt # Change log
webcool is a personal cloud drive and private file management product built with acl. It can be self-hosted on a private server, workstation, or home network. Its C++ server applies acl's networking, HTTP service, concurrency, and server framework capabilities in a real-world cross-platform product.
Key webcool capabilities include:
On the server side, webcool uses acl's high-performance networking and HTTP infrastructure, coroutine-based concurrency model, service management capabilities, and database wrappers to combine file management, media processing, and multi-device access in a long-running application.
| Back | FazBrowse Home | New Git URL |