From ca7b33aa10f553b5b318a4fcf0015ca1457b92c3 Mon Sep 17 00:00:00 2001 From: xfy Date: Thu, 4 Jun 2026 08:16:27 +0800 Subject: [PATCH] =?UTF-8?q?docs(plan):=20=E6=B7=BB=E5=8A=A0=20Windows=20?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E6=80=A7=E8=AF=A6=E7=BB=86=E6=8A=80=E6=9C=AF?= =?UTF-8?q?=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 描述目标:在 Windows 上编译运行 cocoon - 分析核心发现:coco 库已有 Windows 支持,问题在 cocoon 的 POSIX 依赖 - 提出方案:引入 platform.h + platform.c 平台抽象层 - 列出关键 API 映射:POSIX → Windows 对照表 - 记录零拷贝策略:Windows 暂时回退到 read+send,后续用 TransmitFile 优化 - 指定执行方式:Subagent-Driven 逐个 Task 实现 --- .cocoon-plan.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.cocoon-plan.md b/.cocoon-plan.md index 60e8ee8..de8b257 100644 --- a/.cocoon-plan.md +++ b/.cocoon-plan.md @@ -63,6 +63,24 @@ 4. **[中] server.c 单元测试** — 需要 mock socket 和 coco 协程环境 5. **[中] 完善 Doxygen 中文注释** — 所有模块的公共 API 需要完整文档 +### Windows 兼容性详细计划 + +**目标**:在 Windows 上编译运行 cocoon(目前仅支持 Linux/macOS)。 + +**核心发现**:coco 库**已有完整 Windows 支持**(`poll_windows.c` 使用 WSAPoll,`coco_read/coco_write/coco_accept` 内部调用 `recv/send/accept`)。问题在 cocoon 自身直接调用大量 POSIX API。 + +**方案**:引入 `platform.h` + `platform.c` 平台抽象层,封装所有 POSIX/Windows 差异。 + +| 变更 | 说明 | +|------|------| +| **新增** | `src/platform.h`, `src/platform.c`, `CMakeLists.txt` | +| **修改** | `server.c`, `static.c`, `main.c`, `server.h`, `Makefile` | +| **移除依赖** | `sys/socket.h`, `sendfile.h`, `dirent.h`, `signal.h`, `unistd.h` | +| **关键映射** | `close()` → `closesocket()`, `fcntl()` → `ioctlsocket()`, `sendfile()` → `read+send` 循环, `opendir()` → `FindFirstFileA()` | +| **零拷贝** | Windows 上暂时移除 sendfile(后续可用 TransmitFile 优化) | + +**执行方式**:Option 1 — Subagent-Driven(子代理逐个 Task 实现,每步自动 review) + ## 最近行动记录 - 2026-06-04: **本轮行动 — Brotli 压缩支持**