4 Commits

Author SHA1 Message Date
xfy911
522685e55b feat: 实现带宽限速 / 流量整形(Token Bucket 算法)
Some checks failed
CI / build (push) Failing after 1m0s
- 新增 throttle.c/throttle.h:Token Bucket 双层限速实现
  - 支持 per-connection(单连接限速)和 global(服务器总带宽限速)
  - 使用 fd 映射表自动注册/清理,侵入性最小
- cocoon.h: 配置结构体新增 throttle_conn_rate、throttle_global_rate
- server.c: 连接创建时自动初始化 per-connection throttle;server_destroy 释放 global throttle
- static.c: send_all() 自动查表限速
- platform.c: cocoon_file_send() 限速启用时回退到 read+write 循环,逐 chunk 限速
- proxy.c: send_all_fd() 加入限速
- config.c: 解析 JSON 配置中的 throttle 对象(conn_rate / global_rate)
- config.h: 更新 config_merge 签名
- Makefile: 将 throttle.c 加入 SRCS 和所有单元测试编译规则

编译零警告,109 项集成测试通过(6 个失败为已知环境反向代理 404 问题)
2026-06-16 15:41:24 +08:00
xfy911
4105aec916 feat(websocket): 实现 WebSocket 空闲超时处理 + 跨平台 poll/select 抽象
- platform.h / platform.c: 新增 cocoon_socket_poll_readable() 跨平台 socket 可读等待
  - POSIX: poll() + POLLIN
  - Windows: select() + fd_set(readfds)
- websocket.c: ws_handle_connection() 实现 timeout_ms 空闲超时处理
  - 每次循环前调用 poll_readable() 等待数据或超时
  - 超时时发送 1001 Idle timeout 关闭帧,清理连接资源
  - 解决遗留 TODO: /* TODO: 超时处理 */
- tests/websocket_test.py: 新增 test_timeout() 测试
  - 连接后不发帧,验证服务端 2 秒后发送 1001 关闭帧
- tests/integration_test.sh: 新增 WebSocket 空闲超时集成测试
  - 启动 -o 2000 短超时服务器验证超时行为
- Makefile: 补全 test_websocket 编译规则,加入 platform.c
  - 修复 undefined reference 错误
- 全部 142 单元测试 + 77 集成测试通过,编译零警告
2026-06-06 21:16:54 +08:00
xfy911
22c933a99d merge main into feature/windows-compat-impl: resolve conflicts for TLS, HTTP/2, WebSocket, access log 2026-06-05 16:17:55 +08:00
xfy
c9693612bd feat(platform): 新增跨平台抽象层 platform.h + platform.c
- platform.h: 定义跨平台类型 cocoon_socket_t / cocoon_file_t / cocoon_dir_iter_t
- POSIX 路径: fcntl O_NONBLOCK, sendfile 零拷贝, opendir/readdir, sysconf
- Windows 路径: ioctlsocket(FIONBIO), WSAStartup/WSACleanup, FindFirstFile
- 错误码统一: WSAEWOULDBLOCK→EAGAIN, WSAEINTR→EINTR, WSAECONNRESET→ECONNRESET
- 全部中文注释,Doxygen 风格
2026-06-05 00:50:18 +08:00