From 78507084c4eb409ce1a48a8a585de4ce782439d1 Mon Sep 17 00:00:00 2001 From: xfy Date: Fri, 5 Jun 2026 00:50:28 +0800 Subject: [PATCH] =?UTF-8?q?refactor(main):=20=E4=BD=BF=E7=94=A8=E8=B7=A8?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=20API=20=E6=9B=BF=E4=BB=A3=20POSIX=20?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除 头文件 - 新增 cocoon_socket_init() / cocoon_socket_cleanup() 调用 - 信号处理改用 cocoon_signal_setup() 统一封装 - Windows 下自动 WSAStartup/WSACleanup --- main.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 6c7e14f..8b75d57 100644 --- a/main.c +++ b/main.c @@ -9,10 +9,10 @@ #include "cocoon.h" #include "server.h" #include "config.h" +#include "platform.h" #include #include #include -#include /** * g_ctx - 全局服务器上下文(用于信号处理) @@ -184,9 +184,14 @@ int main(int argc, char *argv[]) { return 1; } + /* 初始化 socket 子系统(Windows 下 WSAStartup) */ + if (cocoon_socket_init() != 0) { + fprintf(stderr, "[Cocoon] socket 子系统初始化失败\n"); + return 1; + } + /* 注册信号处理 */ - signal(SIGINT, signal_handler); - signal(SIGTERM, signal_handler); + cocoon_signal_setup(signal_handler); /* 设置日志级别 */ log_set_level(config.log_level); @@ -205,6 +210,9 @@ int main(int argc, char *argv[]) { server_destroy(g_ctx); g_ctx = NULL; + /* 释放 socket 子系统(Windows 下 WSACleanup) */ + cocoon_socket_cleanup(); + /* 释放配置文件分配的 root_dir */ if (config.root_dir) { free((void *)config.root_dir);