{"id":13437104,"url":"https://github.com/ithewei/libhv","last_synced_at":"2025-05-14T07:07:59.400Z","repository":{"id":37296858,"uuid":"146397768","full_name":"ithewei/libhv","owner":"ithewei","description":"🔥 比libevent/libuv/asio更易用的网络库。A c/c++ network library for developing TCP/UDP/SSL/HTTP/WebSocket/MQTT client/server.","archived":false,"fork":false,"pushed_at":"2025-04-17T11:20:15.000Z","size":6571,"stargazers_count":7141,"open_issues_count":73,"forks_count":1289,"subscribers_count":145,"default_branch":"master","last_synced_at":"2025-05-07T06:59:26.328Z","etag":null,"topics":["curl","epoll","http-client","http-server","https","iocp","kcp","mqtt","openssl","requests","webserver","websocket","websocket-client","websocket-server","wrk"],"latest_commit_sha":null,"homepage":"https://github.com/ithewei/libhv/wiki","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ithewei.png","metadata":{"files":{"readme":"README-CN.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-08-28T05:47:15.000Z","updated_at":"2025-05-07T03:35:08.000Z","dependencies_parsed_at":"2023-10-23T12:27:35.627Z","dependency_job_id":"cf52b1af-90a6-4a7b-a973-8a66e7dcb768","html_url":"https://github.com/ithewei/libhv","commit_stats":{"total_commits":1159,"total_committers":50,"mean_commits":23.18,"dds":0.365832614322692,"last_synced_commit":"0cfc3c161fac33cdbd5b0bab0c249f4bc95ed1ed"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ithewei%2Flibhv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ithewei%2Flibhv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ithewei%2Flibhv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ithewei%2Flibhv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ithewei","download_url":"https://codeload.github.com/ithewei/libhv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254092650,"owners_count":22013290,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["curl","epoll","http-client","http-server","https","iocp","kcp","mqtt","openssl","requests","webserver","websocket","websocket-client","websocket-server","wrk"],"created_at":"2024-07-31T03:00:54.347Z","updated_at":"2025-05-14T07:07:59.342Z","avatar_url":"https://github.com/ithewei.png","language":"C","readme":"[English](README.md) | 中文\n\n# libhv\n\n[![Linux](https://badgen.net/badge/Linux/success/green?icon=github)](https://github.com/ithewei/libhv/actions/workflows/CI.yml?query=branch%3Amaster)\n[![Windows](https://badgen.net/badge/Windows/success/green?icon=github)](https://github.com/ithewei/libhv/actions/workflows/CI.yml?query=branch%3Amaster)\n[![macOS](https://badgen.net/badge/macOS/success/green?icon=github)](https://github.com/ithewei/libhv/actions/workflows/CI.yml?query=branch%3Amaster)\n[![Android](https://badgen.net/badge/Android/success/green?icon=github)](https://github.com/ithewei/libhv/actions/workflows/CI.yml?query=branch%3Amaster)\n[![iOS](https://badgen.net/badge/iOS/success/green?icon=github)](https://github.com/ithewei/libhv/actions/workflows/CI.yml?query=branch%3Amaster)\n[![benchmark](https://github.com/ithewei/libhv/workflows/benchmark/badge.svg?branch=master)](https://github.com/ithewei/libhv/actions/workflows/benchmark.yml?query=branch%3Amaster)\n\u003cbr\u003e\n[![release](https://badgen.net/github/release/ithewei/libhv?icon=github)](https://github.com/ithewei/libhv/releases)\n[![stars](https://badgen.net/github/stars/ithewei/libhv?icon=github)](https://github.com/ithewei/libhv/stargazers)\n[![forks](https://badgen.net/github/forks/ithewei/libhv?icon=github)](https://github.com/ithewei/libhv/forks)\n[![issues](https://badgen.net/github/issues/ithewei/libhv?icon=github)](https://github.com/ithewei/libhv/issues)\n[![PRs](https://badgen.net/github/prs/ithewei/libhv?icon=github)](https://github.com/ithewei/libhv/pulls)\n[![contributors](https://badgen.net/github/contributors/ithewei/libhv?icon=github)](https://github.com/ithewei/libhv/contributors)\n[![license](https://badgen.net/github/license/ithewei/libhv?icon=github)](LICENSE)\n\u003cbr\u003e\n[![gitee](https://badgen.net/badge/mirror/gitee/red)](https://gitee.com/libhv/libhv)\n[![awesome-c](https://badgen.net/badge/icon/awesome-c/pink?icon=awesome\u0026label\u0026color)](https://github.com/oz123/awesome-c)\n[![awesome-cpp](https://badgen.net/badge/icon/awesome-cpp/pink?icon=awesome\u0026label\u0026color)](https://github.com/fffaraz/awesome-cpp)\n\n`libhv`是一个类似于`libevent、libev、libuv`的跨平台网络库，提供了更易用的接口和更丰富的协议。\n\n## 📚 中文资料\n\n- **libhv QQ群**: `739352073`，欢迎加群交流\n- **libhv 源码剖析**: \u003chttps://hewei.blog.csdn.net/article/details/123295998\u003e\n- **libhv 接口手册**: \u003chttps://hewei.blog.csdn.net/article/details/103976875\u003e\n- **libhv 教程目录**: \u003chttps://hewei.blog.csdn.net/article/details/113733758\u003e\n- [libhv教程01--介绍与体验](https://hewei.blog.csdn.net/article/details/113702536)\n- [libhv教程02--编译与安装](https://hewei.blog.csdn.net/article/details/113704737)\n- [libhv教程03--链库与使用](https://hewei.blog.csdn.net/article/details/113706378)\n- [libhv教程04--编写一个完整的命令行程序](https://hewei.blog.csdn.net/article/details/113719503)\n- [libhv教程05--事件循环以及定时器的简单使用](https://hewei.blog.csdn.net/article/details/113724474)\n- [libhv教程06--创建一个简单的TCP服务端](https://hewei.blog.csdn.net/article/details/113737580)\n- [libhv教程07--创建一个简单的TCP客户端](https://hewei.blog.csdn.net/article/details/113738900)\n- [libhv教程08--创建一个简单的UDP服务端](https://hewei.blog.csdn.net/article/details/113871498)\n- [libhv教程09--创建一个简单的UDP客户端](https://hewei.blog.csdn.net/article/details/113871724)\n- [libhv教程10--创建一个简单的HTTP服务端](https://hewei.blog.csdn.net/article/details/113982999)\n- [libhv教程11--创建一个简单的HTTP客户端](https://hewei.blog.csdn.net/article/details/113984302)\n- [libhv教程12--创建一个简单的WebSocket服务端](https://hewei.blog.csdn.net/article/details/113985321)\n- [libhv教程13--创建一个简单的WebSocket客户端](https://hewei.blog.csdn.net/article/details/113985895)\n- [libhv教程14--200行实现一个纯C版jsonrpc框架](https://hewei.blog.csdn.net/article/details/119920540)\n- [libhv教程15--200行实现一个C++版protorpc框架](https://hewei.blog.csdn.net/article/details/119966701)\n- [libhv教程16--多线程/多进程服务端编程](https://hewei.blog.csdn.net/article/details/120366024)\n- [libhv教程17--Qt中使用libhv](https://hewei.blog.csdn.net/article/details/120699890)\n- [libhv教程18--动手写一个tinyhttpd](https://hewei.blog.csdn.net/article/details/121706604)\n- [libhv教程19--MQTT的实现与使用](https://hewei.blog.csdn.net/article/details/122753665)\n\n## ✨ 特性\n\n- 跨平台（Linux, Windows, macOS, Android, iOS, BSD, Solaris）\n- 高性能事件循环（网络IO事件、定时器事件、空闲事件、自定义事件、信号）\n- TCP/UDP服务端/客户端/代理\n- TCP支持心跳、重连、转发、多线程安全write和close等特性\n- 内置常见的拆包模式（固定包长、分界符、头部长度字段）\n- 可靠UDP支持: WITH_KCP\n- SSL/TLS加密通信（可选WITH_OPENSSL、WITH_GNUTLS、WITH_MBEDTLS）\n- HTTP服务端/客户端（支持https http1/x http2 grpc）\n- HTTP支持静态文件服务、目录服务、正向/反向代理服务、同步/异步API处理器\n- HTTP支持RESTful风格、路由、中间件、keep-alive长连接、chunked分块、SSE等特性\n- WebSocket服务端/客户端\n- MQTT客户端\n\n## ⌛️ 构建\n\n见[BUILD.md](BUILD.md)\n\nlibhv提供了以下构建方式:\n\n1、通过Makefile:\n```shell\n./configure\nmake\nsudo make install\n```\n\n2、通过cmake:\n```shell\nmkdir build\ncd build\ncmake ..\ncmake --build .\n```\n\n3、通过bazel:\n```shell\nbazel build libhv\n```\n\n4、通过vcpkg:\n```shell\nvcpkg install libhv\n```\n\n5、通过xmake:\n```shell\nxrepo install libhv\n```\n\n## ⚡️ 快速入门\n\n### 体验\n运行脚本`./getting_started.sh`:\n\n```shell\n# 下载编译\ngit clone https://github.com/ithewei/libhv.git\ncd libhv\n./configure\nmake\n\n# 运行httpd服务\nbin/httpd -h\nbin/httpd -d\n#bin/httpd -c etc/httpd.conf -s restart -d\nps aux | grep httpd\n\n# 文件服务\nbin/curl -v localhost:8080\n\n# 目录服务\nbin/curl -v localhost:8080/downloads/\n\n# API服务\nbin/curl -v localhost:8080/ping\nbin/curl -v localhost:8080/echo -d \"hello,world!\"\nbin/curl -v localhost:8080/query?page_no=1\\\u0026page_size=10\nbin/curl -v localhost:8080/kv   -H \"Content-Type:application/x-www-form-urlencoded\" -d 'user=admin\u0026pswd=123456'\nbin/curl -v localhost:8080/json -H \"Content-Type:application/json\" -d '{\"user\":\"admin\",\"pswd\":\"123456\"}'\nbin/curl -v localhost:8080/form -F 'user=admin' -F 'pswd=123456'\nbin/curl -v localhost:8080/upload -d \"@LICENSE\"\nbin/curl -v localhost:8080/upload -F \"file=@LICENSE\"\n\nbin/curl -v localhost:8080/test -H \"Content-Type:application/x-www-form-urlencoded\" -d 'bool=1\u0026int=123\u0026float=3.14\u0026string=hello'\nbin/curl -v localhost:8080/test -H \"Content-Type:application/json\" -d '{\"bool\":true,\"int\":123,\"float\":3.14,\"string\":\"hello\"}'\nbin/curl -v localhost:8080/test -F 'bool=1' -F 'int=123' -F 'float=3.14' -F 'string=hello'\n# RESTful API: /group/:group_name/user/:user_id\nbin/curl -v -X DELETE localhost:8080/group/test/user/123\n\n# 压力测试\nbin/wrk -c 1000 -d 10 -t 4 http://127.0.0.1:8080/\n```\n\n### TCP\n#### TCP服务端\n**c版本**: [examples/tcp_echo_server.c](examples/tcp_echo_server.c)\n\n**c++版本**: [evpp/TcpServer_test.cpp](evpp/TcpServer_test.cpp)\n```c++\n#include \"TcpServer.h\"\nusing namespace hv;\n\nint main() {\n    int port = 1234;\n    TcpServer srv;\n    int listenfd = srv.createsocket(port);\n    if (listenfd \u003c 0) {\n        return -1;\n    }\n    printf(\"server listen on port %d, listenfd=%d ...\\n\", port, listenfd);\n    srv.onConnection = [](const SocketChannelPtr\u0026 channel) {\n        std::string peeraddr = channel-\u003epeeraddr();\n        if (channel-\u003eisConnected()) {\n            printf(\"%s connected! connfd=%d\\n\", peeraddr.c_str(), channel-\u003efd());\n        } else {\n            printf(\"%s disconnected! connfd=%d\\n\", peeraddr.c_str(), channel-\u003efd());\n        }\n    };\n    srv.onMessage = [](const SocketChannelPtr\u0026 channel, Buffer* buf) {\n        // echo\n        channel-\u003ewrite(buf);\n    };\n    srv.setThreadNum(4);\n    srv.start();\n\n    // press Enter to stop\n    while (getchar() != '\\n');\n    return 0;\n}\n```\n\n**注意**:\n\n以上示例只是简单的`echo`服务，TCP是流式协议，实际应用中请务必添加边界进行拆包。\u003cbr\u003e\n文本协议建议加上`\\0`或者`\\r\\n`分隔符，可参考 [examples/jsonrpc](examples/jsonrpc);\u003cbr\u003e\n二进制协议建议加上自定义协议头，通过头部长度字段表明负载长度，可参考 [examples/protorpc](examples/protorpc);\u003cbr\u003e\n通过`setUnpack`（c接口即`hio_set_unpack`）设置拆包规则，支持固定包长、分隔符、头部长度字段三种常见的拆包方式，\u003cbr\u003e\n内部根据拆包规则处理粘包与分包，保证`onMessage`回调上来的是完整的一包数据，大大节省了上层处理粘包与分包的成本。\u003cbr\u003e\n不想自定义协议和拆包组包的可直接使用现成的`HTTP/WebSocket`协议。\u003cbr\u003e\n\u003cbr\u003e\n`channel-\u003ewrite`（c接口即`hio_write`）是非阻塞的（事件循环异步编程里所有的一切都要求是非阻塞的），且多线程安全的。\u003cbr\u003e\n发送大数据时应该做流控，通过`onWriteComplete`监听写完成事件，在可写时再发送下一帧数据。\u003cbr\u003e\n具体示例代码可参考 [examples/tinyhttpd.c](examples/tinyhttpd.c) 中的 `http_serve_file`。\u003cbr\u003e\n\u003cbr\u003e\n`channel-\u003eclose`（c接口即`hio_close`) 也是多线程安全的，这可以让网络IO事件循环线程里接收数据、拆包组包、反序列化后放入队列，\u003cbr\u003e\n消费者线程/线程池从队列里取出数据、处理后发送响应和关闭连接，变得更加简单。\u003cbr\u003e\n\n#### TCP客户端\n**c版本**: [examples/tcp_client_test.c](examples/tcp_client_test.c)\n\n**c++版本**: [evpp/TcpClient_test.cpp](evpp/TcpClient_test.cpp)\n```c++\n#include \u003ciostream\u003e\n#include \"TcpClient.h\"\nusing namespace hv;\n\nint main() {\n    int port = 1234;\n    TcpClient cli;\n    int connfd = cli.createsocket(port);\n    if (connfd \u003c 0) {\n        return -1;\n    }\n    cli.onConnection = [](const SocketChannelPtr\u0026 channel) {\n        std::string peeraddr = channel-\u003epeeraddr();\n        if (channel-\u003eisConnected()) {\n            printf(\"connected to %s! connfd=%d\\n\", peeraddr.c_str(), channel-\u003efd());\n        } else {\n            printf(\"disconnected to %s! connfd=%d\\n\", peeraddr.c_str(), channel-\u003efd());\n        }\n    };\n    cli.onMessage = [](const SocketChannelPtr\u0026 channel, Buffer* buf) {\n        printf(\"\u003c %.*s\\n\", (int)buf-\u003esize(), (char*)buf-\u003edata());\n    };\n    cli.start();\n\n    std::string str;\n    while (std::getline(std::cin, str)) {\n        if (str == \"close\") {\n            cli.closesocket();\n        } else if (str == \"start\") {\n            cli.start();\n        } else if (str == \"stop\") {\n            cli.stop();\n            break;\n        } else {\n            if (!cli.isConnected()) break;\n            cli.send(str);\n        }\n    }\n    return 0;\n}\n```\n\n### HTTP\n#### HTTP服务端\n见[examples/http_server_test.cpp](examples/http_server_test.cpp)\n\n**golang gin 风格**\n```c++\n#include \"HttpServer.h\"\nusing namespace hv;\n\nint main() {\n    HttpService router;\n    router.GET(\"/ping\", [](HttpRequest* req, HttpResponse* resp) {\n        return resp-\u003eString(\"pong\");\n    });\n\n    router.GET(\"/data\", [](HttpRequest* req, HttpResponse* resp) {\n        static char data[] = \"0123456789\";\n        return resp-\u003eData(data, 10);\n    });\n\n    router.GET(\"/paths\", [\u0026router](HttpRequest* req, HttpResponse* resp) {\n        return resp-\u003eJson(router.Paths());\n    });\n\n    router.GET(\"/get\", [](HttpRequest* req, HttpResponse* resp) {\n        resp-\u003ejson[\"origin\"] = req-\u003eclient_addr.ip;\n        resp-\u003ejson[\"url\"] = req-\u003eurl;\n        resp-\u003ejson[\"args\"] = req-\u003equery_params;\n        resp-\u003ejson[\"headers\"] = req-\u003eheaders;\n        return 200;\n    });\n\n    router.POST(\"/echo\", [](const HttpContextPtr\u0026 ctx) {\n        return ctx-\u003esend(ctx-\u003ebody(), ctx-\u003etype());\n    });\n\n    HttpServer server(\u0026router);\n    server.setPort(8080);\n    server.setThreadNum(4);\n    server.run();\n    return 0;\n}\n```\n\n**注意**:\n\n上面示例直接运行在`main`主线程，`server.run()`会阻塞当前线程运行，所以`router`和`server`对象不会被析构，\u003cbr\u003e\n如使用`server.start()`内部会另起线程运行，不会阻塞当前线程，但需要注意`router`和`server`的生命周期，\u003cbr\u003e\n不要定义为局部变量被析构了，可定义为类成员变量或者全局变量，下面的`WebSocket`服务同理。\u003cbr\u003e\n\n#### HTTP客户端\n见[examples/http_client_test.cpp](examples/http_client_test.cpp)\n\n**python requests 风格**\n```c++\n#include \"requests.h\"\n\nint main() {\n    auto resp = requests::get(\"http://www.example.com\");\n    if (resp == NULL) {\n        printf(\"request failed!\\n\");\n    } else {\n        printf(\"%s\\n\", resp-\u003ebody.c_str());\n    }\n\n    resp = requests::post(\"127.0.0.1:8080/echo\", \"hello,world!\");\n    if (resp == NULL) {\n        printf(\"request failed!\\n\");\n    } else {\n        printf(\"%s\\n\", resp-\u003ebody.c_str());\n    }\n\n    return 0;\n}\n```\n\n附HTTP相关接口文档:\n\n- [class HttpMessage](docs/cn/HttpMessage.md)\n- [class HttpClient](docs/cn/HttpClient.md)\n- [class HttpServer](docs/cn/HttpServer.md)\n- [class HttpContext](docs/cn/HttpContext.md)\n\n### WebSocket\n#### WebSocket服务端\n见[examples/websocket_server_test.cpp](examples/websocket_server_test.cpp)\n```c++\n#include \"WebSocketServer.h\"\nusing namespace hv;\n\nint main(int argc, char** argv) {\n    WebSocketService ws;\n    ws.onopen = [](const WebSocketChannelPtr\u0026 channel, const HttpRequestPtr\u0026 req) {\n        printf(\"onopen: GET %s\\n\", req-\u003ePath().c_str());\n    };\n    ws.onmessage = [](const WebSocketChannelPtr\u0026 channel, const std::string\u0026 msg) {\n        printf(\"onmessage: %.*s\\n\", (int)msg.size(), msg.data());\n    };\n    ws.onclose = [](const WebSocketChannelPtr\u0026 channel) {\n        printf(\"onclose\\n\");\n    };\n\n    WebSocketServer server(\u0026ws);\n    server.setPort(9999);\n    server.setThreadNum(4);\n    server.run();\n    return 0;\n}\n```\n\n#### WebSocket客户端\n见[examples/websocket_client_test.cpp](examples/websocket_client_test.cpp)\n```c++\n#include \"WebSocketClient.h\"\nusing namespace hv;\n\nint main(int argc, char** argv) {\n    WebSocketClient ws;\n    ws.onopen = []() {\n        printf(\"onopen\\n\");\n    };\n    ws.onmessage = [](const std::string\u0026 msg) {\n        printf(\"onmessage: %.*s\\n\", (int)msg.size(), msg.data());\n    };\n    ws.onclose = []() {\n        printf(\"onclose\\n\");\n    };\n\n    // reconnect: 1,2,4,8,10,10,10...\n    reconn_setting_t reconn;\n    reconn_setting_init(\u0026reconn);\n    reconn.min_delay = 1000;\n    reconn.max_delay = 10000;\n    reconn.delay_policy = 2;\n    ws.setReconnect(\u0026reconn);\n\n    ws.open(\"ws://127.0.0.1:9999/test\");\n\n    std::string str;\n    while (std::getline(std::cin, str)) {\n        if (!ws.isConnected()) break;\n        if (str == \"quit\") {\n            ws.close();\n            break;\n        }\n        ws.send(str);\n    }\n\n    return 0;\n}\n```\n\n## 🍭 更多示例\n\n### c版本\n- 事件循环:     [examples/hloop_test.c](examples/hloop_test.c)\n- 定时器:       [examples/htimer_test.c](examples/htimer_test.c)\n- pipe示例:     [examples/pipe_test.c](examples/pipe_test.c)\n- TCP回显服务:  [examples/tcp_echo_server.c](examples/tcp_echo_server.c)\n- TCP聊天服务:  [examples/tcp_chat_server.c](examples/tcp_chat_server.c)\n- TCP代理服务:  [examples/tcp_proxy_server.c](examples/tcp_proxy_server.c)\n- UDP回显服务:  [examples/udp_echo_server.c](examples/udp_echo_server.c)\n- UDP代理服务:  [examples/udp_proxy_server.c](examples/udp_proxy_server.c)\n- SOCKS5代理服务: [examples/socks5_proxy_server.c](examples/socks5_proxy_server.c)\n- HTTP服务:     [examples/tinyhttpd.c](examples/tinyhttpd.c)\n- HTTP代理服务: [examples/tinyproxyd.c](examples/tinyproxyd.c)\n- jsonRPC示例:  [examples/jsonrpc](examples/jsonrpc)\n- MQTT示例:     [examples/mqtt](examples/mqtt)\n- 多accept进程模式: [examples/multi-thread/multi-acceptor-processes.c](examples/multi-thread/multi-acceptor-processes.c)\n- 多accept线程模式: [examples/multi-thread/multi-acceptor-threads.c](examples/multi-thread/multi-acceptor-threads.c)\n- 一个accept线程+多worker线程: [examples/multi-thread/one-acceptor-multi-workers.c](examples/multi-thread/one-acceptor-multi-workers.c)\n\n### c++版本\n- 事件循环: [evpp/EventLoop_test.cpp](evpp/EventLoop_test.cpp)\n- 事件循环线程: [evpp/EventLoopThread_test.cpp](evpp/EventLoopThread_test.cpp)\n- 事件循环线程池: [evpp/EventLoopThreadPool_test.cpp](evpp/EventLoopThreadPool_test.cpp)\n- 定时器:    [evpp/TimerThread_test.cpp](evpp/TimerThread_test.cpp)\n- TCP服务端: [evpp/TcpServer_test.cpp](evpp/TcpServer_test.cpp)\n- TCP客户端: [evpp/TcpClient_test.cpp](evpp/TcpClient_test.cpp)\n- UDP服务端: [evpp/UdpServer_test.cpp](evpp/UdpServer_test.cpp)\n- UDP客户端: [evpp/UdpClient_test.cpp](evpp/UdpClient_test.cpp)\n- HTTP服务端: [examples/http_server_test.cpp](examples/http_server_test.cpp)\n- HTTP客户端: [examples/http_client_test.cpp](examples/http_client_test.cpp)\n- WebSocket服务端: [examples/websocket_server_test.cpp](examples/websocket_server_test.cpp)\n- WebSocket客户端: [examples/websocket_client_test.cpp](examples/websocket_client_test.cpp)\n- protobufRPC示例: [examples/protorpc](examples/protorpc)\n- Qt中使用libhv示例: [hv-projects/QtDemo](https://github.com/hv-projects/QtDemo)\n\n### 模拟实现著名的命令行工具\n- 网络连接工具: [examples/nc](examples/nc.c)\n- 网络扫描工具: [examples/nmap](examples/nmap)\n- HTTP服务程序: [examples/httpd](examples/httpd)\n- HTTP压测工具: [examples/wrk](examples/wrk.cpp)\n- URL请求工具:  [examples/curl](examples/curl.cpp)\n- 文件下载工具: [examples/wget](examples/wget.cpp)\n- 服务注册与发现: [examples/consul](examples/consul)\n- kcptun隧道: [examples/kcptun](examples/kcptun)\n\n## 🥇 性能测试\n\n### TCP回显服务pingpong测试\n```shell\ncd echo-servers\n./build.sh\n./benchmark.sh\n```\n\n**吞吐量**:\n```shell\nlibevent running on port 2001\nlibev running on port 2002\nlibuv running on port 2003\nlibhv running on port 2004\nasio running on port 2005\npoco running on port 2006\n\n==============2001=====================================\n[127.0.0.1:2001] 4 threads 1000 connections run 10s\ntotal readcount=1616761 readbytes=1655563264\nthroughput = 157 MB/s\n\n==============2002=====================================\n[127.0.0.1:2002] 4 threads 1000 connections run 10s\ntotal readcount=2153171 readbytes=2204847104\nthroughput = 210 MB/s\n\n==============2003=====================================\n[127.0.0.1:2003] 4 threads 1000 connections run 10s\ntotal readcount=1599727 readbytes=1638120448\nthroughput = 156 MB/s\n\n==============2004=====================================\n[127.0.0.1:2004] 4 threads 1000 connections run 10s\ntotal readcount=2202271 readbytes=2255125504\nthroughput = 215 MB/s\n\n==============2005=====================================\n[127.0.0.1:2005] 4 threads 1000 connections run 10s\ntotal readcount=1354230 readbytes=1386731520\nthroughput = 132 MB/s\n\n==============2006=====================================\n[127.0.0.1:2006] 4 threads 1000 connections run 10s\ntotal readcount=1699652 readbytes=1740443648\nthroughput = 165 MB/s\n```\n\n### TCP代理服务压测\n\n```shell\n# sudo apt install iperf\niperf -s -p 5001 \u003e /dev/null \u0026\nbin/tcp_proxy_server 1212 127.0.0.1:5001 \u0026\niperf -c 127.0.0.1 -p 5001 -l 8K\niperf -c 127.0.0.1 -p 1212 -l 8K\n```\n\n**带宽**:\n```shell\n------------------------------------------------------------\n[  3] local 127.0.0.1 port 52560 connected with 127.0.0.1 port 5001\n[ ID] Interval       Transfer     Bandwidth\n[  3]  0.0-10.0 sec  20.8 GBytes  17.9 Gbits/sec\n\n------------------------------------------------------------\n[  3] local 127.0.0.1 port 48142 connected with 127.0.0.1 port 1212\n[ ID] Interval       Transfer     Bandwidth\n[  3]  0.0-10.0 sec  11.9 GBytes  10.2 Gbits/sec\n```\n\n### HTTP压测\n```shell\n# sudo apt install wrk\nwrk -c 100 -t 4 -d 10s http://127.0.0.1:8080/\n\n# sudo apt install apache2-utils\nab -c 100 -n 100000 http://127.0.0.1:8080/\n```\n\n**libhv(port:8080) vs nginx(port:80)**\n\n![libhv-vs-nginx.png](html/downloads/libhv-vs-nginx.png)\n\n以上测试结果可以在 [Github Actions](https://github.com/ithewei/libhv/actions/workflows/benchmark.yml) 中查看。\n\n## 💎 用户案例\n\n如果您在使用`libhv`，欢迎通过PR将信息提交至此列表，让更多的用户了解`libhv`的实际使用场景，以建立更好的网络生态。\n\n| 用户 (公司名/项目名/个人联系方式) | 案例 (项目简介/业务场景) |\n| :--- | :--- |\n| [阅面科技](https://www.readsense.cn) | [猎户AIoT平台](https://orionweb.readsense.cn)设备管理、人脸检测HTTP服务、人脸搜索HTTP服务 |\n| [socks5-libhv](https://gitee.com/billykang/socks5-libhv) | socks5代理 |\n| [hvloop](https://github.com/xiispace/hvloop) | 类似[uvloop](https://github.com/MagicStack/uvloop)的python异步IO事件循环 |\n| [tsproxyd-android](https://github.com/Haiwen-GitHub/tsproxyd-android) | 一个基于libhv实现的android端web代理服务 |\n| [玄舟智维](https://zjzwxw.com) | C100K设备连接网关服务 |\n\n","funding_links":[],"categories":["Asynchronous Event Loop","C","NetWork","Networking and Internet","Containers \u0026 Language Extentions \u0026 Linting","HarmonyOS","网络和互联网","Tools per Language"],"sub_categories":["Advanced books","For C++/C","Windows Manager","高级书籍","C++"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fithewei%2Flibhv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fithewei%2Flibhv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fithewei%2Flibhv/lists"}